[fpc-pascal] C++ > C wrapper callback > Pascal Continues
Urbansound
urbansound at sbcglobal.net
Wed Jul 27 03:26:07 CEST 2005
> Urbansound wrote:
>> Hi List,
>> A Windows pascal application is recieving data from a C++, VisC API,
>> which is set up as a class, and a conventional C wrapper, attempting to
>> extend functionality into Pascal. C++ and C are vis 4.2 MFC
>>
>> function L1_Callback(quote : pointer) : integer; stdcall; export;
>
> One thing that comes into my mind is that you should make sure that
> "integer" above really means what you want. "integer" is either 16-bit
> or 32-bit,
> Also, do you really want to put "export" here ? It's harmless, but
> unnecessary, if you're only passing a pointer to L1_Callback to some
> other C routine.
Thank you to Michalis Kamburelis...
clipped this down (and still too long)...
Yes the integer sizes were confirmed = 32 (win32 gui) and the export was
added simply attempting to force a change in memory allocation, along with
pre-initializing variables. Among other things, Delphi mode was tried and
we boiled the problem down to two lines of code in particular, commented
below. As well, we hand converted the Pascal app to C, in order to test the
C_wrapper, compiled on GCC and the same calling conventions and methods work
fine in C-GCC, but fail in Pascal. VERY ODD. Wrapper works fine.
Review:
//------------------------------
PROBLEM IS BELOW and either comment line removed, will crash = RT217...
I suspect the problem is pointer "quote", somehow is crashing registers.
FUNCITON HEADER:
function SetL1Callback(func_addr : pointer) : integer; stdcall; external
'DasRapper.dll' name 'SetL1Callback';
>>>>> where SetL1Callback(@L1_Callback); is set in the pascal main
area.<<<<<
FUNCTION CALL TO WRAPPER
function L1_Callback(quote : pointer) : integer; stdcall;
var
bid_price : double = 0.0;
s : ansistring = '';
begin
SendMessage(listbox, LB_ADDSTRING, 0, longint(pchar('L1 Callback')));
SendMessage(listbox, LB_ADDSTRING, 0, longint(Get_secsym(quote)));
bid_price := Get_l1_BidPrice(quote);
//s := FloatToStr(bid_price); // This will crash!
//SendMessage(listbox, LB_ADDSTRING, 0, longint(pchar(@s)));
end;
//------------------------------------
PASCAL WRAPPER function being called is below
DllExport void SetL1Callback(TL1Callback p) { DasApi.m_pL1Callback=p; };
SUMMARY:
There seems to be nothing I can find that would cause a Runtime 217 in the
layout and now finding C conversion of same is working.
Can anyone else please confirm if this should work, or is a bug report be in
order??
Thanks to all, whoever may have additional ideas. Mike
More information about the fpc-pascal
mailing list