• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1694
  • Last Modified:

ShareMem and Strings on Delphi DLL

Hello, I have problem with ShareMem and Strings on Delphi. It doesnt work :(
I have added ShareMem in both application and dll in first unit of project.

I call function LoginUser("A1", "A2", "A3");

and DLL receives empty string instead :(

Please see my code and help me to fix problem.
type
  TLoginUser = function(Username, Password, IP: String): Integer; stdcall;
 
...
private
    LoginUser: TLoginUser;
 
...
 
FormCreate:
 
  DLLModule := LoadLibrary('mydll.dll');
 
  @LoginUser := nil;
  @LoginUser := GetProcAddress(DLLModule, 'LoginUser');
 
 
  s := 'Test'; // string
  LoginUser(s, s, s);
 
==============
 
DLL :
 
function LoginUser(Username, Password, IP: String): Integer;
begin
  writeln('user1 = "' + Username + '"');
  writeln('pass1 = "' + Password + '"');
  writeln('ip = "' + IP + '"');
end;
 
...
 
exports LoginUser;

Open in new window

0
WebWolf1
Asked:
WebWolf1
1 Solution
 
HypoCommented:
Hi,
Your problem is that you have declared your function with the STDCALL calling convention in the application, but not in the library.

Type
TLoginUser = function(Username, Password, IP: String): Integer; stdcall;

If you have STDCALL on your function in the application, then you also need to add it to the library as in the example below. Try change this, and it will probably work.
regards
Hypo

DLL :
 
function LoginUser(Username, Password, IP: String): Integer; STDCALL;
begin
  writeln('user1 = "' + Username + '"');
  writeln('pass1 = "' + Password + '"');
  writeln('ip = "' + IP + '"');
end;

Open in new window

0
 
WebWolf1Author Commented:
yes that was it. its very weird. i have 22 functions all declared with stdcall but not this one :(
anyway thanks
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now