Hi everybody!
Could anyone give me a hand in understanding what I'm doing wrong in the following part of code, written in C++?
The matter is that during the execution the line of code "pCommandGroup->Activate(&vbResult);" causes a crash.
extern "C" void __declspec (dllexport) Test_command()
{
}
extern "C" int __declspec (dllexport) OnUpdateTest()
{
return 1;
}
HRESULT MyAddIn::ConnectToSW(LPDISPATCH ThisSW,long Cookie,VARIANT_BOOL *IsConnected)
{
*IsConnected=VARIANT_FALSE;
CComQIPtr
if (!pSldWorks)
return S_FALSE;
CComPtr
pSldWorks->GetCommandManager(Cookie,&pCommandManager);
if (!pCommandManager)
return S_FALSE;
long lErrors=0;
CComPtr
pCommandManager->CreateCommandGroup2(0,L"Title",L"Tooltip",L"Hint",-1,VARIANT_TRUE,&lErrors,&pCommandGroup);
if (!pCommandGroup)
return S_FALSE;
long lCommandID1=0;
pCommandGroup->AddCommandItem2(L"Command1",0,L"",L"",-1,L"Test_command",L"OnUpdateTest",0,swMenuItem,&lCommandID1);
pCommandGroup->put_HasMenu(VARIANT_TRUE);
VARIANT_BOOL vbResult=FALSE;
pCommandGroup->Activate(&vbResult); // It crashes during the exacution
*IsConnected=VARIANT_TRUE;
return S_OK;
}
My assumption is that could be due to incorrect siganure for the callbacks in the method ICommandGroup::AddCommandItem2. As a matter of fact, if I put there empty strings for the callbacks like this
pCommandGroup->AddCommandItem2(L"Command1",0,L"",L"",-1,L"",L"",0,swMenuItem,&lCommandID1);
the crash doesn't occur.
Unfortunately, all samples how to use this function are only available for C# and VB.
Thank you for any assistance!
SolidworksApi macros