Note that there are some explanatory texts on larger screens.

plurals
  1. POUnresolved External Symbol when using dllexport and specific function name
    primarykey
    data
    text
    <p><strong>EDIT</strong></p> <p>To get around the problem, I added the following to the (beginning of the) header file:</p> <pre><code>#ifdef GetMessage #undef GetMessage static inline BOOL GetMessage( LPMSG lpMsg, HWND hWnd, UINT wMsgFilterMin, UINT wMsgFilterMax ) { #if UNICODE return ::GetMessageW(lpMsg, hWnd, wMsgFilterMin, wMsgFilterMax); #else return ::GetMessageA(lpMsg, hWnd, wMsgFilterMin, wMsgFilterMax); #endif } #endif </code></pre> <hr> <p>I'm creating a C++ DLL (using Visual Studio 2008) from code like the following:</p> <p>Header File:</p> <pre><code>#include &lt;windows.h&gt; // Edit: This is the culprit. class __declspec(dllexport) TestBaseClass { protected: char m_Message[512]; public: TestBaseClass(); virtual char* GetMessage(void) = 0; }; class __declspec(dllexport) TestDerivedClass : public TestBaseClass { public: TestDerivedClass(); virtual char* GetMessage(void); }; </code></pre> <p>CPP File:</p> <pre><code>TestBaseClass::TestBaseClass() { } TestDerivedClass::TestDerivedClass() : TestBaseClass() { } char* TestDerivedClass::GetMessage(void) { sprintf(m_Message, "This is a Message"); return m_Message; } </code></pre> <p>When I go to compile the DLL, I get a linker error:</p> <blockquote> <p>error LNK2001: unresolved external symbol "public: virtual char * __thiscall TestDerivedClass::GetMessageA(void)" (?GetMessageA@TestDerivedClass@@UAEPADXZ)</p> </blockquote> <p>If I change every instance of "GetMessage" to something else (e.g. "TestFunc"), I do not get the linker error.</p> <p><strong>Primary Question</strong>: Why can't I use "GetMessage" as my function name?</p> <p><strong>Secondary Question</strong>: Is there a way to resolve the linker error, and keep "GetMessage" in my class, as currently defined?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload