Solved

Problem with release build accessing a dll

Posted on 2003-11-18
4
301 Views
Last Modified: 2010-04-02
I have added a public-domain fast numerical solver to my computational fluid dynamics code.  The solver is written in C and seems to me (as someone who went straight to C++ and therefore doesn't know much about these things) as a bit strange in places.  I thought the best approach for me would be to compile the code as a dll, with a single function declared as __declspec( dllexport) to provide the input/output to the solver.

I compiled a release version of the dll and added appropriate code to my C++ project (using LoadLibrary & GetProcAddress) to access the function.  It all works fine for a debug build of my project, but when I compile a release version of my project, the dll is called correctly but seems to corrupt the array that contains the solution.  It is mysteriously shifted to the next array in the argument list.

I'm assuming that there is some memory corruption problem, but does anyone have any ideas what it could be?

The function declaration is:

__declspec( dllexport ) int fastlap(int *plhsSize,int *prhsSize,int *pnumSing,double *px,int *pshape,int *pdtype,int *plhsType,int *prhsType,int *plhsIndex,int *prhsIndex,double *plhsVect,double *prhsVect,double *pxf,double *pxnrm,int *pnumLev,int *pnumMom,int *pmaxItr,double *ptol,int *pjob);

The solution should be returned in the plhsVect array, but for a release version it is returned in the prhsVect array.

Just to stress again – in each instance I am using the release build of the dll.

I am using Visual C++ 6.0 on Windows 2000.

Thanks for your help.

NeilCFD
0
Comment
Question by:NeilCfd
[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
  • 2
  • 2
4 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 250 total points
ID: 9772642
Have you tried to turn off the optimizations?
0
 

Author Comment

by:NeilCfd
ID: 9772712
Thanks jkr - that must be the easiest 250 points you've ever earned!

Do you know why the optimisation (optimised for speed in my case) makes this happen?  I thought speed optimisation would be appropriate for my code as the runtime is pretty serious (>24 hours in a lot of cases) but I must admit I haven't done any testing to see what difference it was making.

Thanks again,

NeilCFD
0
 
LVL 86

Expert Comment

by:jkr
ID: 9772776
>>Do you know why the optimisation (optimised for speed in my case) makes this happen?

Actually, to see what is going wrong, you'd have to disassemble and compare both the optimized and the non-optimized version. Optimizers are known for being less-than-perfect, and when I saw the lengthy parameter list, I was afraid that the compiler would try to optimize that one in the 1st place, especially after your remark that said "It is mysteriously shifted to the next array in the argument list"
0
 

Author Comment

by:NeilCfd
ID: 9772828
Yes - that makes sense.  Thanks!

NeilCFD
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
C Language combined operators 28 137
Move constructor only called if marked noexcept? 6 121
Autosar OS Multicore Share Resources confusion ? 2 195
Need some help with mailto 16 41
Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

739 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