T
thoatson
Guest
I have a 3rd-party COM object that I would like my code to access as a client. I have a working test program that is written in C#, but getting this to work in my C++ code is much less straight-forward. I have done some reading on COM objects, but it gets really confusing. If the writer refers to C++, it's often unclear whether s/he is referring to steps needed to create the COM object (i.e. server) or to use the COM object (i.e. as a client).
Here is the code I have:
CLSID clsCOMObjLauncher = CLSID_COMObjLauncher;
CLSID clsCOMObjApp = CLSID_COMObjApplication;
// if COMObj is already running, return with current instance
if (m_pdispCOMObjApp != NULL)
return TRUE;
/* Obtain CLSID identifying COMObj application
* This value is universally unique to COMObj, and
* is used by OLE to identify which server to start.
* We are obtaining the CLSID from the ProgID. */
if (FAILED(CLSIDFromProgID(L"VendorSoftware.Application", &clsCOMObjApp)))
{
MessageBox(NULL, _T("Cannot obtain CLSID from ProgID"), _T("Failed"), MB_OK | MB_ICONSTOP);
return FALSE;
}
// start new copy of COMObj Launcher, grab IDispatch interface
if (FAILED(CoCreateInstance(clsCOMObjLauncher, NULL, CLSCTX_ALL, IID_IDispatch, (void**)&m_pdispCOMObjApp)))
{
MessageBox(NULL, _T("Cannot start an instance of COMObj for Automation."), _T("Failed"), MB_OK | MB_ICONSTOP);
return FALSE;
}
// start new copy of COMObj, grab IDispatch interface
if (FAILED(CoCreateInstance(clsCOMObjApp, NULL, CLSCTX_ALL, IID_IDispatch, (void**) &m_pdispCOMObjApp)))
{
MessageBox(NULL, _T("Cannot start an instance of COMObj for Automation."), _T("Failed"), MB_OK | MB_ICONSTOP);
return FALSE;
}
When I try to compile this, I get no errors, but I get errors on the link step:
error LNK2001: unresolved external symbol _CLSID_COMObjLauncher
error LNK2001: unresolved external symbol _CLSID_COMObjApplication
I'm not sure how to fix this, or if I'm even going in the right direction. How do you get access to a COM object in C++?
Continue reading...
Here is the code I have:
CLSID clsCOMObjLauncher = CLSID_COMObjLauncher;
CLSID clsCOMObjApp = CLSID_COMObjApplication;
// if COMObj is already running, return with current instance
if (m_pdispCOMObjApp != NULL)
return TRUE;
/* Obtain CLSID identifying COMObj application
* This value is universally unique to COMObj, and
* is used by OLE to identify which server to start.
* We are obtaining the CLSID from the ProgID. */
if (FAILED(CLSIDFromProgID(L"VendorSoftware.Application", &clsCOMObjApp)))
{
MessageBox(NULL, _T("Cannot obtain CLSID from ProgID"), _T("Failed"), MB_OK | MB_ICONSTOP);
return FALSE;
}
// start new copy of COMObj Launcher, grab IDispatch interface
if (FAILED(CoCreateInstance(clsCOMObjLauncher, NULL, CLSCTX_ALL, IID_IDispatch, (void**)&m_pdispCOMObjApp)))
{
MessageBox(NULL, _T("Cannot start an instance of COMObj for Automation."), _T("Failed"), MB_OK | MB_ICONSTOP);
return FALSE;
}
// start new copy of COMObj, grab IDispatch interface
if (FAILED(CoCreateInstance(clsCOMObjApp, NULL, CLSCTX_ALL, IID_IDispatch, (void**) &m_pdispCOMObjApp)))
{
MessageBox(NULL, _T("Cannot start an instance of COMObj for Automation."), _T("Failed"), MB_OK | MB_ICONSTOP);
return FALSE;
}
When I try to compile this, I get no errors, but I get errors on the link step:
error LNK2001: unresolved external symbol _CLSID_COMObjLauncher
error LNK2001: unresolved external symbol _CLSID_COMObjApplication
I'm not sure how to fix this, or if I'm even going in the right direction. How do you get access to a COM object in C++?
Continue reading...