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:

Re: Windows HAndles C# to C++ by Claes

Claes
Mon Oct 17 02:32:06 CDT 2005

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

/claes

"PleaseHelp" <PleaseHelp@discussions.microsoft.com> wrote in message
news:A8ED6EC0-9990-4FFE-9720-2B42C776E0DF@microsoft.com...
>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:
>
>



RE: Windows HAndles C# to C++ by PleaseHelp

PleaseHelp
Mon Oct 17 07:06:03 CDT 2005

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

"PleaseHelp" wrote:

> 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:
>
>