In the DLL export process how to use the parameters passed by reference (var), for VC successful call? Or please recommend workaround!

Category: Delphi -> Language/Algorithm/System Design Author: zxb830102 Date: 2008-03-24 11:29:31
 
zxb830102
2008-03-24 11:29:31
Example:

DELPHI
/ / --------------------------------
procedure ExportPro (var test: Integer); export;
begin
test: = 100;
end;
/ / ---- ----------------------------

VC
/ / ------- -------------------------
...
int test = 0;
ExportPro (test) ;
if (test == 100) / / this does not mean that after a call to test 100

...
/ / ------------ --------------------

please experts to help solve or provide workarounds.
kuaige1982
2008-03-24 11:46:06
VC calls you have problems there, it should be:

int test = 0;
ExportPro (& test);
libaobei
2008-03-24 11:54:12
Yes , C function declaration there should be: ExportPro (int & test);
hxy15886
2008-03-24 11:59:02
no one can help you?
arigator
2008-03-24 12:12:48
problem has been solved, VC call no problem, I was in the wrong here, is the calling convention issues, VC default CDECL. But thank you for your participation, although this problem has been for two days before anyone answered.
a3611512
2008-03-24 12:29:56
VC side of the call you have a problem, it should be:

int test = 0;
ExportPro (& test);

---------------------
is wrong to call this method references need to use & only need to take the address pointer. . .

procedure ExportPro (var test: Integer); export; stdcall;

typedef void (__stdcall * PExportPro) (int &);

LoadLibrary
GetProcAddress
FreeLibrary.

OK.
qtelaisite
2008-03-24 12:41:06
just finished the complete post, only to see the big Lucky answer!
Big Lucky's answer should be the most comprehensive up! But I did not specify the VC calling convention, but what is specified in DELPHI CDECL.
Thank Big Lucky enthusiastic. However, amendments to the big Lucky
look, VC call no need to use ExportPro (& test); Or should ExportPro (test); typedef which has been done because the description. If then ampersand, the compiler is not work.
original programforge there are still many enthusiastic people! ^ _ ^