#1 2014-09-30 08:39:45

VladimirPromAuto
Member
From: Belarus
Registered: 2014-09-30
Posts: 2

Implementing client functionality in dll

Hi
I need to implement client as dll. I use sample 14 - Interface based services.
I export procedure "connect":

var
  I: IConnection;
  Model: TSQLModel;
  Client: TSQLRestClientURI;
procedure connect;
begin
  I:= nil;
  Model := TSQLModel.Create([],ROOT_NAME);
  Client := TSQLHttpClient.Create('127.0.0.1','888',Model);
  if not Client.ServerTimeStampSynchronize then begin
    Client.Free;
    Model.Free;
  end
  else  begin
    Client.SetUser('User','synopse');
    Client.ServiceRegister([TypeInfo(IConnection)],sicPerSession);
    Client.Services['Connection'].Get(I);
    if (I <> nil) then   I.wm2_connect_start;
  end;
end;

Everything compiled without mistakes. But when this procedure called, I get exception "Access violation" on TWinHTTP.InternalSendRequest(const aData: RawByteString);
If I put this code in place of the reference to the exported dll function, everything works well.
What am I doing wrong?
Thanks.

Offline

#2 2014-09-30 10:03:50

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,206
Website

Re: Implementing client functionality in dll

I suppose it is due to the fact that your I variable is local, and Client is freed before it.
Try to set

if (I <> nil) then 
try
   I.wm2_connect_start;
finally
   I := nil; force release now
end;

What is the stack trace when you got the AV?

Offline

#3 2014-09-30 10:41:44

VladimirPromAuto
Member
From: Belarus
Registered: 2014-09-30
Posts: 2

Re: Implementing client functionality in dll

"I" is global variable. I got AV in ServerTimeStampSynchronize. Stack trace just before AV is:

SynCrtSock.TWinHTTP.InternalSendRequest('')
SynCrtSock.TWinHttpAPI.Request(???,???,20000,'','',???,'','')
mORMotHttpClient.TSQLHttpClientWinGeneric.InternalRequest('root/TimeStamp','GET','','','application/json; charset=UTF-8')
mORMotHttpClient.TSQLHttpClientGeneric.InternalURI($12FDA0)
mORMot.TSQLRestClientURI.URI('root/TimeStamp','GET',$12FE74 {''},$12FE34 {''},nil {''})
mORMot.TSQLRestClientURI.CallBackGet(???,???,'',nil,0,nil {''})
mORMot.TSQLRestClientURI.ServerTimeStampSynchronize
wm2_connect.connect

Last edited by VladimirPromAuto (2014-09-30 11:26:30)

Offline

Board footer

Powered by FluxBB