Interop problem (.NET 2.0)

A

Ada Byron

Hello,

I need to load in my C# .nET 2.0 application an dll (not COM)written in
Delphi. The dll has a function which returns a pointer to an IModule
interface defined in that dll.
How do I declare my delegate and call the unmanaged function?

I did something like that;

//here unsure if this should be the signature ??

internal delegate MyDelg (out IntPtr IModule);

IntPtr hModule = LoadLibrary("mydll.dll");
//if the handle is valid try to call members
if (hModule != IntPtr.Zero)
{
//get the function pointer
IntPtr fptr = GetProcAddres(hModule, "GetInterface");
if (fptr != IntPtr.Zero)
{
MyDelg mgi = Marshal.GetDelegateForFunctionPointer(fptr,
typeof(MyDelg));

//here unsure ??
IntPtr ptrModuleInterface;
mgi(out ptrModuleInterface);
}
FreeLibrary(hModule);

Please help me to figure out the proper way to invoke that unmanged
function.

Thank you


(e-mail address removed)
 
W

Willy Denoyette [MVP]

And what is this IModule pointer pointing to? You can't call Interfaces, you
can only call functions.

Willy.


| Hello,
|
| I need to load in my C# .nET 2.0 application an dll (not COM)written in
| Delphi. The dll has a function which returns a pointer to an IModule
| interface defined in that dll.
| How do I declare my delegate and call the unmanaged function?
|
| I did something like that;
|
| //here unsure if this should be the signature ??
|
| internal delegate MyDelg (out IntPtr IModule);
|
| IntPtr hModule = LoadLibrary("mydll.dll");
| //if the handle is valid try to call members
| if (hModule != IntPtr.Zero)
| {
| //get the function pointer
| IntPtr fptr = GetProcAddres(hModule, "GetInterface");
| if (fptr != IntPtr.Zero)
| {
| MyDelg mgi = Marshal.GetDelegateForFunctionPointer(fptr,
| typeof(MyDelg));
|
| //here unsure ??
| IntPtr ptrModuleInterface;
| mgi(out ptrModuleInterface);
| }
| FreeLibrary(hModule);
|
| Please help me to figure out the proper way to invoke that unmanged
| function.
|
| Thank you
|
|
| (e-mail address removed)
|
|
 

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