views:

43

answers:

2

I was interested in learning more about mixing runtimes between exes and dlls. On a WinXP machine, I created a dll build against the release runtime (/MD) and an exe that calls a function in the dll that is built debug (/MDd). The function in the dll allocates memory to the heap and the exe deletes it. I expected this to crash, however, it hangs instead. Using ProcessExplorer I see that the state of the executable is "wait:userrequest". The same exercise on a Vista machine does show the dialog. I want to see the dialog on my XP machine too!

I've tried the opposite of all the suggestions here. I've googled around for quite some time now. I've played around with enabling all Error Reporting services I could find in the gpedit.msc as well as verified that the Error Reporting Service is running in the AdministrativeTools->Services dialog.

To be explicit, here is my dll:

int* getDllMem(){
     printf("dll alloc mem");
     int *ptr = new int;
     return ptr;
}

Here is my exe:

int main()
{
     printf("main\n");
     int *ptr = getDllMem();
     printf("main delete\n");
     delete ptr;
     printf("main exit\n");
     return 0;
}
A: 

XP and Vista have a different system architecture, and possibly different assembly code. What machine did you compile the program on? XP or vista?

alexy13
The program is compiled on XP only. When copied to Vista, I see a dialog with error.
JamesG
Maybe a quick solution could be to use try/catch statements, and handle the errors gracefully.
alexy13
+2  A: 

Your program has gone off into undefined and erroneous behavior. Why expect exactly the same result on different operating systems?

If something even slightly different happens during the execution on each of those machines, it could plausibly have the result that one hangs while the other immediately crashes.

Perhaps the runtimes that the program is using are slightly different between those machines/operating systems. Perhaps other aspects of the operating system are having an effect (for instance, address space layout randomization).

I suspect only someone with a very intimate knowledge of the runtime and heap manager could answer exactly why there's a difference.

Honestly, my gut reaction to the question is: You shouldn't spend too much time worrying about why the program's failure is different between these two operating systems because you should never write a program like this in the first place.

TheUndeadFish