something different :p

This is a discussion on something different :p within the Windows Programming forums, part of the Platform Specific Boards category; ok i have been looking around msdn and the best i could find was GetWindowsDirectory() which is not exactly what ...

  1. #1
    Registered User
    Join Date
    Sep 2002
    Posts
    254

    something different :p

    ok i have been looking around msdn and the best i could find was GetWindowsDirectory()

    which is not exactly what i am looking for... here is what i would like to be able to do, i would like to be able to determine using a function the drive letter of the HD or partition where windows has been installed eg: "C:\"

    thank you for your time

  2. #2
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789

    Re: something different :p

    Originally posted by ZerOrDie
    ok i have been looking around msdn and the best i could find was GetWindowsDirectory()

    which is not exactly what i am looking for... here is what i would like to be able to do, i would like to be able to determine using a function the drive letter of the HD or partition where windows has been installed eg: "C:\"

    thank you for your time
    This works in 2000 & XP...if you need it for 98/95 and it doesnt work, write back and I will get another way of doing it

    Code:
    #include <iostream>
    #include <windows.h>
    using std::cout;
    using std::endl;
    
    int main(){
    
    	DWORD dwSize = ExpandEnvironmentStrings("%SYSTEMDRIVE%",
    		NULL,0);//Getsize of string needed
    	if(!dwSize){
    		cout << "Error" << endl;
    		return 1;
    	}
    
    	char *szBuff = new char[dwSize];//create buffer to hold result
    	if(!szBuff){
    		cout << "Error" << endl;
    		return 1;
    	}
    
    	if(!ExpandEnvironmentStrings("%HOMEDRIVE%",
    		szBuff,dwSize)){//Get information
    		cout << "Error" << endl;
    		return 1;
    	}
    
    	cout << "Main Drive is " << szBuff << endl;
    
    	delete [] szBuff;//Cleanup!!!
    
    
    	return 0;
    }
    Last edited by Fordy; 09-11-2002 at 04:13 AM.

  3. #3
    Registered User
    Join Date
    Sep 2002
    Posts
    254
    i was actually aiming for portability between all the recent series of windows eg: 95-xp

    let me know if there is a better to do this

    unfortunatly i wont work on 98 "%HOMEDRIVE%" is the output
    Last edited by ZerOrDie; 09-11-2002 at 10:01 AM.

  4. #4
    Mayor of Awesometown Govtcheez's Avatar
    Join Date
    Aug 2001
    Location
    MI
    Posts
    8,825
    Is windows programming between different versions different frequently, or not?

  5. #5
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789
    Originally posted by Govtcheez
    Is windows programming between different versions different frequently, or not?
    Unfortunately yes...Win 95 was brought out after the first NT to fill a large gap in the market of machines that did not have the facilities to run WinNT....it's API was drastically cut down and as far as I have read it was only supposed to be a temporary measure...

    Unfortunatley it took off and left NT (the system it was a strip-down of) behind......98 & ME more or less implement the same API (few more added on here and there).

    So a lot of the really neat aspects of NT are not allowed in 95/98/ME..

    Back to the problem....I cant think off hand of a way to directly get this info, but you could always get the system directory path and chop it down with one of the standard string functions.....like so.
    Code:
    #include <iostream>
    #include <windows.h>
    #include <cstring>
    using std::cout;
    using std::endl;
    
    int main(){
    
    	DWORD dwSize = GetSystemDirectory(NULL,0);//Getsize of string needed
    	if(!dwSize){
    		cout << "Error" << endl;
    		return 1;
    	}
    
    	char *szBuff = new char[dwSize];//create buffer to hold result
    	if(!szBuff){
    		cout << "Error" << endl;
    		return 1;
    	}
    
    	if(!GetSystemDirectory(szBuff,dwSize)){//Get information
    			cout << "Error" << endl;
    			delete [] szBuff;
    			return 1;
    	}
    
    	dwSize = strcspn(szBuff,"\\");
    
    	szBuff[dwSize] = NULL;
    
    	cout << "Main Drive is " << szBuff << endl;
    
    	delete [] szBuff;//Cleanup!!!
    
    
    	return 0;
    }

  6. #6
    Registered User
    Join Date
    Sep 2002
    Posts
    254
    i was actually thinking of that before i posted this and was whishing for something a little less hackish but if there is no better way i guess it shall do thank you fordy


    oh yah fordy if you dont mind what degrees would you posses im just interested attending university myself
    Last edited by ZerOrDie; 09-11-2002 at 05:20 PM.

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21