Voilà l'exemple mis au propre :
// C++
#define EXTERN_C extern "C"
#define DLLEXPORT __declspec(dllexport)
class DLLEXPORT Device
{
private:
HWND m_hWnd;
public:
Device( HWND hWnd );
~Device( );
BOOL Clear( UINT color );
};
EXTERN_C DLLEXPORT Device* CreateDevice( HWND hWnd )
{
Device* pDevice = new Device( hWnd );
return pDevice;
}
EXTERN_C DLLEXPORT void DestroyDevice( Device* pDevice )
{
if ( pDevice != NULL )
{
delete pDevice;
//pDevice = NULL;
}
}
// C#
[ SuppressUnmanagedCodeSecurity ]
internal sealed class Device
{
private const string DLL_NAME = @"GX.dll";
[ DllImport( DLL_NAME, CallingConvention = CallingConvention.StdCall ) ]
public static extern IntPtr CreateDevice( IntPtr hWnd );
[ DllImport( DLL_NAME, CallingConvention = CallingConvention.StdCall ) ]
public static extern void DestroyDevice( IntPtr pDevice );
[ DllImport( DLL_NAME,
CallingConvention = CallingConvention.ThisCall,
EntryPoint = " ?Clear@Device@@QAEHI@Z " ) ]
[ return: MarshalAs( UnmanagedType.Bool ) ]
public static extern bool Clear( IntPtr pDevice, int color );
}