C#活动事件在C ++客户端中导致错误,但在VB6中有效 [英] C# Active events cause error in C++ client but work in VB6
问题描述
我正在用C#编写ActiveX,将在旧版C ++应用程序中使用.
除了事件处理之外,一切正常.
问题是当在C#中引发事件时,出现以下错误:
I am writing an ActiveX in C#, to be used in a legacy C++ application.
It all works ok, apart from event handling.
The problem is that when the event is raised in C# I get the following error:
An unhandled exception of type ''System.InvalidCastException'' occurred in AwDotNetPinchOcx.dll
Additional information: Unable to cast COM object of type ''System.__ComObject'' to interface type ''AwDotNetPinchOcx.__AwPinchGrid''.
This operation failed because the QueryInterface call on the COM component for the interface with IID ''{76F027EC-3D40-449E-B7E6-EFDF7CC63963}''
failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).
但是,C#ActiveX在测试的VB6应用程序中可以正常工作.
而且,本机VB6 ActiveX在C ++应用程序中也能正常工作!
因此,我目前的解决方法是包含C#ActiveX的VB6 ActiveX包装器,
并在其中传递数据和事件.
我想摆脱这个包装器.
有人可以帮忙吗?
====================================
C ++应用程序使用ConnectionPoint事件接收器方法:
===================================
However, the C# ActiveX works fine in a test VB6 app.
And, a native VB6 ActiveX works fine in the C++ application!
My work-around at the moment is therefore a VB6 ActiveX wrapper that contains the C# ActiveX,
and passes data and events across.
I want to get rid of this wrapper though.
Can anyone help?
=====================================
The C++ app uses the ConnectionPoint event sink method:
=====================================
DWORD EventSinkHolder::AddEventSink(REFIID iid, IUnknown* pYourEventSink)
{
DWORD sinkCookie = 0;
IUnknown* pEventSource = EventSourceInterface();
HASSERT(pEventSource);
LPCONNECTIONPOINTCONTAINER pConnectionPointContainer = NULL;
if (SUCCEEDED(pEventSource->QueryInterface(IID_IConnectionPointContainer, (void**)&pConnectionPointContainer)))
{
HASSERT(pConnectionPointContainer);
LPCONNECTIONPOINT pConnectionPoint = NULL;
if (SUCCEEDED(pConnectionPointContainer->FindConnectionPoint(iid, &pConnectionPoint)))
{
HASSERT(pConnectionPoint);
// connect passed event sink interface to event source
pConnectionPoint->Advise(pYourEventSink, &sinkCookie);
pConnectionPoint->Release();
// record connection for benefit of RemoveAllEventSinks
mySinkEntries.Append(new EventSinkEntry(iid, sinkCookie));
}
pConnectionPointContainer->Release();
}
return sinkCookie;
}
===================================
===================================
C#ActiveX遵循Codeplex示例"CSActiveX"中使用的标准方法.
http://1code.codeplex.com/SourceControl/changeset/view/45838#394692
=====================================
=====================================
The C# ActiveX follows the standard method used in the Codeplex sample "CSActiveX"
http://1code.codeplex.com/SourceControl/changeset/view/45838#394692
推荐答案
由于不同的调用约定,您依赖于包装器.如果您使用Google搜索,很快就会发现这一点.
Because of the different calling conventions you are dependant of the wrapper. If you search with google you soon will find proof of this.
这篇关于C#活动事件在C ++客户端中导致错误,但在VB6中有效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!