Solved

getwindowsdirectory    (netdll.dll???)

Posted on 1998-08-12
6
227 Views
Last Modified: 2010-04-04
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                                          
0
Comment
Question by:sierra20
6 Comments
 
LVL 1

Expert Comment

by:rene_moeller
ID: 1361956
Hi sierra20,

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, BufferSize);
  ShowMessage(StrPas(Buffer));
  FreeMem(Buffer);
end;

Rene_Moeller
0
 

Expert Comment

by:khenr29j
ID: 1361957
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
0
 
LVL 4

Expert Comment

by:erajoj
ID: 1361958
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

0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 4

Expert Comment

by:erajoj
ID: 1361959
Sorry!
I was too slow...

/// John
0
 

Author Comment

by:sierra20
ID: 1361960
Hi

Kristoffer, you can answers the question because you give me the best answers.

Thanks.

Sierra
0
 

Accepted Solution

by:
khenr29j earned 50 total points
ID: 1361961
Here you go Sierra.
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Path  to current project in Delphi. 2 80
Internet Explorer View Settings Question 15 111
How to debug For loops? 3 49
Dev express lookupcombo 3 28
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question