Solved

getwindowsdirectory    (netdll.dll???)

Posted on 1998-08-12
6
223 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 4

Expert Comment

by:erajoj
Comment Utility
Sorry!
I was too slow...

/// John
0
 

Author Comment

by:sierra20
Comment Utility
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
Comment Utility
Here you go Sierra.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

762 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now