• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1792
  • 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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

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