GetWindowsDirectory doesn't work in my VC++ application

I wrote:

LPSTR pszSysPath;

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.

Who is Participating?
Meir RivkinFull stack Software EngineerCommented:
     char pszSysPath[128];
     GetWindowsDirectory(pszSysPath, 128);
ZhenAuthor Commented:
Thank  sedqwick,

I did this before. Same error message.

ZhenAuthor Commented:
I use these Get...Directory(s) in VB. It makes VB crash.

What is the problem behind this?
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

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

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
produces an error that GetSystemDirectoryA is not known.

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

ZhenAuthor Commented:
Yes, I did #include <windows.h>


You say you have:


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.  
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


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:


error C2061: syntax error : identifier 'identifier'
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 :)
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.

>>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.

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.
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.
looks like he wanted both... and expects a miraculous solution to pop up...
ZhenAuthor Commented:
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)

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.