This topic describes how to create a C++ Windows MFC stand-alone application that logs into
a SOLIDWORKS Enterprise PDM file vault and lists the files in the root folder.
- Start up Microsoft Visual Studio 2010.
- Click File > New > Project > Visual C++ > MFC > MFC
Application.
- Type the name of your project in Name.
- Click the Browse button and browse to the folder where to
create your project.
- Click OK.
- Click Next.
- Select application type, Dialog based.
- Click Next, Next, and Next.
- Click Finish.
- Click Build > Build Solution.
- Copy Edm.tlb from the API subfolder of the SOLIDWORKS Enterprise PDM CD
to project_path\project_name\project_name.
- Register Edm.tlb. For example, on a computer
running Windows 7 x64:
- Search the disk where Windows 7 x64 was installed for
regtlibv12.exe.
- Open a command window and type:
>cd path_to_regtlibv12.exe
>regtlibv12.exe "project_path\project_name\project_name\Edm.tlb"
- Close the command window.
- Drag a button from the Toolbox onto the form.
- Double-click Button1 on the form.
- Type the following code at the top of the code
after the
#include
statements:
#import "Edm.tlb" no_namespace - Find and replace
//TODO: Add your control
notification handler code
here, which appears
in the button's command handler, with the following code. Fix the formatting
of the code if needed.
//Initialize COM (Usually done just once, for
instance in InitInstance.)
CoInitialize(0);
IEdmVault5Ptr poVault;
HRESULT hRes = poVault.CreateInstance( __uuidof(EdmVault5), NULL );
try
{
//Create a vault interface.
if( FAILED(hRes) )
_com_issue_error(hRes);
//Log in on the vault.
poVault->LoginAuto( "MyVault", (long)m_hWnd );
//Get a pointer to the root folder.
IEdmFolder5Ptr poFolder;
poFolder = poVault->RootFolder;
//Get position of first file in the folder.
IEdmPos5Ptr poPos;
poPos = poFolder->GetFirstFilePosition();
CString oMessage;
if( poPos->IsNull )
oMessage = "The root folder of your vault does not contain any files.";
else
oMessage = "The root folder of your vault contains these files:\n";
while( poPos->IsNull == VARIANT_FALSE )
{
IEdmFile5Ptr poFile = poFolder->GetNextFile( poPos );
oMessage += (LPCTSTR)poFile->GetName();
oMessage += "\n";
}
AfxMessageBox( oMessage );
}
catch( const _com_error &roError )
{
//We get here if one of the methods above failed.
if( poVault == NULL )
{
AfxMessageBox( _T("Could not create vault interface." ));
}
else
{
BSTR bsName = NULL;
BSTR bsDesc = NULL;
poVault->GetErrorString( (long)roError.Error(), &bsName, &bsDesc );
bstr_t oName( bsName, false );
bstr_t oDesc( bsDesc, false );
bstr_t oMsg = "Something went wrong.\n";
oMsg += oName;
oMsg += "\n";
oMsg += oDesc;
AfxMessageBox( oMsg );
}
}
//Deinitialize COM.
CoUninitialize();
-
Replace MyVault in the code with the name of a SOLIDWORKS Enterprise PDM vault on your computer.
-
If creating this project on a Windows 7 x64 computer, change the platform to x64:
-
Right-click the name of your project in the Solution Explorer and click Properties.
-
Click the Configuration Manager button.
-
Click the down-arrow button in the Platform column and select New.
-
Select x64 in New platform and click OK.
-
Click Close. If Active(x64) is not shown in Platform, then repeat Steps 2 - 5 until it is.
-
Click OK.
-
Specify the project configuration properties:
-
Right-click the name of your project in the Solution Explorer and click Properties.
-
Click Configuration Properties > General.
-
Set Use of MFC to Use MFC in a Shared DLL.
-
Set Character Set to Use Unicode Character Set.
-
Click Build > Clean Solution.
-
Click Build > Rebuild Solution.
-
Click Debug > Start Debugging or press F5.
-
Click Button1.
A message box is displayed that either contains the names of the files in the root folder of the specified vault or informs you that the root folder of the specified vault does not contain any files.
-
Close the form.
-
Click File > Save All.
See
Also
Stand-alone Applications (VB.NET)
Destroy Deleted
Files in Vault Example (C++)
Destroy Deleted Files
in Vault Example (VB.NET)