I'm using an NIDAQmx DLL in a Delphi XE4 app. The DLL only has an ANSI C header file.
I'm trying to convert this function:
int32 __CFUNC DAQmxGetPhysicalChanName(TaskHandle taskHandle,
const char channel[], char *data, uInt32 bufferSize);
This is my translation:
function DAQmxGetPhysicalChanName(taskHandle: TTaskHandle;
chanName: PAnsiChar; chanPhysName: PAnsiChar;
bufferSize: DWORD): Integer; stdcall; external NI_DLL_NAME delayed;
When I call it like this:
var
s1,s2: String[200];
sp: PAnsiChar;
begin
// sp:=@s2[1]; When I uncomment this, fucntion works as
// expected, otherwice return string s2 is empty!
res:=DAQmxGetPhysicalChanName(taskHandle,@s1[1],@s2[1],200);
The function works only when I insert sp:=@s2[1]
before the call. I never actually use the sp
pointer, but just the fact that it get assigned helps. Without that, the s2
string is empty. I cant understand why. What am I doing wrong?