?
Solved

Calling DLL function in release mode from exe in debug mode

Posted on 2010-01-10
5
Medium Priority
?
695 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 44

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

Percona Live Europe 2017 | Sep 25 - 27, 2017

The Percona Live Open Source Database Conference Europe 2017 is the premier event for the diverse and active European open source database community, as well as businesses that develop and use open source database software.

Question has a verified solution.

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

After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
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…

765 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