Re: How can i detect windows folder automatically using c++?
Posted 24 September 2006 - 01:16 AM
Xing, on 24 Sep, 2006 - 10:04 AM, said:
That's not possible through standard C++. You will need to use external library for that.
That is obvious...any OS specific feature can be implemented only using external libraries.
Since he asked specifically for Windows, I don't think he is writing his application for multiple platforms.
So portability doesn't have much importance here.
sajadkk, on 24 Sep, 2006 - 08:56 AM, said:
How can i detect windows folder automaticaly using c++?
that is i want to detect windows folder and want to store a file int it using c++,please help me.
You can use the GetWindowsDirectory API Function defined in windows.h like this:
After the function call, s will contain the path of the Windows Directory.
Here's the Function Prototype Information about this API Function:
LPTSTR lpBuffer, // address of buffer for Windows directory
UINT uSize // size of directory buffer
Pointer to the buffer to receive the null-terminated string containing the path. This path does not end with a backslash unless the Windows directory is the root directory. For example, if the Windows directory is named WINDOWS on drive C, the path of the Windows directory retrieved by this function is C:\WINDOWS. If the system was installed in the root directory of drive C, the path retrieved is C:\.
Specifies the maximum size, in characters, of the buffer specified by the lpBuffer parameter. This value should be set to at least MAX_PATH to allow sufficient room in the buffer for the path.