I'm developing a C# application (VS2017, .NET4.6.1) which uses an ocx COM componet, written in Delphi by another company. regsvr32 the ocx and add reference to a WinForm project. Instantiating the COM object and calling methods works fine (tested), but when I attach to more than one event, I get the following COMException: System.Runtime.InteropServices.COMException:'Exception from HRESULT:0x80040202'
I searched in google and found someone encounter this exception too. https://social.msdn.microsoft.com/Forums/vstudio/en-US/46fa8073-5d45-4f68-8168-a3826b23f671/hresult-0x80040202-on-attaching-more-than-one-event-to-oop-com-object?forum=csharpgeneral I try to follow this post, but it doesn't work. But there's no Solution. This ocx is work fine for delphi.
The screenshot is the detail of the ocx: enter image description here
Who can help me? Thanks.
add my code: enter image description here
spIpOcxNewClass spIpOcxNew1 = new spIpOcxNewClass();//spIpOcxNewClass is COM component
private void Main_Load(object sender, EventArgs e)
{
spIpOcxNew1.OnConnected += SpIpOcxNew1_OnConnected; //This event subscript is OK.
}
//connect
private void btnInit_Click(object sender, EventArgs e)
{
var strAppIP = tbIP.Text.Trim();
var nPort = Convert.ToInt32(nudPort.Value);
spIpOcxNew1.SHeartbeatInterval = Convert.ToInt32(nudHeart.Value);
spIpOcxNew1.SInit(strAppIP, nPort);
}
//After connected, it raise a event, then I subscript more event.
private void SpIpOcxNew1_OnConnected()
{
lblState.Text = "Connected";//Connected
spIpOcxNew1.OnDisConnected += SpIpOcxNew1_OnDisConnected;//Subscript second event will throw exception
spIpOcxNew1.OnLoginSucceed += SpIpOcxNew1_OnLoginSucceed;
}
User contributions licensed under CC BY-SA 3.0