Home > Back-end >  Ask a question of C calling DLL written in Delphi. Look at the trouble free.
Ask a question of C calling DLL written in Delphi. Look at the trouble free.

Time:09-18

Delphi wrote a DLL one way:

The function CAM_GrabImage (var devId: WideString; The out imageData: Pointer; The out imageSize: Int64; The out imageWidth: Integer; The out imageHeight: Integer) : Integer; Cdecl;

Written in Delphi program calls the imageData returns the normal pointer,


In c + + call imageData address turned out to be null, when the other parameters all return,


Somebody in and solve a similar situation?


Here is called C code, without exception, is imageData in the debug time is null, and when the entered the initial address, after the run becomes null,
Dllfun typedef __cdecl int (*) (char * devId, char * imageData, long * imageSize, imageWidth int * and an int * imageHeight);
Result=CAM_GrabImage (devId, imageData, imageSize, imageWidth, imageHeight);

Delphi
ImageData: Pointer I tried PChar
C
Char * void * are tried,
Results, are written in Delphi code calls the DLL returned to normal, C calls the same DLL, abnormal,


Please feel free to comment, thank you,

CodePudding user response:

ImageData: the inside of the Pointer to the data is X, Y
But not a variable,

CodePudding user response:

Pointer is a Pointer type, coordinate is a TPoint structure, the out keyword modified parameters can only accept the output value, can't input, the corresponding Char *, PChar Pointer corresponding void * no problem, but the imageData may be Delphi is special type of object, if it is, usually cannot be used to the C/C + + DLL pass parameters should use basic types or structure of general type,

CodePudding user response:

The function CAM_GrabImage (var devId: WideString; The out imageData: Pointer; The out imageSize: Int64; The out imageWidth: Integer; The out imageHeight: Integer) : Integer; Cdecl;
And
Dllfun typedef __cdecl int (*) (char * devId, char * imageData, long * imageSize, imageWidth int * and an int * imageHeight);
In ah,
Should be first WideString would *, var devId: WideString should be would be * *, secondly should use long long or __int64 Int64, in addition all out parameters are changed, to preach references,
Dllfun typedef __cdecl int (*) (would be * * devId, char * * imageData, long long * imageSize, imageWidth int * and an int * imageHeight);

CodePudding user response:

Parameters you have any question, directly using the pointer no
If not you try changing a way of parameter passing

CodePudding user response:

I has always been defined as a string or Pchar Pwidechar, haven't tried with string, directly widestring

CodePudding user response:

The
reference 3 floor DelphiGuy response:
function CAM_GrabImage (var devId: WideString; The out imageData: Pointer; The out imageSize: Int64; The out imageWidth: Integer; The out imageHeight: Integer) : Integer; Cdecl;
And
Dllfun typedef __cdecl int (*) (char * devId, char * imageData, long * imageSize, imageWidth int * and an int * imageHeight);
In ah,
Should be first WideString would *, var devId: WideString should be would be * *, secondly should use long long or __int64 Int64, in addition all out parameters are changed, to preach references,
Dllfun typedef __cdecl int (*) (would be * * devId, char * * imageData, long long * imageSize, imageWidth int * and an int * imageHeight);

CodePudding user response:

About DLL call,,, especially the pointer to the data, the main problem is the space allocation problem, you imagedata data space, is in Delphi getmem distribution? This method is called, you additionally, allocation of imagedata data area, to ensure the is long-standing, cannot be deleted,

CodePudding user response:

Write this DLL technology does not pass, to Delphi, CBC calls, string, widestring can also use, to general, pchar, best pwidechar, rather than in the DLL, you is hard to use good
  • Related