import unmanaged dll into c sharp

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rorybr
    New Member
    • Apr 2010
    • 2

    #1

    import unmanaged dll into c sharp

    hi,
    i'm trying to import an unmanaged dll into a c# application. The dll is given to me but i'm new with dll import thing and having some troubles importing it. Dll comes with a pdf file which describes the functions but all parameters and types are c++ type and i need to write them as c# types. i tried "Dllimport" but i think i couldn't write the correct parameter types. Functions use handles and pointers which doesn't make it easier for me. If someone can write the correct syntax and usage of the functions, i will be most grateful. im writing the functions as described in the pdf:

    Comm_Init function: Initializes the DLL for first time loading. Gets a window handle (HWND) as
    parameter.

    Code:
    void Comm_init
    (
    HWND wndHandle
    );
    Comm_create function: creates a TCP communication to device using ip address and TCP port number.

    Code:
    TCommHnd Comm_create
    (
    char *address,
    int port,
    mEventHandler eventHandler,
    int synchComm
    );
    these are the main functions i need to figure out. And there is a type definition (TCommHnd) which described as "typedef void* TCommHnd;" .

    Comm_init function initializes DLL, for further usage. It is not a thread safe
    function, it should be called one time during the operation of the DLL. All functions except
    Comm_init are thread safe functions, for different TCommHnd’s.

    I wrote the type definitions and functions into a class file in my project and tried to use the functions in the program. But i think i made some mistakes either in definitions or in usage. I dont really know anything about dllimport and handles but i really need to figure this one out. should i use LoadLibrary and GetProcAddress? Any help will be appreciated,

    Best regards
    Last edited by tlhintoq; Apr 25 '10, 04:41 PM. Reason: [CODE] ...Your code goes between code tags [/CODE]
  • tlhintoq
    Recognized Expert Specialist
    • Mar 2008
    • 3532

    #2
    TIP: When you first created your question you were asked to wrap your code with [code] tags.
    [imgnothumb]http://files.me.com/tlhintoq/10jihf[/imgnothumb]
    It really does help a bunch. Look how much easier it is to read now that someone has done it for you. Its the button with a '#' on it. More on tags. They're cool. Check'em out.

    Comment

    • tlhintoq
      Recognized Expert Specialist
      • Mar 2008
      • 3532

      #3
      Are you using this DLL because you need *other* functions as well, or because you thought it would be an easy shortcut to TCP/IP communication?

      If you don't need other functions that are in the DLL, it might be a lot cleaner for your application to just to TCP/IP within C#

      There is an exampel TCP client/server on the MSDN

      Comment

      • rorybr
        New Member
        • Apr 2010
        • 2

        #4
        I'm using this dll because i need to use other functions of the dll... dll is not just a TCP/IP dll... it creates modbusTCP/IP communication with some specific devices... thats why i have to use it

        Comment

        Working...