I have a dll created using C++, which i want to use in my C# prgm. How should i convert it. Also I have header files, how can i use them in my C# prgm. Can anyone guide me or provide some good materials.


8 Years
Discussion Span
Last Post by sknake

There's no need to translate anything in terms of the DLL. See this link: http://msdn.microsoft.com/en-us/library/aa288468(VS.71).aspx What do the header files contain? With the dll import you will be specifying your function prototypes right in the C# code. Any #defines can be translated into consts (or into methods if they define macros).

Edited by jonsca: n/a


Ya u r right, I dont want to convert the source code just the dll. K I use PInvoke to convert the dll. What abt Header files.....


My header files contain #define and typedef stmts..... So to replace typedef should i use the delegate???


I'm not 100% sure. I honestly don't have the experience with this kind of thing. That article seems to cover what to do with typedefs but in the context of a struct. People that know more about this kind of thing will probably pick up on the thread. I just didn't want you to think you had to scrap and translate everything. I wish I could be more help.

Votes + Comments
good advice

What type of DLL is it and do you want to maintain C++ or are you wanting to move your code over to C#? You can use DllImport to define the signatures and call the method:

    private static extern long ShellExecute(Int32 hWnd, string lpOperation,
    string lpFile, string lpParameters, string lpDirectory, long nShowCmd);

    private enum SW
      SW_HIDE = 0,

    private void OpenNotepad()
      ShellExecute(0, "open", "notepad.exe", null, null, (long)SW.SW_SHOWNORMAL);

The question is do you want this code to run natively or are you happy with exporting the method calls? You can do it either way. I personally prefer having all managed code.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.