Hello,
I have the following question:
I am trying to create two win32 console applications with MFC support First.exe and Second.exe. Second.exe is exporting a function to First.exe using "__declspec(dllexport)" and First.exe is calling the exported function
Code snippet Second.exe:
Code:
int global;
__declspec(dllexport) int a() 
{
     unsigned int dummy;
    dummy = 0xFFFFFFFF;
    dummy = 0xFFFFFFFF;
    dummy = 0xFFFFFFFF;
    .
    .    /*-> Hundreds  of "dummy = 0xFFFFFFFF;"*/
    .
    dummy = 0xFFFFFFFF;

   global = 1;
   return 1;
}
Code snippet First.exe:
Code:
__declspec(dllimport) int a();

int _tmain(int argc, TCHAR* argv[], TCHAR* envp[]) {
  // initialize MFC and print and error on failure
  // ....
  a();
   return 0;
}
Depening on the number of "dummy = 0xFFFFFFFF;" used in Secound.exe; First.exe is running normal or is crashing at runtime with eror message: "Unhandled excepton in FIRST.exe(Second.exe): 0xC0000005: Access Violation.". First.exe is running fine if only few dummy instructions ("dummy = 0xFFFFFFFF") are used and is crashing when hundreds of dummy instructions are used in Second.exe.

When the program crashes then it always crash at instruction "global = 1;" that is translated in disassembly to:
"mov dword ptr ds:[416668h],1" where 416668h is the address of variable "global" out of the map file of Second.exe"
When the program runs without errors the instruction "global = 1;" is translated in disassembly to:
"mov dword ptr [Secound_NULL_THUNK_DATA+34Ch (00415668)],1" where 415668 is the address of variable "global" out of the map file of Secound.exe

Does anyone know why I'm having this problem and how could I fix it ?

Thanks