Function CheckSnExist(pSn: String): Integer; StdCall; export;
Implementation
Function CheckSnExist(pSn: String): Integer;
Var
ChkQry : TOraQuery;
Begin
ChkQry := TOraQuery.Create(Nil);
ChkQry.Session := Data.Orsn;
With ChkQry Do
Begin
Close;
SQL.Clear;
SQL.Add('select count(*) from sfism4.r_wip_tracking_t');
SQL.Add(' where serial_number = :sn');
ParamByName('sn').AsString := pSn;
Open;
Result := Fields[0].AsInteger;
Close;
End;
ChkQry.Free;
End;
Exports
CheckSnExist,
End.
VC中的代码:
typedef int (* pGetData)( char* P1) ;
pGetData GetData;
HINSTANCE hinst;
hinst=LoadLibrary(TEXT("TEST.dll")); //Load dll LPCTSTR strContent);
if(hinst==NULL)
{
AfxMessageBox("load dll Fail");
}
GetData=(pGetData)GetProcAddress(hinst,"CheckSnExist"); //get address of the function
if(GetData==NULL)
{
AfxMessageBox("get the address of the function Fail");
}
else
{
if(GetData("2GE02001")==0) //run the function in the delphi dll
{
AfxMessageBox("the number is not exist");
}
else
{
AfxMessageBox("the number is exist");
}
}
if(hinst!=NULL)
{
FreeLibrary(hinst); // unload hinst
hinst=NULL;
free(GetData);
}