importing from an unmanaged DLL

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Nkolsen
    New Member
    • Feb 2008
    • 3

    importing from an unmanaged DLL

    Hi

    I know this issue have been here before, but im struggeling with my problem.
    Im trying to import an unmanaged DLL from C to C#.

    From the headerfile i have the following declaration:

    extern "C"_declspec(dl lexport)
    long _stdcall TCatIoGetInputP tr( unsigned short nPort, void** ppInput, int nSize );

    with the following variable description:

    ppInp:
    Address of the pointer to get the address of the output buffer. If TCatIoGetInputP tr succeeds, the pointer is initialized to the address of the input buffer.



    I thought i could use something like:

    [DllImport("TCat IoDrv.dll", SetLastError = true)]
    public static extern int TCatIoGetInputP tr(ushort nPort, byte [] ppInput,
    int nSize);

    But it doesnt seem to work.


    Any one who could help ?


    Thanks,

    Nikolaj
  • Plater
    Recognized Expert Expert
    • Apr 2007
    • 7872

    #2
    Do you have .def file in your unmanaged DLL?

    I have one for my "TestFixtureDLL .dll" that looks something like this:
    Code:
    ; TestFixtureDLL.def : Declares the module parameters for the DLL.
    
    LIBRARY      "TestFixtureDLL"
    
    EXPORTS
        ; Explicit exports can go here
    	DllCanUnloadNow     PRIVATE
    	DllGetClassObject   PRIVATE
    	DllRegisterServer   PRIVATE
    	DllUnregisterServer PRIVATE
    	writelocalbus
    	readlocalbus
    	swritelocalbus
    	sreadlocalbus
    The four functions I want available to managed code were:
    writelocalbus
    readlocalbus
    swritelocalbus
    sreadlocalbus
    NOTE: That is not their function defs, for instance writelocalbus is really:
    Code:
    bool writelocalbus(UINT16 Offset, UINT16 Data)
    {
    //....
    }
    The other four functions were required by the DLL to be used in managed code (I think, maybe they are just general DLL requirements)

    Comment

    • Nkolsen
      New Member
      • Feb 2008
      • 3

      #3
      I only have the header file for the function calls, so im not able to see what is in the .DLL.

      My problem is what to do with the double void pointer in C# ? Can I just use a bytearray?

      Comment

      • Plater
        Recognized Expert Expert
        • Apr 2007
        • 7872

        #4
        Originally posted by Nkolsen
        My problem is what to do with the double void pointer in C# ? Can I just use a bytearray?
        I didn't even see that void **, you might ahve to read into the Marshalling section in MSDN about what to do with void **. This goes beyond my realm of unamanged DLL usage.

        Comment

        • Nkolsen
          New Member
          • Feb 2008
          • 3

          #5
          Yea have been there looking for solutions, but cant find much specifically about my issue..

          Comment

          • Plater
            Recognized Expert Expert
            • Apr 2007
            • 7872

            #6
            Have you tried using IntPrtr for void** ?

            Comment

            Working...