|
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
|
|
|
|
|
Terry,
Trupti Mehta wrote: On above code in UpdateData, I get "ASsertionFailure" File dlgdata.cpp: line 52 error, I choose Retry/Ignore
Could you get me the call stack? Press "retry" and it will take you to debugger. Just press "Alt+7" and you can see the Call stack window.
Trupti Mehta wrote: On coming of Child 2, I get "Out Of Memory" Error.
Since its WinCE, memory is limited. Check whether your dialog objects are created in heap instead of stack. Recursive function calls too can cause "out of memory". Check your call stack and verify that.
OT: Did you checked my reply in your old parent-child dialog communication problem?
Regards,
Jijo.
_____________________________________________________
http://weseetips.com[ ^] Visual C++ tips and tricks. Updated daily.
|
|
|
|
|
Jijo raj wrote: Could you get me the call stack? Press "retry" and it will take you to debugger. Just press "Alt+7" and you can see the Call stack window.
That's the problem Jijo, I don't get any stack. It infact doesn't go to the debugger. Usually on errors/exceptions the file where the error rises comes up & we can debug it, but with this error that file doesn't come up only. Also Alt+7 on Retry didn't work. Immediately after pressing Retry, "An unsupported operations ..." message box comes up.
<blockquote class="FQ"><div class="FQA">Jijo raj wrote:</div>OT: Did you checked my reply in your old parent-child dialog communication problem? </blockquote>
Yes I did. As I don't call the child dialogs by DoModal(), but call by Create & then ShowWindow().
This is the way they are created & called:
In parent .cpp:
void DataEntryDialog::CreateChildDialogs()
{
CRect rect(4, 2, 5,2);
childPage1.CRHCreateGenericChildDialog(this, &rect,IDD_PAGE1_DLG, NULL);
childPage1.SetDeptStock(deptStock);
childPage1.ShowWindow(SW_SHOW);
childVisible = 1;
free(rect);
return;
}
In child, while finishing work with it :
CPage1Dlg::~CPage1Dlg() {
m_operName.Empty();
deptStock.~DeptStock();
delete operatorsMap;
}
void CPage1Dlg::TellParent()
{
this->CRHPostMessageToParent(WM_CHANGED_DS, (int)&deptStock);
this->ShowWindow(SW_HIDE);
this->CRHPostMessageToParent(WM_SHOW_NEXT_VIEW, 2);
return;
}
Back to parent, in OnSHOW_NEXT_VIEW MESSAGE:
afx_msg LRESULT DataEntryDialog::OnSHOW_NEXT_VIEW(WPARAM wparam, LPARAM lparam) {
int childView = (int)lparam;
DestroyVisibleChild();
CRect rect(4, 2, 5,2);
switch(childView) {
case 1:
childPage1.CRHCreateGenericChildDialog(this, &rect,IDD_PAGE1_DLG, NULL);
childPage1.SetDeptStock(deptStock);
childPage1.SetOperatorsMap(operMap);
childPage1.ShowWindow(SW_SHOW);
break;
case 2:
AfxMessageBox(_T("ABOUT Create Child 2"));
childPage2.CRHCreateGenericChildDialog(this, &rect, IDD_PAGE2_DLG, NULL);
childPage2.SetDeptStock(deptStock);
childPage2.ShowWindow(SW_SHOW);
AfxMessageBox(_T("Shown"));
break;
case 3:
childPage3.CRHCreateGenericChildDialog(this, &rect, IDD_PAGE3_DLG, NULL);
childPage3.SetDeptStock(deptStock);
childPage3.SetDepartmentsMap(deptsMap);
childPage3.ShowWindow(SW_SHOW);
break;
}
childVisible = childView;
free(rect);
return 0;
}
void DataEntryDialog::DestroyVisibleChild()
{
CString s;
s.Format(_T("Destroying %d child"), childVisible);
AfxMessageBox(s, MB_SETFOREGROUND);
s.Empty();
switch(childVisible) {
case 1:
childPage1.~CPage1Dlg();
childPage1.DestroyWindow();
AfxMessageBox(_T("Destroyed Child 1"));
break;
case 2:
childPage2.~CPage2Dlg();
break;
..........
On debuggin on my own, I found out aFTER "Destroying 1 child", from DestroyChild(), "Destroyed Child 1" doesn't come up, 1st child is hidden & ("ABOUT Create Child 2")); also doesn't come up. So, it seems their is some problem with destructor of childpage1.
Their are no recursive funcitons called. I have tried my best to free up all the memory occupied by any object. On a normal object
DeptDetails dd(5, "Dept");
i have a practise of calling just dd.~DeptDetails(), but someone pointed out, "Calling destructor without freeing the memory", so where am I going wrong. And keeping that in mind, in many such places I have called free(&dd) before the destructor.
Jijo, my all 7 child dlgs are in PagesDlg file. I want DeptStock object to be used in all of them. At present I pass object via parent & update the parent back by CHANGED_DS message. Is their any better way to work out which might reduce sending msg to parent for updated object.
Help me out at the earliest, please. Now, I am in a hurry.
Thanks
Terry
|
|
|
|
|