Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Using Delphi with C/C++. char *data problem

I am trying to use delphi to read from a function that returns data with a char *data type in C/C++.

What's the corresponding data type going to be in Delphi? I'm getting nowhere with it.

The function definition in the C header is

int32 __CFUNC DAQmxGetSysDevNames(char *data, uInt32 bufferSize);

In delphi it will be something like this.

function DAQmxGetSysDevNames(var data : pchar;
buffersize : integer): integer;
stdcall; external 'NICAIU.DLL';

and in use it is

procedure TNIcard.initcard(var devices : string);
var
istatus : integer;
pname : pchar;
namesbuffersize : integer;
begin
namesbuffersize := 1024;
istatus := DAQmxGetSysDevNames(pname,namesbuffersize);

end;

However when the program runs it hangs at this function.

Any ideas anyone?

MTIA

Andy



Comments

  • zibadianzibadian Member Posts: 6,349
    : I am trying to use delphi to read from a function that returns data with a char *data type in C/C++.
    :
    : What's the corresponding data type going to be in Delphi? I'm getting nowhere with it.
    :
    : The function definition in the C header is
    :
    : int32 __CFUNC DAQmxGetSysDevNames(char *data, uInt32 bufferSize);
    :
    : In delphi it will be something like this.
    :
    : function DAQmxGetSysDevNames(var data : pchar;
    : buffersize : integer): integer;
    : stdcall; external 'NICAIU.DLL';
    :
    : and in use it is
    :
    : procedure TNIcard.initcard(var devices : string);
    : var
    : istatus : integer;
    : pname : pchar;
    : namesbuffersize : integer;
    : begin
    : namesbuffersize := 1024;
    : istatus := DAQmxGetSysDevNames(pname,namesbuffersize);
    :
    : end;
    :
    : However when the program runs it hangs at this function.
    :
    : Any ideas anyone?
    :
    : MTIA
    :
    : Andy
    :
    PChar parameters are almost never var, since they aren't created within the function. Also the uInt32 is unsigned, while integer is. You should change that to cardinal. The correct (untested) function should look like this:
    [code]
    function DAQmxGetSysDevNames(data: PChar;
    buffersize: Cardinal): integer; stdcall; external 'NICAIU.DLL';
    [/code]
  • libratigger62libratigger62 Member Posts: 2
    : PChar parameters are almost never var, since they aren't created within the function. Also the uInt32 is unsigned, while integer is. You should change that to cardinal. The correct (untested) function should look like this:
    : [code]
    : function DAQmxGetSysDevNames(data: PChar;
    : buffersize: Cardinal): integer; stdcall; external 'NICAIU.DLL';
    : [/code]
    :

    Genius! Thanks very much. Got it working now.


    function DAQmxGetSysDevNames(data: PChar;
    buffersize: Cardinal): integer; stdcall; external 'NICAIU.DLL';

    var
    name : array[0..1023] of char;
    //
    istatus := DAQmxGetSysDevNames(@name,namesbuffersize);



    Andy
Sign In or Register to comment.