I try to create a dll and load it dynamically,but an error message displaied when I call the function
below red font is the code:
library mydll;
{$mode objfpc}{$H+}
uses
Classes, Windows,WinSock,
SysUtils,Dialogs
{ you can add units after this };
Function WinUserName(): string; stdcall;
var
FStr: PChar;
FSize: Cardinal;
begin
FSize := 255;
GetMem(FStr, FSize);
GetUserName(FStr, FSize);
Result := FStr;
FreeMem(FStr);
end;
function myMessage(): string; stdcall;
begin
MessageBox(0,PChar('Hello world'),PChar(''),MB_OK);
end;
exports WinUserName index 1,myMessage index 2;
begin
end.
the funny thing is, the same code can work properly as a function in my main program