Page 1 of 1

TUniConnection in DLL when called from web service

Posted: Thu 07 Feb 2013 06:37
by arusoft
I wanted to create a DLL in delphi that will be called by a C# web service.

This DLL has some database routines like getting info, saving info etc.

I know that DLL has problems if we use global variables. So my plan is to create uniConnection component within a procedure in DLL and then pass along to other procedures as required or is there better way to handle uniConnection in this scenario.

Thank You.

Re: TUniConnection in DLL when called from web service

Posted: Thu 07 Feb 2013 07:45
by CristianP
Hi,

It is clear you will need a login() and logout() functions.
The login() can create the uniConnection and return a pointer that you can use in all functions including logout() for freeing.

But a better way is login() to return a handle. This handle will be into a list of sessions with thread-safe accesses.

Best Regards,
Cristian Peţa

Re: TUniConnection in DLL when called from web service

Posted: Fri 08 Feb 2013 05:47
by arusoft
Thanks for reply. Can you show an example please?

Thanks.

Re: TUniConnection in DLL when called from web service

Posted: Fri 08 Feb 2013 11:58
by CristianP
Hi,

You can just use the simple way

Code: Select all

interface
function Connect(out DataModule: Pointer): Boolean; stdcall;
procedure DoSomething(DataModule: Pointer); stdcall;
procedure Disconnect(DataModule: Pointer); stdcall;

implementation

function Connect(out DataModule: Pointer): Boolean; stdcall;
begin
  DataModule := TDataModule1.Create(nil);
  Result := TDataModule1(DataModule).MyConnect;
end;

procedure DoSomething(DataModule: Pointer); stdcall;
begin
  TDataModule1(DataModule).UniQuery1.Open;
end;

procedure Disconnect(DataModule: Pointer); stdcall;
begin
  TDataModule1(DataModule).Free;
end;
Best Regards,
Cristian Peţa

Re: TUniConnection in DLL when called from web service

Posted: Mon 18 Feb 2013 11:08
by DemetrionQ
Hello.

Please specify whether you have already got a C# library with web service and you want to use DLL from it for work with UniDAC, or you want to create a new DLL web service.
Also note that there is a product for C# similar to UniDAC. You can find more information at http://www.devart.com/dotconnect/universal .