views:

167

answers:

1

This is my second question of the day, pardon me.

I am writing a wrapper library to communicate with a scanner device. The source code was in C++ MFC. I am converting it to a plain Dll which will be invoked from C#. So, I am using DllImport in C# to call the wrapper library.

Now I am provided with MFC code and the library is a ActiveX Object, at least I think so.

class CDpocx : public CWnd
{
}

So in my wrapper library I will have an instance of CDpocx and will call it via C# P/Invoke. But the problem is CDpocx also throws some events which I need to catch. In traditional app, I would just attach an function with it. But How would I attach the events on non MFC class.

I have seen something like:

BEGIN_EVENTSINK_MAP(CVC60Dlg, CDialog)
    //{{AFX_EVENTSINK_MAP(CVC60Dlg)
    ON_EVENT(CVC60Dlg, IDC_DPOCXCTRL1, 1 , OnReadyDpocxctrl1, VTS_NONE)
    //}}AFX_EVENTSINK_MAP
END_EVENTSINK_MAP()

OnReadyDpocxctrl1 is the function that handles 1 (Ready) event.

How can I gain simmilar function in non MFC class.

Regards, Maksud

A: 

I'm not sure if this is what you want, but if you want to call an ActiveX component from C#, you should use Windows Forms ActiveX Control Importer (Aximp.exe) which will convert the type definitions in a COM type library for an ActiveX control into a Windows Forms control.

fretje
Thanks. Will try this. Actually the problem is that, I have driver and sample code for both C++ and VisualBasic. C++ version (originally was in VC6 converted to VC++.NET 2008) works perfectly while visual basic version (VB6 converted into VB.NET and again converted into VC#.NET) does not work as expected. So I was tempted to create a C++ Wrapper which will be called from C#, Again. I will try your solution.
Maksud