Solved

GetWindowsDirectory doesn't work in my VC++ application

Posted on 2001-08-15
14
734 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

Suggested Solutions

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
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 difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

809 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