Reputation: 507
Before I ask my question, here are some informations about my development environment:
Operating System: Windows 64 bit
IDE: Visual Studio 2013
I would like to control a device over a C# project. What I have got from the producer of the device: a .h-file and a static library (.lib-file). In a C++-Console-Application the controlling works fine. But now I have some issues to build a DLL for C#
To build such a .dll-file I created an empty C++ DLL Console-Application, copied the .h-file into the project and referenced the .lib-file to the linker (added an "additional library direction" and an "additional dependency" in the solution settings).
But at this step, the problem occurs. When I build the project, the console prints
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
The log files do not show any errors but I have no DLL file in the Debug (or Release) folder.
What I tried: I added a "fake" .cpp-file where I implement one of the functions from the .h-file -> dll is built. So I guess that Visual Studio does not recognize the .lib file.
The next step would be to write a C# "wrapper" with the DllImport commands.
Thank you in advance for all answers and tips.
Upvotes: 3
Views: 3926
Reputation: 30105
On Window's, functions are not automatically exported from DLL's, either ones in the builds own source files (c/cpp) or from linked static libraries.
You could export them by adding __declspec(dllexport)
to the function declarations, or you can add a "Module-Definition File (.def)" to the project, and list the functions to export. For example here a function foo
can be from a static lib included in my DLL.
LIBRARY TEST
EXPORTS
foo @1
For it not creating a file at all, not sure if MS consider it a bug or feature, but it does not create the DLL if the project has no actual source files. You need at least one, it can even be empty.
Upvotes: 2