How to compile C ++ dll using visual studio?

I have some C ++ classes that I would like to compile into a dll file. When I try to compile the project, I get an unresolved external character error:

  • error LNK2019: unresolved _WinMain @ 16 character specified in tmainCRTStartup function
  • fatal error LNK1120: 1 unresolved external

This is what I have done so far:

I just created a new win32 project, the selected dll and an empty project. Then I copied all the h and cpp files to the directory and added them to the project.

In addition, I added the file "DllMain.cpp" containing this code:

#include <windows.h> BOOL APIENTRY DllMain( HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved ) { return TRUE; } 
+4
source share
3 answers

When creating a new Win32 application project, select "Application Settings" in the wizard and select "DLL" for the type of application. It will start with an empty DllMain .

You say you did it, but you shouldn't look for WinMain . To double check that you are actually creating a DLL, look in the project settings → General and make sure that:

  • "Configuration Type" is the "Dynamic Library (DLL)"
  • Use of MFC is set to "Use standard Windows libraries"
  • Using ATL - Do Not Use ATL
+1
source

For some reason, the project received a configuration for creating .exe.

But you can easily fix your project. Open the properties dialog and go to the "Configuration Properties / General" section. On the right side, find the “Configuration Type” element and change it from “Application” to “Dynamic Library”.

Also keep in mind that you need to change this on all configurations (i.e. debugging and release).

+3
source

This link can help you http://msdn.microsoft.com/en-us/library/799kze2z (v = vs .80) .aspx also check the linker settings in the project properties dialog box. If you use additional libraries, make sure their paths are set on the linker tab.

+1
source

All Articles