[fpc-pascal] C++ > C wrapper callback > Pascal

Urbansound urbansound at sbcglobal.net
Tue Jul 26 06:57:07 CEST 2005

Hi List,

    I'm probably over my head on this one and some of the FPC forum entries 
talk about limited functionality toward C++, but here goes.

    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

    The application crashes on the callback shown below.  The odd thing is 
that it crashes, simply using a string allocation in pascal.  Tried 
ansistring and others.  Assumption, is that the callback is possibly not 
configuring memory or address pointer correctly and then the String 
allocation is landing off location by register and stomping on a relative 
memory location.

    Is this a valid implementaiton or outside the scope of FPC?

    Thanks in advance for any suggestions.

THE PASCAL is called back to, in the following:

function L1_Callback(quote : pointer) : integer; stdcall; export;
    bid_price : double;
    s : string;
    SendMessage(listbox, LB_ADDSTRING, 0, longint('L1 Callback'));
    SendMessage(listbox, LB_ADDSTRING, 0, longint(Get_secsym(quote)));
    bid_price := Get_l1_BidPrice(quote);
    //s := 'test message';                             // This will crash!
    //s := FloatToStr(bid_price);                 // Intended call crashes!
    //SendMessage(listbox, LB_ADDSTRING, 0, longint(s));

THE C WRAPPER has the following:

int CDasApiEx::OnQuote(st_L1Quotes *pQuote)
 if(m_pL1Callback) (*m_pL1Callback)(reinterpret_cast<void*>(pQuote));
 return 0;


More information about the fpc-pascal mailing list