错误 LNK 2005 & LNK1169 C++ Visual Studio DLL

Error LNK 2005 & LNK1169 C++ Visual Studio DLL

我正在尝试为 OBS 创建一个 DLL 插件,但是当我尝试编译一个简单的脚本时,出现了以下错误 -

Error   1   error LNK2005: _DllMain@12 already defined in dllmain.obj   c:\Users\user\documents\visual studio 2013\Projects\name\nameEnhanced\nameEnhanced.obj  nameEnhanced

Error   2   error LNK1169: one or more multiply defined symbols found   c:\users\user\documents\visual studio 2013\Projects\name\Debug\nameEnhanced.dll 1   1   nameEnhanced

我创建了一个简单的脚本,它只有 2 个文件,即 -

handle.h
nameEnhanced.cpp

这些是我的文件 -

handle.h

#include <windows.h>
#include <string>
using namespace std;

namespace MsgeBox
{
    class myMessage
    {
    public:
        static void createMessage(HWND windowsOwner, LPCWSTR theMessage, LPCWSTR theTitle, UINT theIcon){
            MessageBox(windowsOwner, theMessage, theTitle, theIcon);
        }
    };
}

nameEnhanced.cpp

 // nameEnhanced.cpp : Defines the exported functions for the DLL application.
    //

#include "stdafx.h"
#include <Windows.h>
#include "handle.h"

BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
    MsgeBox::myMessage::createMessage(NULL, (LPCWSTR)"Hello", (LPCWSTR)"I See You.", MB_ICONWARNING | MB_CANCELTRYCONTINUE);
    switch (fdwReason)
    {
    case DLL_PROCESS_ATTACH:
        // attach to process
        // return FALSE to fail DLL load
        break;

    case DLL_PROCESS_DETACH:
        // detach from process
        break;

    case DLL_THREAD_ATTACH:
        // attach to thread
        break;

    case DLL_THREAD_DETACH:
        // detach from thread
        break;
    }
    return TRUE; // successful
}

我已尝试删除 dllmain.obj 文件,但没有成功

我使用 https://msdn.microsoft.com/en-us/library/windows/desktop/ms645505(v=vs.85).aspx 作为我的代码的基础

我相信 Visual Studio 提供了一个带有 DLL 项目模板的 dllmain.cpp 源文件,你说:

I've tried to delete the dllmain.obj file but that didn't work

然而,这不会阻止它在每次构建时被重新创建。您需要清理项目,然后从项目中删除 dllmain.cpp