title: Problem with WndProc() in header file
body: <p>I have a LRESULT CALLBACK function in a header file(hook.h) that I both forward declare then define in the file(along with some classes that contain static variables). I then define(implement/create?) the static class variables in the associated .cpp file (hook.cpp).</p>
  
  <p>Finally I include the header file in my stdafx.h file so I can use it in my program.</p>
  
  <p>Because I include the hook.h file twice I get a compilation error that the LRESULT CALLBACK function is defined twice, the error is:</p>
  
  <pre><code>stdafx.obj : error LNK2005: "long __stdcall LowLevelKeyboardProc(int,unsigned int,long)" (?LowLevelKeyboardProc@@YGJHIJ@Z) already defined in main.obj
  1&gt;main.obj : error LNK2001: unresolved external symbol "protected: static class LowLevelKeyboardHookEx * LowLevelKeyboardHookEx::instance" (?instance@LowLevelKeyboardHookEx@@1PAV1@A)
  1&gt;C:\Users\Soribo\Dropbox\C++ Programming\Visual C++ Programming\Key Cataloguer\Release\Key Cataloguer.exe : fatal error LNK1120: 1 unresolved externals
  </code></pre>
  
  <p>How can I avoid this issue?</p>
  
  <p>My header file:</p>
  
  <pre><code>#ifndef KEYBOARDHOOK_H
  #define KEYBOARDHOOK_H
  
  #include "stdafx.h"
  
  LRESULT CALLBACK KeyboardProc( int code, WPARAM wParam, LPARAM lParam );
  
  class MyClass {
      public:
        static std::string instanceStr;
        // further down this class it refers to the function KeyboardProc() thus need for forward declaration
  };
  
  LRESULT CALLBACK KeyboardProc( int code, WPARAM wParam, LPARAM lParam )
  {
    // implements function
  }
  
  #endif
  </code></pre>
  
  <p>My hook.cpp file:</p>
  
  <pre><code>#include "stdafx.h"
  #include "hook.h"
  
  std::string MyClass::instanceStr = "";
  </code></pre>
  
  <p>My stdafx.h file:</p>
  
  <pre><code>#pragma once
  
  #include "targetver.h"
  
  #define WIN32_LEAN_AND_MEAN             // Exclude rarely-used stuff from Windows headers
  // Windows Header Files:
  #include &lt;windows.h&gt;
  
  // C RunTime Header Files
  #include &lt;stdlib.h&gt;
  
  // Application Specific Includes
  #include &lt;string&gt;
  #include "hook.h"       // I think this is the cause of the error because I include this file twice in compilation which means that the LRESULT function is redefined/reimplemented
  </code></pre>
  
  <p>I have also tried not including the hook.h file in hook.cpp &amp; just including stdafx.h but I get the same issue?</p>