sierra20
asked on
getwindowsdirectory (netdll.dll???)
Hi
I use the function GetWindowsDirectory, I have no problem in win95 but in winnt 4, when the function is
executed, its give me an error :
var directory : string;
GetWindowsDirectory(PChar( directory) ,Max_Path) ;
"""An exception as occurs (EAccessViolation) with the message access violation of address '77F66DEF'
of module 'netdll.dll'. Write of address '00403DD5'.Processus stop """
P.S.:(i translate from the french error)
I dont understand what going on.
Thanks
I use the function GetWindowsDirectory, I have no problem in win95 but in winnt 4, when the function is
executed, its give me an error :
var directory : string;
GetWindowsDirectory(PChar(
"""An exception as occurs (EAccessViolation) with the message access violation of address '77F66DEF'
of module 'netdll.dll'. Write of address '00403DD5'.Processus stop """
P.S.:(i translate from the french error)
I dont understand what going on.
Thanks
You need to allocate memory for the string before you let Windows overwrite it. NT is probably more sensitive to memory overwrites and doesn't let you shoot yourself in the foot like Windows '95 does.
Corrected code:
var directory : string;
Begin
SetLength(Directory, GetWindowsDirectory(Nil, 0)+1);
GetWindowsDirectory(PChar( directory) ,Max_Path) ;
// etc
The first line allocates enough memory to hold the length of the windows directory returned by GetWindowsDirectory(Nil, 0) and adds one character to hold the trailing null character.
Best wishes,
-Kristoffer
Corrected code:
var directory : string;
Begin
SetLength(Directory, GetWindowsDirectory(Nil, 0)+1);
GetWindowsDirectory(PChar(
// etc
The first line allocates enough memory to hold the length of the windows directory returned by GetWindowsDirectory(Nil, 0) and adds one character to hold the trailing null character.
Best wishes,
-Kristoffer
Hi,
In Windows 95, everything seems to be allowed!? ;-)
You have to allocate heap space by setting the string length to MAX_PATH:
var directory : string; // creates empty string
SetLength( directory, MAX_PATH ); // allocates heap space
GetWindowsDirectory(PChar( directory) ,MAX_PATH) ; // now working!
/// John
In Windows 95, everything seems to be allowed!? ;-)
You have to allocate heap space by setting the string length to MAX_PATH:
var directory : string; // creates empty string
SetLength( directory, MAX_PATH ); // allocates heap space
GetWindowsDirectory(PChar(
/// John
Sorry!
I was too slow...
/// John
I was too slow...
/// John
ASKER
Hi
Kristoffer, you can answers the question because you give me the best answers.
Thanks.
Sierra
Kristoffer, you can answers the question because you give me the best answers.
Thanks.
Sierra
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I get the same error in NT, but this piece of code works:
var
Buffer : PChar;
BufferSize : integer;
begin
BufferSize := 255;
GetMem(Buffer, BufferSize);
GetWindowsDirectory(Buffer
ShowMessage(StrPas(Buffer)
FreeMem(Buffer);
end;
Rene_Moeller