?
Solved

Calling DLL function in release mode from exe in debug mode

Posted on 2010-01-10
5
Medium Priority
?
701 Views
Last Modified: 2013-11-25
My main application is compiled in debug mode, and make several call to a DLL.

Everything works fine until the DLL is compiled in Release mode, then the stack on some of the functions i nthat DLL become corrupt.

I have eleminated all std string from those argument to the DL function and replaced them with basic type such as char, double and integer. But I still run into the same problem.
0
Comment
Question by:leogi
5 Comments
 
LVL 33

Expert Comment

by:pgnatyuk
ID: 26278825
Check that both debug and release configuration have the same parameters in the project settings. Pay attention on Run-time libraries in the Code Generation section - it should be the same for the executable and the DLL. For example Multi-Threaded DLL for the main application and for the DLL.

It makes sense to show the error message - it can be an assert, it may contain an error code that we can explain and you will find the mistake.
0
 

Author Comment

by:leogi
ID: 26280163
Well the function stack is corrupted, so the function breaks with invalid data. The data it actually breaks on is actually its own defined data structure only available inside the function body.
I'm not sure why both the exe and the DLL have to be compiled against thesame Runtime Library, indeed the main exe is compiled with the debug Multithreaded, when the DLL is compiled using the Regular Multithreaded.
I know indeed that when both are compiled using the Multithreaded Debug, everythings works fine, however, I will double check again, but I believe that when both again are compiled using the same regular Release Runtime, the same problem occurs, which tends to indicate the problem is not about runtime libraries compatibilities.
0
 
LVL 45

Accepted Solution

by:
AndyAinscow earned 500 total points
ID: 26281245
I don't really see why havinfg the dll as 'release' and the app as 'debug' should cause this problem. After all the windows api dll's your app uses would be the release versions even for a debug app.

There is a major (and not always realised) difference between release and debug builds.  A debug build has variables set to an initial value and check bytes around variables.  A release build just uses whatever value was in that memory block (not necessarily zero) and doesn't have the safety bytes - so a buffer overrun can result in corruption of other variables that isn't seen in a debug build.

eg.
int i;
if(i != 0)
  CrashTheApp();    <<--  this shouldn't be called in debug but can occasionally be called in release.

So:  
Is the release build always failing in the same function ?
In a debug build do you see reported problems in the output window of visual studio when your app exits ?
0
 
LVL 33

Expert Comment

by:pgnatyuk
ID: 26281293
Be sure that if you set Multi-Threaded for the Run-Time libraries in the DLL project settings, you have to set the same for the executable.
It is about C++ run-time libraries - will it be statically linked or not. So if you use different models your executable will use one C++ run-time library and the DLL another one.

http://msdn.microsoft.com/en-us/library/abx4dbyh(VS.80).aspx
0
 
LVL 49

Assisted Solution

by:DanRollins
DanRollins earned 500 total points
ID: 26282129
>> The data it actually breaks on is actually its own defined data structure only available inside the function body.

If it's an auto varible, the problem is almost almost certainly related to the padding bytes that AndyAinscow mentioned. The Debug Build hides some errors that only show up in Release. One that recently nailed me:
   memset( rMyAbcdStruct, 0, sizeof( rMyEfghStruct ) );
Using the wrong size (luckily?) worked fine in Debug, but failed massively in Release.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

621 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question