Board index » delphi » Error Calling DLL when Optimization is turned on.

Error Calling DLL when Optimization is turned on.

I have a DLL written in Visual C++ that I'm calling from Delphi.  The
function in the DLL is defined as:

****In the DLL****
#define RTLOADER_API __declspec(dllexport)
extern "C" RTLOADER_API LONG LoadDriver(LONG DeviceNumber);
***********

On the Delphi side I load the DLL like this:

*****Load in Delphi, statically*****
function LoadDriver(DeviceNum:LongInt):LongInt; stdcall; external
'RTLOADER.DLL';
*******

And Call it like this:

******Call the routine from Delphi*****
 Error := LoadDriver(DeviceNum);
*****

If I leave off 'stdcall' in the definition of the Function then I get
garbage for the parameter inside the DLL, even without optimization.

It works fine until I turn on Optimization, then it stops working.

Does anyone have any clues?  I think it boils down to my definition,
but I'm not sure how to proceed.  Thanks for your help!

I also have a DLL written in Delphi and called it from C.  I have to
turn off optimizations there as well, in order to call the DLL.  So
whatever I'm doing I'm consistent.

 

Re:Error Calling DLL when Optimization is turned on.


To answer my own question.....

I found this URL, if anyone is interested.

http://www.drbob42.com/delphi/headconv.htm

Quote
On Tue, 27 Apr 1999 16:14:18 GMT, Gi...@sloth.com (Giant Sloth) wrote:
>I have a DLL written in Visual C++ that I'm calling from Delphi.  The
>function in the DLL is defined as:

>****In the DLL****
>#define RTLOADER_API __declspec(dllexport)
>extern "C" RTLOADER_API LONG LoadDriver(LONG DeviceNumber);
>***********

>On the Delphi side I load the DLL like this:

>*****Load in Delphi, statically*****
>function LoadDriver(DeviceNum:LongInt):LongInt; stdcall; external
>'RTLOADER.DLL';
>*******

>And Call it like this:

>******Call the routine from Delphi*****
> Error := LoadDriver(DeviceNum);
>*****

>If I leave off 'stdcall' in the definition of the Function then I get
>garbage for the parameter inside the DLL, even without optimization.

>It works fine until I turn on Optimization, then it stops working.

>Does anyone have any clues?  I think it boils down to my definition,
>but I'm not sure how to proceed.  Thanks for your help!

>I also have a DLL written in Delphi and called it from C.  I have to
>turn off optimizations there as well, in order to call the DLL.  So
>whatever I'm doing I'm consistent.

Re:Error Calling DLL when Optimization is turned on.


This URL didn't help at all.  What a waste.  Oh well, does anyone have
any clues?

Other Threads