CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Jun 2001
    Location
    USA
    Posts
    298

    Using a C++ DLL with C#

    I have a 3rd party dll written in VC6.0 that I want to use within a C# application. When I call one of the exported functions I get a can't find entry point exception.

    The dll is called diodrv.dll and there are 4 exported functions. Dumpbin and Depends both report this:

    File Type: DLL

    Section contains the following exports for diodrv.dll

    ordinal hint RVA name

    1 0 00001110 ?CloseDio@@YGXXZ
    2 1 00001040 ?CreateDio@@YGKXZ
    3 2 00001080 ?ReadDioReg@@YGKK@Z
    4 3 000010D0 ?WriteDioReg@@YGXKK@Z

    I have the source code and VC6 project for the dll. The function definitions are like this:
    Code:
    #define DIODRV_API __declspec(dllexport)
    
    DIODRV_API DWORD __stdcall CreateDio(void);
    My C# for importing the functions is this:

    Code:
    [DllImport("diodrv.dll")]
    static extern Int32 CreateDio();
    What's the best way to get access to these functions?

    Thanks

  2. #2
    Join Date
    Oct 2006
    Location
    Sweden
    Posts
    3,654

    Re: Using a C++ DLL with C#

    This isn't really my area but you might try setting ExactSpelling to false. See http://msdn.microsoft.com/en-us/library/7b93s42f.aspx
    Debugging is twice as hard as writing the code in the first place.
    Therefore, if you write the code as cleverly as possible, you are, by
    definition, not smart enough to debug it.
    - Brian W. Kernighan

    To enhance your chance's of getting an answer be sure to read
    http://www.codeguru.com/forum/announ...nouncementid=6
    and http://www.codeguru.com/forum/showthread.php?t=366302 before posting

    Refresh your memory on formatting tags here
    http://www.codeguru.com/forum/misc.php?do=bbcode

    Get your free MS compiler here
    https://visualstudio.microsoft.com/vs

  3. #3
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Using a C++ DLL with C#

    The name mangling is messing you up.

  4. #4
    Join Date
    Jun 2001
    Location
    USA
    Posts
    298

    Re: Using a C++ DLL with C#

    Quote Originally Posted by Arjay View Post
    The name mangling is messing you up.
    OK.. Is there some way to rebuild the dll such that the names aren't mangled?

  5. #5
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Using a C++ DLL with C#

    Quote Originally Posted by Dave C View Post
    OK.. Is there some way to rebuild the dll such that the names aren't mangled?
    I would use a .def file.

    http://msdn.microsoft.com/en-US/libr...(v=vs.80).aspx

  6. #6
    Join Date
    Jun 2001
    Location
    USA
    Posts
    298

    Re: Using a C++ DLL with C#

    Thank you Arjay - the DEF file worked.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured