|
-
Oct 13th, 2001, 06:31 PM
#1
Thread Starter
Member
GetWindowsDir in C++?
I haven't used the API in C++ yet; how do you get the Windows System directory in C++?
-
Oct 13th, 2001, 07:02 PM
#2
Code:
#include <windows.h>
UINT i;
char path[MAX_PATH];
UINT sz = MAX_PATH;
i = GetWindowsDirectory(path, sz);
if (i==ERROR_SUCCESS) {
// you got it --- path is a null terminated string
}
else {
something bombed.... not very likely with this call
call GetLastError to see what happened
}
-
Oct 13th, 2001, 07:05 PM
#3
Thread Starter
Member
Thanks.
-
Oct 13th, 2001, 07:12 PM
#4
PowerPoster
i got a quick q for a similar app that i am doing...
How do you find where any app is installed. like if i want to know where "somefile.exe" is?
Is there a standard way of doing it?/
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
-
Oct 13th, 2001, 07:24 PM
#5
Code:
#include <windows.h>
UINT i;
char path[MAX_PATH];
UINT sz = MAX_PATH;
i = GetWindowsDirectory(path, sz);
if (i==ERROR_SUCCESS) {
// you got it --- path is a null terminated string
}
else {
something bombed.... not very likely with this call
call GetLastError to see what happened
}
shouldn't it not equal ERROR_SUCCESS if you got it?
Laugh, and the world laughs with you. Cry, and you just water down your vodka.
Take credit, not responsibility
-
Oct 13th, 2001, 07:37 PM
#6
PowerPoster
Originally posted by crptcblade
shouldn't it not equal ERROR_SUCCESS if you got it?
No
-
Oct 13th, 2001, 07:45 PM
#7
PHP Code:
#include <iostream.h>
#include <windows.h>
//using namespace std;
int main()
{
UINT i;
char path[MAX_PATH];
UINT sz = MAX_PATH;
i = GetWindowsDirectory(path, sz);
if (i==ERROR_SUCCESS) {
cout << path << endl;
// you got it --- path is a null terminated string
}
else {
cout << "error" << endl;
//something bombed.... not very likely with this call
//call GetLastError to see what happened
}
return 0;
}
keeps outputting "error"
If I say if(i != ERROR_SUCCESS), I get the correct path.
Laugh, and the world laughs with you. Cry, and you just water down your vodka.
Take credit, not responsibility
-
Oct 13th, 2001, 08:03 PM
#8
PowerPoster
Well the error_success is used in loads of API's to indicate success (as the name suggests)
If the function succeeds, the return value is ERROR_SUCCESS.
-
Oct 13th, 2001, 08:06 PM
#9
Thread Starter
Member
Has anybody known for the API call to fail?
-
Oct 13th, 2001, 08:11 PM
#10
PowerPoster
no, but you shouldn't take the risk just because it hasn't on previous occasions (i'm talking generically here)
-
Oct 13th, 2001, 08:11 PM
#11
Thread Starter
Member
True; so would path just contain a million null chars? So can I assume that if the first char is not null that there was success?
-
Oct 13th, 2001, 08:40 PM
#12
Monday Morning Lunatic
I thought it returned 0 if it failed, and then you can check GetLastError().
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Oct 15th, 2001, 01:54 PM
#13
Ahem...
From MSDN:
If the function succeeds, the return value is the length, in characters, of the string copied to the buffer, not including the terminating null character.
If the length is greater than the size of the buffer, the return value is the size of the buffer required to hold the path.
If the function fails, the return value is zero. To get extended error information, callGetLastError.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|