|
You could also use GetEnvironmentVariable:
TCHAR tcDirName[_MAX_PATH];
GetEnvironmentVariable(_T("userprofile"), tcDirName, _MAX_PATH);
This environment variable is set when the user logs on.
Note that it is not always on the same drive as the system (C .
Hope that helps.
Karl - WK5M
PP-ASEL-IA (N43CS)
PGP Key: 0xDB02E193
PGP Key Fingerprint: 8F06 5A2E 2735 892B 821C 871A 0411 94EA DB02 E193
|
|
|
|
|
Thanks for your reply, is there any specific win32 API who will do this job. As i need to use this in win32 API programming, not in MFC or higher framwork.
-Nandu
|
|
|
|
|
That is Win32 API call.
Karl - WK5M
PP-ASEL-IA (N43CS)
PGP Key: 0xDB02E193
PGP Key Fingerprint: 8F06 5A2E 2735 892B 821C 871A 0411 94EA DB02 E193
|
|
|
|
|
Nandu_77b wrote: is there any specific win32 API who will do this job
Yes, use
GetUserProfileDirectory - retrieves the path to the root directory of the specified user's profile.
For e.g. C:\Documents and Settings\Nibu
A function which uses ths API to return current process user home dir...
#include "Userenv.h"
#pragma comment(lib, "userenv.lib")
CString GetUserHomeDir()
{
TCHAR szHomeDirBuf[MAX_PATH] = { 0 };
HANDLE hToken = 0;
VERIFY( OpenProcessToken( GetCurrentProcess(), TOKEN_QUERY, &hToken ));
DWORD BufSize = MAX_PATH;
VERIFY( GetUserProfileDirectory( hToken, szHomeDirBuf, &BufSize ));
CloseHandle( hToken );
return CString( szHomeDirBuf );
}
Then there are other functions too which might interest you, like...
GetAllUsersProfileDirectory
GetDefaultUserProfileDirectory
GetProfilesDirectory
Look up these in MSDN for more information.
Nibu thomas
Microsoft MVP for VC++
Code must be written to be read, not by the compiler, but by another human being.
Programming Blog: http://nibuthomas.wordpress.com
modified on Wednesday, June 4, 2008 11:55 PM
|
|
|
|
|
Is the given code correct?
I am wondering about the return instruction, in which a CString object is created:
return CString( szHomeDirBuf );
In my opinion this object will be already destroyed while the function returns.
When accessing from caller, the object is already invalid.
CString res = GetUserHomeDir();
Am I wrong?
|
|
|
|
|
Hi
How to get User's gateway IP using VC++ ?.
Is there any VC++ API to find the IE Version ?.
Thanks in advance.
Prabhat Singh
|
|
|
|
|
Use GetAdaptersInfo() .
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Can somebody tell me the best book to start with COM&ATL Stuff?
|
|
|
|
|
Aseem Sharma wrote: tell me the best book
Well I think books can be somewhat personal but for me it was this one.[^]
led mike
|
|
|
|
|
Inside COM - Dale Rogerson
Sudhir Kumar
|
|
|
|
|
|
|
hi, well, im currently using visual studio 2003 to compile or attempt to compile a Half life 2, AKA. a source mod, but i get 2 errors and im having trouble getting rid of them so i can compile the *.dll file, i get these errors as follows:
Error C2062: Type 'void' unexpected
Error C2447: '{': missing function header (old-style formal list?)
the code seems to be correct and should work but those 3 errors are prohibiting me from compiling the *.dll file, any help would be great apreaciated.
(i have attached the small block of code that the errors point too)
CWeaponDualies( void )
{
m_flSoonestPrimaryAttack = gpGlobals->curtime;
m_flAccuracyPenalty = 0.0f;
m_fMinRange1 = 24;
m_fMaxRange1 = 1500;
m_fMinRange2 = 24;
m_fMaxRange2 = 200;
m_bFiresUnderwater = true;
}
modified on Wednesday, June 4, 2008 9:17 AM
|
|
|
|
|
What happens when you remove void ?
|
|
|
|
|
it removes 1 of the errors, thanks for pointing that error out, but i still get this error:
Error C2447: '{' missing function header style (old-style formal list?)
|
|
|
|
|
Check if the function has an appropriate function declaration.
Google for the error "C2447". There are several solutions to solve this.
modified on Wednesday, June 4, 2008 9:33 AM
|
|
|
|
|
Weird problem I have this function (is a function changed I used it to another purpose)
void browseFolder(TCHAR *path, TCHAR *initial)
{
WIN32_FIND_DATA FindFileData;
HANDLE hFind=INVALID_HANDLE_VALUE;
TCHAR dir[MAX_PATH];
TCHAR aux[MAX_PATH];
StringCchCopy(aux, MAX_PATH, path);
StringCchCat(aux, MAX_PATH, TEXT("\\*"));
hFind= FindFirstFile(aux,&FindFileData);
do
{
if (FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{
if((_tcscmp (FindFileData.cFileName, _T(".")) != 0) && (_tcscmp (FindFileData.cFileName, _T("..")) != 0))
{
StringCchCopy(dir, MAX_PATH, path);
StringCchCat(dir, MAX_PATH, TEXT("\\"));
StringCchCat(dir, MAX_PATH, FindFileData.cFileName);
browseFolder(dir,initial);
}
}
else
{
TCHAR pathFileName[MAX_PATH];
StringCchCopy(pathFileName, MAX_PATH, path);
StringCchCat(pathFileName, MAX_PATH, TEXT("\\"));
StringCchCat(pathFileName, MAX_PATH, FindFileData.cFileName);
CString szMessage;
szMessage.Format(_T("%s"),pathFileName);
_tprintf(_T("%s\n"),szMessage);
DeleteFile(szMessage);
}
}
while (FindNextFile(hFind, &FindFileData) != 0);
hFind= INVALID_HANDLE_VALUE;
_tprintf(path);
RemoveDirectory(path);
}</dir>
The function delete all the files but lives the folders intact I cannot understand why. Seems like they are in use and they cannot be deleted....
|
|
|
|
|
HEY !
how many times are you going to ask this ?
can't you follow the same thread ? it's not a chat buddy, it's a forum.
so ask you question, and wait !
|
|
|
|
|
Did you try GetLastError() or check that whether the files have been deleted completely before calling RemoveDirectory(). Try putting some Sleep(interval) between deleting files and the folder if you want to test this
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
I do not see that you heeded the earlier suggestion of calling FindClose(hfind) .
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Thank you from the bottom of heart.
The FindClose was the magic function now it works fine.
|
|
|
|
|
Hello,
I have a SDI application for Win CE ARMV4I. From menu, I select an option & a dialog appreas which is a main dialog. On this dialog, other child dialogs are opened. Their are 7 instances of child dialogs. On a message command send by a child dialog, the previous dialog is destroyed, new is created & displayed.
On Child dialog 1, on the below lines:
AfxMessageBox(_T("Into OnGetData"));
UpdateData(true);
OperatorDetails od;
if (true) {
m_operName = "Trial";
UpdateData (false);
AfxMessageBox(m_operName);
EnableConfirm(true);
} else {
m_operName = "";
EnableConfirm(false);
}
od.~OperatorDetails();
UpdateData (true);
On above code in UpdateData, I get "ASsertionFailure" File dlgdata.cpp: line 52 error, I choose Retry/Ignore (Abort shuts down the window) & I get "An unsupported operation was attempted". I get this error 3 times when I am at the above lines, later it is again fine. The flow of error windows is like "Into OnGetData", "Assertion Failure", "An unsuported...", "Assertion Failure", "An unsuported...", "Trial", "Assertion Failure" & "An unsuported...". The error is not with EnableConfirm(), as I tried deleting the lines but the error still persists.
On coming of Child 2, I get "Out Of Memory" Error.
Can anyone tell me what is the error and why does this come like this. Any help is highly appreciated.
Thanks
Terry
|
|
|
|
|
My first suggestion would be to not use UpdateData() .
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
David, not to use UpdateData, then what to use? Go for something like SetWindowText()! What is the associated var is not of CString & of other data type like int, float, etc.
Would be glad to know the alternative. More would also like to know why not to use UpdateData ?
Thanks
Terry
|
|
|
|
|
Trupti Mehta wrote: David, not to use UpdateData, then what to use?
See here.
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|