I have been trying to reuse a C dll file in delphi based on this documentation.
Server was running well, i could access and used the database on local server with java and php.
On delphi i used dynamic load and worked well on all functions that return variables but failed on those that return interface.
unit for library :
unit SQLDBC_C;
interface
uses windows, classes, sysutils;
type
SQLDBC_IRuntime = interface
end;
var
getSDKVersion : function :Pchar; stdcall;
ClientRuntime_GetClientRuntime: function (errorText:Pchar; errorTextSize:Integer) : SQLDBC_IRuntime; stdcall;
implementation
var
libhandle : THandle;
procedure initLibrary;
begin
libhandle := LoadLibrary('libSQLDBC_C.dll');
if libhandle>=23 then begin
@getSDKVersion:=GetProcAddress(libhandle,'getSDKVersion');
@ClientRuntime_GetClientRuntime:=
GetProcAddress(libhandle,'ClientRuntime_GetClientRuntime');
end;
end;
initialization
begin
initLibrary;
end;
finalization
begin
if libhandle>=32 then
FreeLibrary(libhandle);
end;
end.
here is the test procedure :
procedure TForm1.Button1Click(Sender: TObject);
var
err : array [0..200] of char;
rt : SQLDBC_IRuntime;
begin
Memo1.Clear;
FillChar(err, sizeof(err), 0);
Memo1.Lines.Add(getSDKVersion); //this function successed
rt := ClientRuntime_GetClientRuntime(@err,200);
//this function had no return value, (rt always nil) but no error return at err variable
if assigned(rt) then begin
......
end;
end;
I've read the similar problems asked by geskill, Dan Hacker, max and Ron but it could not solve my problem.
Could anyone told me what's wrong here?