From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with Delphi created DLL taking string parameter

Hello everybody,
 
I am trying to call a DLL created with Delphi 7. It takes one parameter of type String writes it in a textfile and returns nothing. I have designed a very simple VI consisting of a String constant linked to a Call Library Function Node. In the Call Library Function Node I use stdcall Calling Convention and String - Pascal String Pointer as arg1. LabView crashes after the execution, the DLL creates the output file but writes nothing in it.
 
I have tried about any combination of Calling Convention and argument type in the Call Library Function Node but not one seemed to work. If I pass a double value to the DLL (changing the DLL accordingly...) I have no problems.
 
This seems to me to be the most basic example of a DLL-call, can any body tell me what I am missing? Thank you very much!
 
Stefan
 
The DLL Delphi code:
 
library UMP_DLL;
uses
  SysUtils,
  Classes;
procedure UMP_calc(output: String);
var
  myFile  : TextFile;
begin
  AssignFile(myFile,'output.txt');
  ReWrite(myFile);
  Write(myFile,output);
  CloseFile(myFile);
end;
exports
  UMP_calc;
 
begin
end.
0 Kudos
Message 1 of 3
(4,071 Views)

OkOk, I just found the problem...

I did not specify the Calling Convention in my Delphi file. Adding "cdecl;" at the end of the procedure declaration (and changing Calling Convention and arg1 to "C" and "String - C String" respectively) solved the problem.

0 Kudos
Message 2 of 3
(4,068 Views)

Hi stiif,

 

I'm a bit late but whatever, problems don't seem to change...

What version of LV and Delphi did you used ? I try to do exactly the same without result...

 

Fabrice

0 Kudos
Message 3 of 3
(3,606 Views)