Windows HAndles C# to C++

G

Guest

I would liek to create a window in C# and pass the handle and the hInstance
to an unmanaged c++ dll for some DirectX stuff. I have many iterations and
get nowhere. The HWND gets an null reference exception. The HINSTANCE in
the C++ is not the same as the C# instance. Anyway here was the latest

C++
__declspec(dllexport) void CvpCSILibApp::setWnd(HWND win);
__declspec(dllexport) void CvpCSILibApp::setHI(HINSTANCE win);

in the C# Wrapper DSWrapper
System.IntPtr
p=Marshal.GetHINSTANCE(System.Reflection.Assembly.GetExecutingAssembly().GetModules()[0]);
DSWrapper.setHI(p);

and
DSWrapper.setWnd(myWin.Handle);
Any Help?
John





[ DllImport("vpCSILib.dll")]
public static extern void setWnd(System.IntPtr wnd);

[ DllImport("vpCSILib.dll")]
public static extern void setHI(System.Int32 wind);

In the C# implementation:
 
C

Claes Bergefall

Since both HINSTANCE and HWND is a typedef for void*
you might have some luck with the IntPtr.ToPointer method

/claes
 
G

Guest

Yes but many of the win32 api take HWND
and one can simply pass IntPtr as I have done.
Since the C++ DLL is mine, do I need to do anything differently to allow
this to get in? And OBTW, I have tried IntPtr.ToPointer, ToInt32 with a
multitude of casting and
set the C++ to managed and converted it there as well....
John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top