Solved

GetWindowsDirectory doesn't work in my VC++ application

Posted on 2001-08-15
14
753 Views
Last Modified: 2008-02-01
I wrote:

LPSTR pszSysPath;
GetWindowsDirectory(pszSysPath,_MAX_PATH);

In the edit window, I can see the parameter information shown for the GetWindowsDirectory.
When compile it, error appears.

Compile error:
error C2061: syntax error : identifier 'GetSystemDirectoryA'

I tried others like GetSystemDirectory, GetCurrentDirectory, etc. The results are the same.
Is there any mistake. Please help me.

Thank you.

0
Comment
Question by:Zhen
[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
  • 4
  • 3
  • 2
  • +3
14 Comments
 
LVL 42

Accepted Solution

by:
sedgwick earned 50 total points
ID: 6391581
try:
     char pszSysPath[128];
     GetWindowsDirectory(pszSysPath, 128);
0
 

Author Comment

by:Zhen
ID: 6391761
Thank  sedqwick,

I did this before. Same error message.

Zhen
0
 

Author Comment

by:Zhen
ID: 6391820
I use these Get...Directory(s) in VB. It makes VB crash.

What is the problem behind this?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 7

Expert Comment

by:peterchen092700
ID: 6391956
>> what's the problem behind this?
VB:
a) probably a different than with your original Q
b) probably the parameter you pass as first value


VC:
did you #include <windows.h> ?

I checked the defines in two VC++ 6 versions - unless someone has tempered with the windows headers, it is extremely unlikely the line
  GetWindowsDirectory(pszSysPath,_MAX_PATH);
produces an error that GetSystemDirectoryA is not known.

btw. this Q would have better fit in the Windows Programming forum

Helped?
Peter
0
 

Author Comment

by:Zhen
ID: 6392077
Yes, I did #include <windows.h>

Thanks,

Zhen
0
 
LVL 32

Expert Comment

by:jhance
ID: 6392125
You say you have:

GetWindowsDirectory(pszSysPath,_MAX_PATH);


in your code but the error is:

error C2061: syntax error : identifier 'GetSystemDirectoryA'

I think you are not looking in the correct place in your source code.  What is the REST of the error message?  It gives a LINE NUMBER and FILE NAME.  
0
 

Expert Comment

by:lame_programmer
ID: 6392711
maybe everything is ok on your code..
what compiler are you using?

take a look in MSDN at Q113118 (mk:@MSITStore:\\YOUR_PATH_TO_MSDN\kbvc.chm::/Source/visualc/q113118.htm)

i quote:

Microsoft C/C++ Compiler (CL.EXE), included with:
Microsoft C/C++ for MS-DOS, version 7.0
Microsoft Visual C++ for Windows, versions 1.0, 1.5
Microsoft Visual C++ 32-bit Edition, versions 1.0, 2.0, 4.0, 4.1, 4.2, 5.0

[..snip..]

The compilers listed above may misinterpret a combination of an enumerated type, a default parameter, and a constructor or function notation cast as a syntax error and may incorrectly generate one of the following:

[..snip..]

error C2061: syntax error : identifier 'identifier'
0
 

Expert Comment

by:lame_programmer
ID: 6392737
forgot to suggest a solution:
1. - ask your "staff" to upgrade to Visual C++ 6.. or .NET? :)
2. - use something else instead of _MAX_PATH
i guess it is a const variable right now.. change it to
#define _MAX_PATH value
or give it another type.. try.. somehow it must work ('cause a lot of people used GetWindowsDirectory :)
0
 
LVL 1

Expert Comment

by:llewelm
ID: 6393809
What no points! Here's a free answer to your VB question:

Unlike C-style languages, you must actually allocate the memory for the output buffer before calling the function as follows:

Dim strBuf as String

strBuf = Space(128)
GetWindowsDirectory (strBuf, 128)

This should work.

0
 
LVL 32

Expert Comment

by:jhance
ID: 6393836
>>strBuf = Space(128)

This is the C++ topic area.  The above statement is unlikely to work since Space() is not a valid C++ or C runtime library function on any Windows environment that I'm aware of.

Not only that but sedgwick already posted a valid way of doing this above.
0
 
LVL 1

Expert Comment

by:llewelm
ID: 6393855
jhance,

If you check back in the question history, you will see that Zhen asked how this same thing might be accomplished in Visual Basic.

That was actually the basis of my "no points" comment.  Zhen should have actually been posted as a separate question under the VB forum.
0
 
LVL 32

Expert Comment

by:jhance
ID: 6393867
Sorry, I missed that.  If he wanted VB, I wonder why he asked in the C++ area.  In fact, this Q is off-topic here also.  It really should be in the Windows Programming area since it's not a c++ question at all.
0
 
LVL 7

Expert Comment

by:peterchen092700
ID: 6393998
looks like he wanted both... and expects a miraculous solution to pop up...
0
 

Author Comment

by:Zhen
ID: 6395458
Thank you all.

I tried the code in my home computer, no problem.
The GetWindowsDirectory and GetSystemDirectory both work but GetCurrentDirectory doesn't.

I'm so excited by the overwhelming response.

I acceptted sedqwick's answer, because he is the first to answer.

llewelm's VB answer is right too, and some others...

I'm new in VC. If I posted my question in the wrong area, I still got so many answers. I appreciate all your helps. Thank you! Thank you!!

The code I used In VC is:
char pszSysPath[_MAX_PATH];
GetSystemDirectory((LPSTR)pszSysPath, _MAX_PATH);

In VB:
Dim strSysPath as String*256
GetSystemDirectory(strSysPath, 256)

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

726 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