I haven't used the API in C++ yet; how do you get the Windows System directory in C++?
Printable View
I haven't used the API in C++ yet; how do you get the Windows System directory in C++?
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
}
Thanks. :cool:
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?/
shouldn't it not equal ERROR_SUCCESS if you got it?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
}
:)
No ;)Quote:
Originally posted by crptcblade
shouldn't it not equal ERROR_SUCCESS if you got it?
keeps outputting "error"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;
}
If I say if(i != ERROR_SUCCESS), I get the correct path.
:confused:
Well the error_success is used in loads of API's to indicate success (as the name suggests)Quote:
If the function succeeds, the return value is ERROR_SUCCESS.
Has anybody known for the API call to fail?
no, but you shouldn't take the risk just because it hasn't on previous occasions (i'm talking generically here)
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?
I thought it returned 0 if it failed, and then you can check GetLastError().
Ahem...
From MSDN:
Quote:
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.