Solved

GetWindowsDirectory doesn't work in my VC++ application

Posted on 2001-08-15
14
715 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
  • 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
 
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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…

743 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

12 Experts available now in Live!

Get 1:1 Help Now