title: ESP was not properly saved across a function call when using function pointers
body: <p>I am trying to create a program which saves the function pointer of a member function to an array. The program then takes the function pointer from that array and calls the function said pointer points to. This works as long as the member function used does not have any arguments. When I give it arguments the following error occurs in Visual Studio 2017:</p>
  
  <blockquote>
    <p>Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call.  This is usually a result of calling a function declared with one calling convention with a function pointer declared with a different calling convention.</p>
  </blockquote>
  
  <p>My code is:</p>
  
  <pre><code>typedef uint8_t byte;
  
  template&lt;typename T&gt;
  class Test
  {
  public:
      void FuncTest(byte* data)
      {
          cout &lt;&lt; (T)(0.0625f) &lt;&lt; endl;
      }
  };
  
  typedef Test&lt;float&gt; fTest;
  typedef Test&lt;long long&gt; lTest;
  
  int main()
  {
      byte data[1024];
  
      {
          void (fTest::*ffp)(byte*) = &amp;fTest::FuncTest;
          //void (lTest::*lfp)(byte*) = &amp;lTest::FuncTest;
  
          printf("%p\n", ffp);
  
          memcpy(&amp;data[0], (int64*)&amp;ffp, sizeof(int64));
      }
  
      {
          int64 pData;
  
          memcpy(&amp;pData, &amp;data[0], sizeof(int64));
  
          void(*func_pointer)(byte*) = (void(*) (byte*))(pData);
  
          printf("%p\n", pData);
  
          func_pointer(nullptr);
      }
  }
  </code></pre>
  
  <p>If anyone could help, it would be greatly appreciated.</p>