Interop problem (.NET 2.0)

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ada Byron

    Interop problem (.NET 2.0)

    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("my dll.dll");
    //if the handle is valid try to call members
    if (hModule != IntPtr.Zero)
    {
    //get the function pointer
    IntPtr fptr = GetProcAddres(h Module, "GetInterface") ;
    if (fptr != IntPtr.Zero)
    {
    MyDelg mgi = Marshal.GetDele gateForFunction Pointer(fptr,
    typeof(MyDelg)) ;

    //here unsure ??
    IntPtr ptrModuleInterf ace;
    mgi(out ptrModuleInterf ace);
    }
    FreeLibrary(hMo dule);

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

    Thank you


    Ada@yahoo.com

    *** Sent via Developersdex http://www.developersdex.com ***
  • Willy Denoyette [MVP]

    #2
    Re: Interop problem (.NET 2.0)

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

    Willy.


    "Ada Byron" <gabriela_popa@ yahoo.com> wrote in message
    news:%23SYULg3R GHA.2300@TK2MSF TNGP11.phx.gbl. ..
    | 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("my dll.dll");
    | //if the handle is valid try to call members
    | if (hModule != IntPtr.Zero)
    | {
    | //get the function pointer
    | IntPtr fptr = GetProcAddres(h Module, "GetInterface") ;
    | if (fptr != IntPtr.Zero)
    | {
    | MyDelg mgi = Marshal.GetDele gateForFunction Pointer(fptr,
    | typeof(MyDelg)) ;
    |
    | //here unsure ??
    | IntPtr ptrModuleInterf ace;
    | mgi(out ptrModuleInterf ace);
    | }
    | FreeLibrary(hMo dule);
    |
    | Please help me to figure out the proper way to invoke that unmanged
    | function.
    |
    | Thank you
    |
    |
    | Ada@yahoo.com
    |
    | *** Sent via Developersdex http://www.developersdex.com ***


    Comment

    Working...