: Yang Maofeng
Email: Dinkysoft@163.com
A few friends often share a global variable in the DLL. For example, the username (username) after login ...
In fact, this problem is very simple. Below I wrote my practice out to share with everyone.
Place the shared variable in the main program: Username, ...., etc.
Write two functions in the main program
Function curusername (): pchar;
Begin
Result: = PCHAR (Username);
END;
Procedure setcurusername (loginusername: pchar)
Begin
Username: = Loginusername;
END;
Then output these two functions in the project file (* .dpr) of the main program.
.....
{$ R * .res}
Exports
Curusername, setcurusername;
....
This can use these two functions in each DLL.
Function curusername: pchar; // Get the current login account from the main program
VAR
GetCurusername: Function: PCHAR;
Begin
@Getcurusername: = getProcadDress (Pchar (Application.exename), 'curusername');
IF assigned (getcurusername) Then // found
Result: = GetCurusername
Else
Result: = 'admin';
END;