using COM during initilization

using COM during initilization

Anonymous
Not applicable
447 Views
9 Replies
Message 1 of 10

using COM during initilization

Anonymous
Not applicable
During the startup of a drawing, I am trying to load a menu via the COM interface (a modified version of the SDK example). I am doing this during the AcRx::kLoadDwgMsg. The menu fails to load at this line: if(::GetActiveObject(clsid, NULL, &pUnk) != S_OK), something about "no document" which sounds strange as there IS a document, and I am able to extract block attributes from it during the same AcRx::kLoadDwgMsg. After my init code has ran and Acad is in a "quiet" state, I can then enter my load menu command at the promp and the code runs fine and loads the menu. Is COM not fully initilized during this time? How can I get this menu to load at startup? Thanks for any "pointers" Perry
0 Likes
448 Views
9 Replies
Replies (9)
Message 2 of 10

Anonymous
Not applicable
You don't use GetActiveObject() to get a pointer to the Application object. You need to use AcadGetIDispatch(), or acedGetAcadWinApp::GetIDispatch() (MFC). -- http://www.caddzone.com AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006 http://www.acadxtabs.com "perry" wrote in message news:42540478$1_2@newsprd01... > During the startup of a drawing, I am trying to load a menu via the COM interface (a modified version of the SDK > example). I am doing this during the > AcRx::kLoadDwgMsg. The menu fails to load at this line: > if(::GetActiveObject(clsid, NULL, &pUnk) != S_OK), > something about "no document" > which sounds strange as there IS a document, and I am able to extract block > attributes from it during the same AcRx::kLoadDwgMsg. > After my init code has ran and Acad is in a "quiet" state, I can then enter my > load menu command at the promp and the code runs fine and loads the menu. > Is COM not fully initilized during this time? > How can I get this menu to load at startup? > Thanks for any "pointers" > Perry
0 Likes
Message 3 of 10

Anonymous
Not applicable
Tony Tanzillo wrote: > You don't use GetActiveObject() to get a pointer to the > Application object. You need to use AcadGetIDispatch(), > or acedGetAcadWinApp::GetIDispatch() (MFC). > That code came straight out of the SDK, so I assumed it was correct. As I am still grappling with C/Arx I dont want to tackle COM for a long time yet. Other than hacking existing code. I guess there are no "Proper" examples of Arx/Com for me to use :( Perry
0 Likes
Message 4 of 10

Anonymous
Not applicable
> That code came straight out of the SDK, so I assumed it was correct. Straight out of the SDK? For what, a standalone COM client? An in-process ObjectARX COM server? Where exactly did 'that code come straight out of'' ? -- http://www.caddzone.com AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006 http://www.acadxtabs.com
0 Likes
Message 5 of 10

Anonymous
Not applicable
Tony Tanzillo wrote: >>That code came straight out of the SDK, so I assumed it was correct. > > > Straight out of the SDK? For what, a standalone COM > client? An in-process ObjectARX COM server? > > Where exactly did 'that code come straight out of'' ? > C:\Program Files\ObjectARX 2002\docsamps\comsamps\AsdkPlainComSamp Yes, I know Im in the "Stone ages" here with 2002. Perry
0 Likes
Message 6 of 10

Anonymous
Not applicable
>>>That code came straight out of the SDK, so I assumed it was correct. >> > C:\Program Files\ObjectARX 2002\docsamps\comsamps\AsdkPlainComSamp It's wrong. The reason why you can't use GetActiveObject() from an in-process client is that it can return any of several running instances of AutoCAD, which may not be the one that the ARX dll is loaded into. Use this function to get a pointer to an IDispatch, that can be queried for IAcadApplicatoin: extern LPDISPATCH AcadGetIDispatch(bool bAddRef); If your link fails, then add an underscore to the front of the function name (e.g., _AcadGetIDispatch). -- http://www.caddzone.com AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006 http://www.acadxtabs.com "perry" wrote in message news:42543ba2$1_1@newsprd01... > Tony Tanzillo wrote: >> >> Straight out of the SDK? For what, a standalone COM >> client? An in-process ObjectARX COM server? >> >> Where exactly did 'that code come straight out of'' ? >> > > Yes, I know Im in the "Stone ages" here with 2002. > Perry
0 Likes
Message 7 of 10

Anonymous
Not applicable
Tony Tanzillo wrote: >>>>That code came straight out of the SDK, so I assumed it was correct. >>> > >>C:\Program Files\ObjectARX 2002\docsamps\comsamps\AsdkPlainComSamp > > > It's wrong. The reason why you can't use GetActiveObject() > from an in-process client is that it can return any of several > running instances of AutoCAD, which may not be the one that > the ARX dll is loaded into. > > Use this function to get a pointer to an IDispatch, that can > be queried for IAcadApplicatoin: > > extern LPDISPATCH AcadGetIDispatch(bool bAddRef); > > If your link fails, then add an underscore to the front > of the function name (e.g., _AcadGetIDispatch). > So nice of those Autodesk guys to lead me astray. The fact that it will work at a "quiet" state I guess is just luck? I'll try what you said Tony, being that I dont know COM it may bugger me. Maybe some of the C pro's at my work can help me on that. Thanks Perry
0 Likes
Message 8 of 10

Anonymous
Not applicable
The same code is there in the 2005 SDK; from samples\com\AsdkPlainComSamp_dg hr = ::CLSIDFromProgID(L"AutoCAD.Application", &clsid); if (FAILED(hr)) return; if(::GetActiveObject(clsid, NULL, &pUnk) != S_OK) return; Dan "perry" wrote in message news:42543ba2$1_1@newsprd01... > Tony Tanzillo wrote: >>>That code came straight out of the SDK, so I assumed it was correct. >> >> >> Straight out of the SDK? For what, a standalone COM >> client? An in-process ObjectARX COM server? >> >> Where exactly did 'that code come straight out of'' ? >> > C:\Program Files\ObjectARX 2002\docsamps\comsamps\AsdkPlainComSamp > > Yes, I know Im in the "Stone ages" here with 2002. > Perry
0 Likes
Message 9 of 10

Anonymous
Not applicable
J. Daniel Smith wrote: > The same code is there in the 2005 SDK; from samples\com\AsdkPlainComSamp_dg > > hr = ::CLSIDFromProgID(L"AutoCAD.Application", &clsid); > > if (FAILED(hr)) > > return; > > if(::GetActiveObject(clsid, NULL, &pUnk) != S_OK) > > return; > > Dan Are you saying that bad code has propagated to the latest releases of the SDK? Perry
0 Likes
Message 10 of 10

Anonymous
Not applicable
Yes, the sample hasn't changed. The AcadGetIDispatch() function is undocumented, but the CWinApp::GetIDispatch() is documented but that requires MFC. -- http://www.caddzone.com AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006 http://www.acadxtabs.com "perry" wrote in message news:42554d17$1_1@newsprd01... > J. Daniel Smith wrote: >> The same code is there in the 2005 SDK; from samples\com\AsdkPlainComSamp_dg >> >> hr = ::CLSIDFromProgID(L"AutoCAD.Application", &clsid); >> >> if (FAILED(hr)) >> >> return; >> >> if(::GetActiveObject(clsid, NULL, &pUnk) != S_OK) >> >> return; >> >> Dan > Are you saying that bad code has propagated to the latest releases of the SDK? > Perry
0 Likes