Delphi 调用 C++ 回调函数

//输入函数声明
extern "C" __declspec(dllexport) int    SetRecNotifyProc( void  (*TempRecProForPub)(TICanFrame *TempFrame),char *BusName);  

//实现
int   SetRecNotifyProc( void  (*TempRecProForPub)(TICanFrame *TempFrame),char *BusName)
{

         for (int bus=0;busCount;bus++)
         {

                TCANBUS* tempBusint=(TCANBUS*)UseCanBusArrey->Items[bus];

                if (AnsiString(tempBusint->BusName)==AnsiString(BusName))
                {
                    tempBusint->RecProForPub=TempRecProForPub;
                }
         }


}
//回调函数指针声明
     void(*RecProForPub) (TICanFrame *TempFrame);


实现

   if (RecProForPub!=NULL)
   {
         RecProForPub(TempFrame);
   }



Delphi 部分 静态调用
type
     TempRecProForPub=  procedure(var tempframe:TICanFrame); cdecl;

var
  
  function SetRecNotifyProc(RecProForPub :TempRecProForPub;BusName:PChar): Integer; cdecl; external 'SdcsPub.dll'name '_SetRecNotifyProc';

procedure TFormDevInfo.FormCreate(Sender: TObject);
var BDsNameChar:array[0..100] of char;
var BusName:array[0..100] of char;
useip:string ;
useBusName:string ;
i:Integer;
begin
     useip:='192.168.3.233';
     useBusName:='XAYF';
     StrCopy(@(BDsNameChar[0]),PChar(useip));
     StrCopy(@(BusName[0]),PChar(useBusName));
     // InitTest(i);
     InitCanbus(@BDsNameChar[0],9908,9909,@BusName[0]);
     SetRecNotifyProc(UseRecProForPub,BusName);




   //  ListViewDeviceInfo.Items.Clear;
   //  CreateDeiviceInfo();
end;


你可能感兴趣的:(C++,builder)