A
A
Alexander2014-01-31 14:09:11
Delphi
Alexander, 2014-01-31 14:09:11

Bundle of Delphi 7 and С++(DLL). Change structure by reference

There is a structure in Delphi:

type
RESPONSE =packed Record
    datetime:PChar;
    code:PChar;
    response_string:PChar;
end;

var 
resp:RESPONSE;

and in c++
struct RESPONSE {
    char *datetime;
    char *code;
    char *string;
  };

Function description in Delphi
function getResponse(resp:PRESPONSE):Integer; cdecl ; external 'TestDLL.dll' name 'EF_getResponse';

Description of a function in C++
DLLEXPORT void getResponse(RESPONSE *resp);
I call a function in a DLL from Delphi
getResponse(Addr(resp));
In the DLL, the pointers to strings in the structure must change.
Here is a working code.
resp->datetime="Test datetime";
And with such a code, trouble
resp->datetime=(char*)element->GetText();
Description of the GetText() function
const char * GetText();
How to correctly assign values ​​to the fields of a structure?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
sba, 2014-01-31
@Neuromatik

You can’t just take and cast everything in a row. First you need to at least copy the data pointed to by the result of the GetText() call. And yes, struct RESPONSE is not C++ at all.

A
Andrew, 2014-01-31
@OLS

And the pointer that you are trying to write (return) to the main program does not accidentally point to a variable somewhere in the data segment of the DLL itself?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question