0

I'm using MFC in Visual Studio 2015 on Windows 7 64Bit.

In my application,there is an activeX control,I need to communicate between activeX control and my application.

But activeX need my application to pass a LPDISPATCH pointer/interface to it.

How should I do to get the LPDISPATCH pointer/interface of my application's method(OnExtRequest)?

This is the method provided by the activeX:

void SetOnExtRequest(LPDISPATCH propVal)
{
    SetProperty(0x4, VT_DISPATCH, propVal);
}

This is my application's callback function(pass this function's LPDISPATCH Pointer/interface to activeX)

int CMyDlg::OnExtRequest(CString sObj, int uMeth, CString sData, int uHandle, CString sPeer)
{
    //TODO:......
}

Plz help me,thank you!

Yao
  • 1
  • 3
  • Hmm, you have a lot of work to do. Your CMyDlg class must implement IDispatch. And you'll have to rewrite that function, there is no way that an ActiveX control is going to pass you a CString. The Automation type for a string is BSTR. – Hans Passant Jul 11 '16 at 07:45
  • thanks,I know this is a problem,but implement IDispatch is superior,can you show me an example code or just a iDispatch class.thx. – Yao Jul 11 '16 at 09:32

1 Answers1

1

Your OnExtRequest() callback method is not part of an ActiveX object so you cannot pass it directly to SetOnExtRequest(). You need to write a class that implements IDispatch and have its Invoke() implementation call your OnExtRequest() method. Then create an instance of that class and pass it to SetOnExtRequest().

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
  • Do you have an example source code?because in my application,will create up to 16 activeX control,and i have to deal with it separately – Yao Jul 11 '16 at 06:05