Book a Demo

Author Topic: GetContextItem and GetTreeSelectedItem in VisualC  (Read 3053 times)

straka.milan

  • EA Novice
  • *
  • Posts: 2
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
GetContextItem and GetTreeSelectedItem in VisualC
« on: July 28, 2007, 06:36:34 am »
Hello,

I am writing an EA Addin in Visual C++, unmanaged.

I am trying to call GetContextItem and GetTreeSelectedItem methods of Repository, but all the calls segfaults. These two methods have same prototypes, so I will describe only one of them furhter.

Using OLE browser, I found out these prototypes:
IRepository: ObjectType GetTreeSelectedItem(IDispatch* Item);
IDualRepository: ObjectType GetTreeSelectedItem([out] IDispatch** Item);

First weird thing is, that these 2 calls differs in level of indirection of Item.

I thought, that

LPDISPATCH i=VALUE;
IDualRepository->GetTreeSelectedItem(&i);

should be the correct call when VALUE=NULL. But
this call segfaults -- it tries to read the address VALUE.

Then I tried to supply correct pointer to my custom IDispatch interface which monitored Invoke calls -- it segfaults before any IDispatch::Invoke call is made.

But in C# it works (sample from EA installation) --

object i;
Repository.GetTreeSelectedItem(out i)

works just fine.


The GetTreeSelectedItem can be solved by calling GetTreeSelectedObject, which works. But GetContextItem does not have similar GetContextObject and it is difficult to simulate GetContextItem. (Current diagram has SelectedObjects, but when multiple object are selected, you dont know which one is in context).

Please help.

Milan Straka
« Last Edit: July 28, 2007, 06:47:38 am by straka.milan »

straka.milan

  • EA Novice
  • *
  • Posts: 2
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
GetContextItem direct dual call works
« Reply #1 on: July 29, 2007, 12:35:03 am »
Hello,

I found out, that although calling the methods through the Dispatch interface (Invoke method) fails, the direct call of the method using dual interface works!

I was using MFC generated dispatch wrappers (COleDispatchDriver), which nicely wraps error handling and parameter conversions (no BSTRs and similar). When calling GetContextItem and GetTreeSelectedItem directy through Dual interface IDualRepository, everything works.

I want to use COleDispatchDriver, so I wrote following call for COleDispatchDriver
Code: [Select]

inline long CDualRepository_GetContextItem(CDualRepository *r, IDispatch **i) {
   long itype;
   HRESULT hr=(
       ((HRESULT (__stdcall *)(LPDISPATCH,IDispatch **,long*))
       (*((*((void***)r->m_lpDispatch))+(7/*IUnknown and IDispatch*/+0x3a))))
       (r->m_lpDispatch, i, &itype)
   );
   if (hr!=S_OK) AfxThrowOleException(hr);
   return itype;
}


0x3a is the "number" of GetContextItem. That works fine.

But do anyone knows why the call through Invoke fails?

Milan Straka