Hello,
I've got a weird problem in that I'm unable to call the
"GetDefaultUserProfileDirectory" API when I dynamically load it however it
works fine if I explicitly reference it. (I've probably got the terminology
wrong but I'm sure you will see what I mean)
If I use the call "_GetDefaultUserProfileDirectory" below I get an Access
Violation error, if I use GetDefaultUserProfileDirectoryA all functions as
expected. I don't understand why one would work while the other doesn't when
they are both the same.
Thanks in advance,
David
function GetDefaultUserProfileDirectoryA (lpProfileDir : PChar; var
lpcchSize : dword) : BOOL;stdcall;far; external 'userenv.dll';
function GetDefaultUserProfileDirectory:string;
type
Type_GetDefaultUserProfileDirectory = function(lpProfileDir:PChar;var
lpcchSize:DWORD):Boolean; StdCall;
var
len : DWORD;
iResultCode : integer;
_GetDefaultUserProfileDirectory : Type_GetDefaultUserProfileDirectory;
sProfilePath: string;
bResult: boolean;
begin
len:=65536;
SetLength(sProfilePath, len);
iResultCode:=LoadLibrary('userenv.dll');
@_GetDefaultUserProfileDirectory:=GetProcAddress(iResultCode,'GetDefaultUserProfileDirectory');
//bResult:=_GetDefaultUserProfileDirectory(PChar (sProfilePath), len);
bResult:=GetDefaultUserProfileDirectoryA(PChar (sProfilePath), len);
result:=PChar(sProfilePath);
FreeLibrary(iResultCode);
end;