How to compile a c++ dll using visual studio?

13,147

Solution 1

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

You say that you did this, but it should not be looking for WinMain then. To double check you're really building a DLL, look in project settings -> General, and check that:

  1. "Configuration type" is "Dynamic Library (.dll)"
  2. Use of MFC is set to "Use Standard Windows Libraries"
  3. Use of ATL is "Not using ATL"

Solution 2

For some reason the project got configured to build a .exe.

But you can easily fix your project. Open the properties dialog and go to "Configuration Properties/General". On the right side locate the "Configuration Type" item and change it from "Application" to "Dynamic Library".

Also keep in mind that you need to change this on all the configurations (i.e. Debug and Release).

Solution 3

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

Share:
13,147
Pedro
Author by

Pedro

Updated on June 13, 2022

Comments

  • Pedro
    Pedro almost 2 years

    I have some c++ classes that I'd like to compile into a dll file. When I am trying to compile the project, I receive an unresolved external symbol error:

    1. error LNK2019: unresolved symbol _WinMain@16 referenced in function tmainCRTStartup
    2. fatal error LNK1120: 1 unresolved external

    This is what I've done so far:

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

    Furthermore I added a file "DllMain.cpp" containing this code:

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