Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2005-07

C++ > C wrapper callback > Pascal Continues

2 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Urbansound
Show quoted text 14 lines
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

Peter Vreman
to Urbansound
Show quoted text 67 lines
> 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??

A bug report is only in order if there are complete sources otherwise it can't be reproduced.

Thanks to all, whoever may have additional ideas. Mike

Are the pascal units are initialized? A call to FPC_INITIALIZEUNITS is required otherwise the memorymanager etc. will not work.