Home > Back-end >  Delphi create DLL to the c calls, to join in the DLL ADO control to query the database, an error
Delphi create DLL to the c calls, to join in the DLL ADO control to query the database, an error

Time:09-25

If inscribe
Delphi shielding ADO piece of code there is no problem, but with couldn't call
In the Delphi code:
 library ADSB; 

USES the
ShareMem, SysUtils ADODB, DB, ActiveX, Windows, StrUtils,
Classes;
{$R *. Res}
Const
Connectionstr='Provider=SQLOLEDB. 1; Persist Security Info=False; User ID=sa; Initial Catalog=airline2; The Data Source=. ';

The function aircraft (var FlightID: PChar) : PChar; Cdecl; Export;
Var
PType: string;
Con1: TADOConnection;
Qry1: TADOQuery;
The begin
CoInitialize (nil);
Qry1:=TADOQuery. Create (nil);
Con1:=TADOConnection. Create (nil);
Qry1. Connection:=con1;
Qry1. The ConnectionString:=connectionstr;
Qry1. Close;
Qry1. SQL. The Clear;
Qry1. SQL. The Add (' select NO from routes where FN collate Chinese_PRC_CS_AS=: a ');
Qry1. The Parameters. ParamByName (' a '). The Value:=StrPas (FlightID);
Qry1. Open;
If qry1. RecordCount> 0 then
The begin
PType:=qry1 Fields. [0] Value;
end;
Result:=PChar (PType);
Qry1. Close;
CoUninitialize;
end;

Exports
Aircraft;

The begin

End.

Vs the code is as follows:
 # include & lt; Windows. H> 
#include
#include
#include
using namespace std;
Typedef char * (* myFun) (char * arg1);
Int main (int argi, char * argv [])
{
HINSTANCE hDll;
HDll=LoadLibrary (" ADSB. DLL ");
If (hDll!=NULL)
{
MyFun fun;
Fun=(myFun) GetProcAddress call (hDll, "aircraft");
If (fun!=NULL)
{
Char * p="AAF103";
Char * pl=fun (p);
Cout}
FreeLibrary (hDll);
}
system("pause");
return 0;
}

Beg you to see what a great god can help have a problem? Thank you very much!

CodePudding user response:


Prompt error as shown

CodePudding user response:

Some advice: don't use pchar as a function return value, and take them to the function of input parameters qry use don't use con the socket, a choice, use pchar want to apply for memory, can step through dynamic database, this is the basic skill,

CodePudding user response:

Can step through dynamic database, this is the basic skill,

CodePudding user response:

Con1 don't have to set the ConnectionString?
Qry1 need to set up the ConnectionString?


Qry1. The ConnectionString:=connectionstr;

The dynamic repository to step through the look on both sides of the position
  • Related