I'm compiling a C++ DLL from a reasonably well-vetted library (zeromq), and consuming it in my own Delphi bindings. I'm currently hitting an unexpected behavior in the C++ code, and don't have the background to debug it well. The ultimate responsibility for the bug is probably in my Delphi code, but I need to understand the C++ better to know what I did wrong.
The problem code looks like this (simplified)
if (*mySize_tObject == sizeof (uint64_t)) { return 0;//We never reach this code. }
*mySize_tObject
is passed in as a size_t
. In my Delphi bindings, it is a Cardinal
with a value of 8.
I've tried playing around with the C++ outputs to narrow down what might be happening, and gotten these results:
return *mySize_tObject;//8return sizeof (uint64_t);//8return *mySize_tObject + sizeof (uint64_t);//16
if (*mySize_tObject == sizeof(uint64_t)) { return 1;}else if (*mySize_tObject < sizeof(uint64_t)) { return 2; }else if (*mySize_tObject > sizeof(uint64_t)) { return 3;//This is the value that returns}else { return 0;}
So I'm getting back, essentially, 8>8. Since I know that isn't true (citation needed), I'm left thinking that one of these values is secretly a float like 8.000001 and I'm only seeing truncated results.
I would also consider tips for live debugging a .dll
if this doesn't make any sense to people that know C++.
I guess it's also worth noting that I previously had my Delphi bindings working in 32bit, and started running into these difficulties while converting to 64bit (I also changed the DLL compiling settings to match).
I apologize for not being able to produce a minimal reproducible example, but I'll try to give as much detail about my calls as I can here:
The Delphi binding:
TMyBinding = function(var mySize_tObject : size_t): Integer; cdecl;
The value being passed is instantiated as SizeOf( result )
, with result
being an Int64
.
*Note: size_t
is defined elsewhere as a Cardinal
in the Delphi code.
The header for this function in C++:
int myFunct(size_t *mySize_tObject ) const;