Hi
thanks for your reply
Here's a snippet of the C# DLL code. I used regasm to register the DLL.
I also attached the code for my VC++ project. Sorry if it is too long
Thanks in advance
*************************************************************
// Win32TestProg.cpp : Defines the entry point for the console application
#include "stdafx.h
#using <mscorlib.dll
#using <myDLL.dll
using namespace System
int _tmain(int argc, _TCHAR* argv[]
HANDLE handle = CreateEvent(NULL, TRUE, FALSE, NULL)
myDLL::class_a *a
a= new myDLL_AZ::class_a()
a->registerEventHandler(handle)
while (true
int ret = WaitForSingleObject(handle, -1)
System::Console::WriteLine (a->getStateVar())
Console::WriteLine(a->getStateMsg())
ResetEvent(handle)
CloseHandle (handle)
return 0
*************************************************************
using System
using System.Runtime.InteropServices
namespace
public class class_
private static class_a m_instance = null
private static readonly object padlock = new object()
private CWin32 m_win32
private int MAX_HANDLE = 10
private IntPtr [] m_handle
private int m_num_handle = 0
private short m_state
private string m_statemsg
public class_a(
/
// TODO: Add constructor logic her
/
m_handle = new IntPtr[MAX_HANDLE]
m_win32 = new CWin32()
init()
public static class_a getInstance(
lock (padlock
if (m_instance == null
m_instance = new class_a()
return m_instance
private void init(
private void OnStateChanged(short state, string message
m_state = state
m_statemsg = message
//notify the source about the even
for (int cnt=0; cnt<m_num_handle; cnt++
m_win32.win32SetEvent(m_handle[cnt])
public short getStateVar ()
{
return m_state;
public string getStateMsg ()
{
return m_statemsg;
public int registerEventHandler (IntPtr handle
if(m_num_handle > MAX_HANDLE
return -1
m_handle [m_num_handle] = handle
m_num_handle++
return 1
/// <summary
/// This class export win 32 finction signature
/// </summary
public class CWin3
//D L L I M P O R T O F W I N 3
//CONSTAN
#region CONSTAN
public static readonly IntPtr InvalidHandleValue = new IntPtr(-1)
public const UInt32 FILE_MAP_READ = 0x04
public const UInt32 PAGE_READWRITE = 0x04
#endregio
//WIN3
#region DLL IMPORT
//SET EVEN
[DllImport("Kernel32.dll",CharSet=CharSet.Auto)
private static extern Boolean SetEvent(IntPtr hEvent)
//RESET EVEN
[DllImport("Kernel32.dll",CharSet=CharSet.Auto)
private static extern Boolean ResetEvent(IntPtr hEvent)
//OPEN EVEN
[DllImport("Kernel32.dll",CharSet=CharSet.Auto)
private static extern IntPtr OpenEvent(UInt32 dwDesiredAccess,Boolean bInheritHandle,String lpName)
//CREATE EVEN
[DllImport("Kernel32.dll",CharSet=CharSet.Auto)
private static extern IntPtr CreateEvent(IntPtr lpEventAttributes,Boolean bManualReset,Boolean bInitialState,String lpName)
//CLOSE HANDL
[DllImport("Kernel32.dll",CharSet=CharSet.Auto)
private static extern Boolean CloseHandle(IntPtr hObject)
//WAIT FOR SINGLE OBJEC
[DllImport("Kernel32.dll",CharSet=CharSet.Auto)
private static extern UInt32 WaitForSingleObject(IntPtr hHandle,Int32 dwMilliseconds)
#endregio
public CWin32(
/
// TODO: Add constructor logic her
/
public Boolean win32SetEvent(IntPtr hEvent
return CWin32.SetEvent(hEvent)
public Boolean win32ResetEvent(IntPtr hEvent
return CWin32.ResetEvent(hEvent)