Hi, I've been searching Google trying to find an answer to this.

I've got a C# class that is trying to load an unmanaged DLL with C-style exports. I'm 
using LoadLibraryEx() and GetProcAddress().

Unfortunately GetProcAddress() returns a function pointer (Marshal.IntPtr).

[DllImport("kernel32.dll")] static extern IntPtr GetProcAddress(IntPtr hModule, string 
lpProcName);

I'm trying to figure out how to covert the IntPtr into a Delegate so I can call it 
from my C# code.

I've tried the following, but get an ArgumentException: Function pointer not created 
by a Delegate.

[DllImport("kernel32.dll")][return : MarshalAs(UnmanagedType.FunctionPtr)]
static extern MyDelegate GetProcAddress(IntPtr hModule, string lpProcName);


It appears that .NET 2.0 will have a method 

        Marshal.GetDelegateForFunctionPointer().

<http://longhorn.msdn.microsoft.com/lhsdk/ref/ns/system.runtime.interopservices/c/marshal/m/getdelegateforfunctionpointer.aspx>

I was wondering if anyone knew of the equivalent code for .NET 1.x.

Any help would be greatly appreciated.

Thanks!
�

Michael

===================================
This list is hosted by DevelopMentor�  http://www.develop.com
Some .NET courses you may be interested in:

NEW! Guerrilla ASP.NET, 26 Jan 2004, in Los Angeles
http://www.develop.com/courses/gaspdotnetls

View archives and manage your subscription(s) at http://discuss.develop.com

Reply via email to