2016-04-25 59 views
-1

我試圖創建OBS一個DLL插件,但是當我嘗試編譯一個簡單的腳本,它給了我下面的錯誤 -錯誤LNK 2005和LNK1169 C++的Visual Studio DLL

Error 1 error LNK2005: [email protected] 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作爲我的代碼的基礎

回答

1

我相信Visual Studio提供了一個dllmain.cpp源文件與DLL項目模板和你說:

我試圖刪除dllmain.obj文件,但沒有奏效

但是,這不會阻止它在每個構建中被重新創建。您需要清理該項目,然後從項目中刪除dllmain.cpp

+0

我對使用Visual Studio不是很熟悉。 – Gerwin

+0

所以你需要我告訴你如何從項目中刪除源文件?這不會發生。 – trojanfoe

+0

好吧,那個工作,我從來沒有要求你告訴我如何刪除一個文件,我只是認爲你的意思是別的,不需要攻擊人。 – Gerwin