title: Failing to register FoxPro 6 made DLL on Win 8.1 but it registers fine on Win 7
body: <p><strong>Summary:</strong> Having two testing FoxPro made DLLs (one FoxPro 6, the other by FoxPro 9 -- see the code below), two compilers (VC++ 2010 and VC++ 2015), two machines (Windows 7 and Windows 8.1), and one C++ source with code that should register the DLLs (see below). The FoxPro 6 DLL fails to register on Windows 8.1; however, it registers fine on Windows 7.</p>
  
  <p>(See the note about the later discovery with <code>regsvr32</code>. However, the C++ code explains where it fails.)</p>
  
  <p><strong>Details:</strong> Both machines are in LAN, user logged to the same domain. Both C++ project does the static linking (Multi-threaded Debug (/MTd)) to eliminate problems with missing runtime, both use the UAC Execution Level <code>requireAdministrator</code>.</p>
  
  <p>The code for the FoxPro DLL (the FoxPro 9 version only returns 9 instead):</p>
  
  <pre><code>DEFINE CLASS APSfoxTestClass AS CUSTOM OLEPUBLIC
      PROCEDURE DllVersion()
          RETURN 6
      ENDPROC
  ENDDEFINE
  </code></pre>
  
  <p>The C++ code:</p>
  
  <pre><code>#include &lt;windows.h&gt;
  
  #include &lt;algorithm&gt;
  #include &lt;iostream&gt;
  #include &lt;string&gt;
  
  using namespace std;
  
  bool RegisterDll(std::string DllName)
  {
      // LoadLibrary() requires backslashes.
      replace(DllName.begin(), DllName.end(), '/', '\\');
  
      HMODULE hLib = LoadLibrary(DllName.c_str());
      if (hLib == 0)
          return false;
  
      // Find the DllRegisterServer entry point, and call the function.
      FARPROC lpDllEntryPoint = GetProcAddress(hLib, TEXT("DllRegisterServer"));
      HRESULT hr = E_FAIL;   // pessimistic initialization
  
      if (lpDllEntryPoint != 0)
          hr = (*lpDllEntryPoint)(); // &lt;----- here it fails for apsfoxtest.dll
                                     // but it is OK for apsfoxtest9.dll
  
      // Release the library.
      if (hLib != 0)
          FreeLibrary(hLib);
  
      // Return the status (success) of the call.
      return hr == S_OK;
  }
  
  
  bool UnregisterDll(std::string DllName)
  {
      replace(DllName.begin(), DllName.end(), '/', '\\');
      HMODULE hLib = LoadLibrary(DllName.c_str());
      if (hLib == 0)
          return false;
  
      FARPROC lpDllEntryPoint = GetProcAddress(hLib, TEXT("DllUnregisterServer"));
      HRESULT hr = E_FAIL;
  
      if (lpDllEntryPoint != 0)
          hr = (*lpDllEntryPoint)();
  
      if (hLib != 0)
          FreeLibrary(hLib);
  
      return SUCCEEDED(hr);
  }
  
  
  int main()
  {
      HRESULT hRes = CoInitialize(0);
  
      string dllname("apsfoxtest9.dll");
      cout &lt;&lt; "Registering " &lt;&lt; dllname &lt;&lt; " ... ";
      bool isOK = RegisterDll(dllname);
      cout &lt;&lt; (isOK ? "OK" : "Failed") &lt;&lt; endl;
  
      cout &lt;&lt; "Unregistering " &lt;&lt; dllname &lt;&lt; " ...";
      isOK = UnregisterDll(dllname);
      cout &lt;&lt; (isOK ? "OK" : "Failed") &lt;&lt; endl;
  
      cout &lt;&lt; "-------------------------------------------\n";
  
      dllname = "apsfoxtest.dll";
      cout &lt;&lt; "Registering " &lt;&lt; dllname &lt;&lt; " ... ";
      isOK = RegisterDll(dllname);
      cout &lt;&lt; (isOK ? "OK" : "Failed") &lt;&lt; endl;
  
      cout &lt;&lt; "Unregistering " &lt;&lt; dllname &lt;&lt; " ... ";
      isOK = UnregisterDll(dllname);
      cout &lt;&lt; (isOK ? "OK" : "Failed") &lt;&lt; endl;
  
      CoUninitialize();
  }
  </code></pre>
  
  <p>The VC++ 2015 binary was compiled on Win 8.1 machine (a newer machine, a newer compiler), but works fine on Win 7 machine for both versions of DLL. The VC++ 2010 was compiled on Win 7 machine. Both executables work fine for FoxPro 9 DLL on both Win 8.1 and Win 7, both executables fail on Win 8.1 when registering the FoxPro 6 DLL.</p>
  
  <p>When debugging (it was possible only for VC++ 2015 on Win 8.1) the execution fails when calling the <code>DllRegisterServer</code> code (at the line marked by the comment) with the <em>Access violation</em> exception see the end of the tail from the Output window: </p>
  
  <pre><code>'test_regsvr.exe' (Win32): Unloaded 'C:\__Cpp\__pepr\20150903\apsfoxtest9.dll'
  'test_regsvr.exe' (Win32): Loaded 'C:\__Cpp\__pepr\20150903\apsfoxtest.dll'. Module was built without symbols.
  'test_regsvr.exe' (Win32): Loaded 'C:\__Cpp\__pepr\20150903\VFP6R.DLL'. Module was built without symbols.
  'test_regsvr.exe' (Win32): Loaded 'C:\Windows\SysWOW64\winspool.drv'. Cannot find or open the PDB file.
  'test_regsvr.exe' (Win32): Loaded 'C:\Windows\SysWOW64\comdlg32.dll'. Cannot find or open the PDB file.
  'test_regsvr.exe' (Win32): Loaded 'C:\Windows\WinSxS\x86_microsoft.windows.common-controls_6595b64144ccf1df_5.82.9600.17810_none_7c5b6194aa0716f1\comctl32.dll'. Cannot find or open the PDB file.
  'test_regsvr.exe' (Win32): Loaded 'C:\Windows\SysWOW64\shell32.dll'. Cannot find or open the PDB file.
  'test_regsvr.exe' (Win32): Loaded 'C:\Windows\SysWOW64\mpr.dll'. Cannot find or open the PDB file.
  'test_regsvr.exe' (Win32): Loaded 'C:\Windows\SysWOW64\oleaut32.dll'. Cannot find or open the PDB file.
  'test_regsvr.exe' (Win32): Loaded 'C:\Windows\SysWOW64\winmm.dll'. Cannot find or open the PDB file.
  'test_regsvr.exe' (Win32): Loaded 'C:\Windows\SysWOW64\shlwapi.dll'. Cannot find or open the PDB file.
  'test_regsvr.exe' (Win32): Loaded 'C:\Windows\SysWOW64\winmmbase.dll'. Cannot find or open the PDB file.
  'test_regsvr.exe' (Win32): Loaded 'C:\Windows\SysWOW64\devobj.dll'. Cannot find or open the PDB file.
  'test_regsvr.exe' (Win32): Loaded 'C:\Windows\SysWOW64\SHCore.dll'. Cannot find or open the PDB file.
  Invalid parameter passed to C runtime function.
  Invalid parameter passed to C runtime function.
  'test_regsvr.exe' (Win32): Loaded 'C:\__Cpp\__pepr\20150903\VFP6RENU.DLL'. Module was built without symbols.
  Exception thrown at 0x0C00D2BF (VFP6R.DLL) in test_regsvr.exe: 0xC0000005: Access violation reading location 0x00000000.
  </code></pre>
  
  <p><strong>Later found:</strong> The <code>regsvr32 apsfoxtest.dll</code> called from the <code>cmd</code> launched <em>as administrator</em> probably also fails (the final message box with the success message does not appear).</p>
  
  <p><strong>May be related:</strong> We have observed a possibly related problem when the application that used the FoxPro 6 DLL was executed on Windows servers. It failed because of the DEP mechanism (Data Execution Prevention). The DEP exception for the application had to be added.</p>
  
  <p>Do you have similar experience with FoxPro 6 and the Windows 8.1? Can the FoxPro 6 DLL be fixed somehow?</p>