Solved

getwindowsdirectory    (netdll.dll???)

Posted on 1998-08-12
6
236 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses
Course of the Month6 days, 5 hours left to enroll

626 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