I want to create a dll in visual c#, and use it in win32 program (visual c++).
From what I understand, for adding dll file in Visual C++ , I need also .h file and .lib file, but when I create a class library in visual c# I only get dll file.
Is it possible to create a .h file and .lib file in visual c# ?
Asked
Active
Viewed 3,816 times
1

user1544067
- 1,676
- 2
- 19
- 30
-
Read this: http://stackoverflow.com/questions/4818850/is-is-possible-to-export-functions-from-a-c-sharp-dll-like-in-vs-c – Steve B Jan 16 '13 at 13:36
2 Answers
5
No, it's not possible. But here is what you can do to use a C# library in C++:
- C++/CLI Wrapper (this allows you to have both managed and unmanaged code in the same source file. The managed portion can then call the C# code). Here you can find an example.
- Host CLR (the CLR acts as a library that can be loaded and "hosted" by a process).
- COM Interop (expose your .NET type as a COM interface and matching coclass which you can easily use from unmanaged C++).
This thread is also quite interesting!

Tommaso Belluzzo
- 23,232
- 8
- 74
- 98
-
I'm trying the first solution, I use a version of Visual Studio Express, can I create an empty solution? – user1544067 Jan 16 '13 at 15:46
-
-
this what written [here](http://code.msdn.microsoft.com/windowsdesktop/Consuming-C-Library-in-937458e5) Step 1. Create a empty solution. – user1544067 Jan 16 '13 at 15:56
-
Well just create a simple library project for a simple C# library. That's what he means. – Tommaso Belluzzo Jan 16 '13 at 15:57
-
if I will do it in visual c#, how will I create a C++ project in visual c#? – user1544067 Jan 16 '13 at 16:04
-
Well just stick on that guideline, it should do the job for you. You have to choose a C++ project type from the list of available projects types when you select to create a new project in VS: Templates -> Visual C# -> Class Library. – Tommaso Belluzzo Jan 16 '13 at 16:05
-
0
You could use LoadLibrary and GetProcAddress to load the DLL dynamically and you wouldn't need to create the files you refer to. You can read more here.

Belogix
- 8,129
- 1
- 27
- 32
-
This way can you also create instances of a class defined in the dll? – user1544067 Jan 16 '13 at 14:46