We can use either MFC or ATL to create a client VC++ application of the COM server to access that information. In the attached sample, MFC is used. We should add a class Iproperties which wraps the methods and properties of the COM server from DwgPropsX.DLL with MFC class wizard into the project skeleton. Then we may find the ProgID of the COM server from Windows registry and find the CLSID with function CLSIDFromProgID. Of course, please make sure the COM server has been registered. The most common way to register Windows services is to use RegSvr32.Exe. We can also register them programmatically by calling it as a system command or with other APIs. Please find more information regarding this from MSDN.
The project supports multiple documents. When we open a DWG file with a view available, if it contains drawing properties, they will display in the current view. We can display properties of more drawings in multiple view windows. Anyway, the most important part is the following appended global function which contains COM initialization, ProgID to CLSID conversion, dispatch interface creation, properties retrieve, and COM clean up.
Full sample project.
// Global function to retrieve the drawing properties.
// In
// LPCTSTR szFileName: Full path and name of a DWG file
// Output
// LPCTSTR: A string containing all the property information
// delimited by new line symbol '\n'
LPTSTR getSummaryInformation(LPCTSTR szFileName)
{
LPTSTR szSummInfo = NULL;
CString str;
IProperties dwgProp;
HRESULT hr = NOERROR;
CLSID clsid;
LPDISPATCH pDisp=NULL;
hr = CoInitialize(NULL);
if (FAILED(hr))
return NULL;
hr = ::CLSIDFromProgID(L"DwgPropsX.Properties", &clsid);
if(FAILED(hr))
return NULL;
VERIFY(dwgProp.CreateDispatch(clsid) == TRUE);
dwgProp.Load(szFileName);
str = "Drawing Summary Information:\n";
str = str + (CString)"\nTitle: " +
(CString)dwgProp.GetTitle();
str = str + (CString)"\nSubject: " +
(CString)dwgProp.GetSubject();
str = str + (CString)"\nAuthor: " +
(CString)dwgProp.GetAuthor();
str = str + (CString)"\nComments: " +
(CString)dwgProp.GetComments();
str = str + (CString)"\nKeywords: " +
(CString)dwgProp.GetKeywords();
str = str + (CString)"\nLast Saved By: " +
(CString)dwgProp.GetLastSavedBy();
str = str + (CString)"\nRevision Number: " +
(CString)dwgProp.GetRevisionNumber();
str = str + (CString)"\nHyperlink Base: " +
(CString)dwgProp.GetHyperlinkBase();
for(int i=0; i<10; i++)
{
CString tempStr;
tempStr.Format("\nCustom %d: %s", i+1,
(LPCTSTR)dwgProp.GetCustom(i));
str = str + tempStr;
}
DATE date;
BSTR strDate;
date = dwgProp.GetEditingTime();
VarBstrFromDate(date, LOCALE_SYSTEM_DEFAULT,
LOCALE_NOUSEROVERRIDE, &strDate);
str = str + (CString)"\nEditing Time: " + (CString)strDate;
date = dwgProp.GetCreated();
VarBstrFromDate(date, LOCALE_SYSTEM_DEFAULT,
LOCALE_NOUSEROVERRIDE, &strDate);
str = str + (CString)"\nCreated Time: " + (CString)strDate;
date = dwgProp.GetLastUpdated();
VarBstrFromDate(date, LOCALE_SYSTEM_DEFAULT,
LOCALE_NOUSEROVERRIDE, &strDate);
str = str + (CString)"\nLast Updated Time" + (CString)strDate;
szSummInfo = (LPTSTR)malloc(str.GetLength()+1);
_tcscpy(szSummInfo, str.GetBuffer(str.GetLength()));
CoUninitialize();
return szSummInfo;
}