What I am doing is trying to porting C++ code to C#.
In the C++ code one of the function calls uses the handle returned from
LoadLibrary() as a parameter. Since I am using the "DLLImport" I don't have
that handl to pass into the function. I am looking for a way in C# to get the
same handle as if I had called LoadLibrary().
Any suggestions on how I would get this.
And just as a follow up to my first question the
"Process.GetCurrentProcess().Handle" is not correct. To get the hWnd I think
I need to do the following:
myForm.Handle.ToInt32()
Thanks.
"Mattias Sjögren" wrote:
> I am trying to call into some C++ code from C#. One of the functions
> requires a handle to the instance (HINSTANCE hInstance) of the C#
> program. How do I access this in C#.
I believe what you are looking for is:
Process.GetCurrentProcess().Handle
No that'll give you a process handle. What you need is something like
Marshal.GetHINSTANCE(typeof(YourType).Module).
The C++ code is
doing a LoadLibrary() to get a handle of the DLL being loaded. Is there a way
of getting the handle to the DLL in C# if I am using DllImport as in:
You can call LoadLibrary from managed code as well if you want but I'm
not sure why you need it in this case.
Mattias
--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.