ImageEn for Delphi and C++ Builder ImageEn for Delphi and C++ Builder

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
Forum membership is Free!  Click Join to sign-up
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 Passing record of records to DLL
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

spetric

Croatia
308 Posts

Posted - Dec 16 2016 :  18:49:41  Show Profile  Reply
Hi,

I'm trying to set my DLL to work from Delphi and I've encountered a problem.
I have a record which contain 4 other records:

type
  Tpx_RenderData = record
    RenderParams: Tpx_RenderParams;
    SelectionParams: Tpx_SelectionParams;
    DrawParams: Tpx_DrawParams;
    ShadowParams: Tpx_ShadowParams;
  end {Tpx_RenderData};


Now, initializing function should fill this record with initial data.
Here is a function definition:

function speInit(var renderData: Tpx_RenderData): Bool cdecl  {$IFDEF WIN32} stdcall {$ENDIF};
function speInit; external 'libSpEngine.dll';


In main form function is called:

var
  frmMain: TfrmMain;
  renderData: Tpx_RenderData; //(record)
.....
begin
  IEGlobalSettings().AutoFragmentBitmap := False;
  speInit(renderData);
  ....


I've traced DLL and it fills renderData.ShadowParams record with some data,
but after DLL function exits, everything inside renderData.ShadowParams is as before. In C++ everything works ok. In Delphi I'm passing renderData record by reference (var) but nothing happens.

When simple record from Delphi is passed to some DLL, everything is Ok.
I'm obviously missing something when nested records are in the game!?

TIA,
Siniša






spetric

Croatia
308 Posts

Posted - Dec 17 2016 :  15:02:55  Show Profile  Reply
Got it!

The problem was in bool (c++, 1 byte) converted to Bool (Delphi, 4 bytes).
The Delphi documentation states that there are 4 boolean types:
Boolean, ByteBool, WordBool, and LongBool. Where the hack that Bool came from?

As Bolean is 1 byte (the same as ByteBool), renaming Bool to Boolean solved the problem, as C++ structure and Delphi record are now of the same size and record/structure fields are filled correctly.



Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: