|
Use FindFirstFile()/FindFirstFileEx() to find a file with a specifc name. DeleteFile() to delete it
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
If you already know the path of the file to be deleted, then you don't have to search for it. You can use PathFileExists() function to see if the file exists. you can also use the function PathIsDirectory() to see if given path is that of a directory or a file. The below code snippet might make the point clear to you.
TCHAR szFilePath[MAX_PATH];
_tcscpy(szFilePath, _T("C:\\file.txt") );
if(PathFileExists(szFilePath) && !PathIsDirectory(szFilePath))
DeleteFile(szFilePath);
Regards,
Vijay.
|
|
|
|
|
error C2065: 'PathFileExists' : undeclared identifier
error C2065: 'PathIsDirectory' : undeclared identifier
Regards:
Xohaib Shirani
|
|
|
|
|
Header shlwapi.h
Import library shlwapi.lib
OK,. what country just started work for the day ? The ASP.NET forum is flooded with retarded questions. -Christian Graus
Best wishes to Rexx[^]
|
|
|
|
|
Hi
In Programming with Microsoft Visual C++.NET book, author shows a custom control dll. In his code:
LRESULT CALLBACK AFX_EXPORT
RygWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
CWnd* pWnd;
pWnd = CWnd::FromHandlePermanent(hWnd);
if (pWnd == NULL) {
pWnd = new CRygWnd();
pWnd->Attach(hWnd);
}
ASSERT(pWnd->m_hWnd == hWnd);
ASSERT(pWnd == CWnd::FromHandlePermanent(hWnd));
LRESULT lResult = AfxCallWndProc(pWnd, hWnd, message,
wParam, lParam);
return lResult;
}
I downloaded The Ultimate Toolbox code, there is no call to AfxCallWndProc
For example:
BOOL COXTabViewContainer::Create(CWnd* pParentWnd, CRect rect,
DWORD dwStyle,
UINT nID)
{
ASSERT(pParentWnd != NULL);
ASSERT(dwStyle & WS_CHILD);
ASSERT(nID != 0);
DWORD dwCreateStyle=dwStyle&~(WS_HSCROLL|WS_VSCROLL);
dwCreateStyle&=~WS_BORDER;
dwCreateStyle|=WS_CHILD;
WNDCLASS wndClass;
wndClass.style=CS_DBLCLKS;
wndClass.lpfnWndProc=AfxWndProc;
wndClass.cbClsExtra=0;
wndClass.cbWndExtra=0;
wndClass.hInstance=AfxGetInstanceHandle();
wndClass.hIcon=0;
wndClass.hCursor=::LoadCursor(NULL,IDC_ARROW);
wndClass.hbrBackground=(HBRUSH)(COLOR_BTNFACE+1);
wndClass.lpszMenuName=NULL;
wndClass.lpszClassName=_T("TabViewContainer");
if(!AfxRegisterClass(&wndClass))
return FALSE;
if (!CreateEx(WS_EX_CLIENTEDGE,wndClass.lpszClassName,NULL,
dwCreateStyle,rect.left,rect.top,rect.Width(),rect.Height(),
pParentWnd->m_hWnd,(HMENU)(INT_PTR)nID,NULL))
{
return FALSE;
}
pParentWnd->ModifyStyleEx(WS_EX_CLIENTEDGE, 0, SWP_DRAWFRAME);
::SetWindowLongPtr(GetSafeHwnd(),GWL_USERDATA,ID_TABVIEWCONTAINER_SIGN);
SetScrollStyle(0,TRUE);
CalcLayout();
return TRUE;
}
In MSJ for AfxCallWndProc:
You can think of AfxWndProc as a function with a big switch statement that routes WM_XXX messages to your window class's OnXXX handler functions. This is a first-order approximation of how AfxWndProc works:
// This is a gross simplification
LRESULT AfxWndProc(HWND hwnd, UINT msg, ...)
{
CWnd* pWnd = CWnd::FromHandle(hwnd);
switch (msg) {
case WM_CREATE:
pWnd->OnCreate(...);
return 0;
case WM_SETFOCUS:
pWnd->OnSetFocus(...);
return 0;
.
.
.
// etc.
}
return 0L;
}
If AfxWndProc routes WM_XXX messages to window class's OnXXX handler functions, why didn't Ultimate toolbox use it?
If i derive a class from any MFC wnd class(CWnd, CFrameWnd, CEdit etc...) haven't it got all the default wndproc for messages(because i derived it from CWnd class)? So why do we need to call AfxWndProc?
|
|
|
|
|
I have this code snippet which writes an encrypted value of a string into a file
(KEY_FILE -- #defined as C:\xyz.txt) ;
BYTE *pbBlob;
DWORD cbBlob;
:
:
:
if (!CryptExportKey(hSessionKey, hKey, SIMPLEBLOB, 0, NULL, &cbBlob))
{
dwResult = GetLastError();
MessageBox("Error CryptExportKey() failed.", "Information", MB_OK);
return;
}
if (!CryptExportKey(hSessionKey, hKey, SIMPLEBLOB, 0, NULL, &cbBlob))
{
dwResult = GetLastError();
MessageBox("Error CryptExportKey() failed.", "Information", MB_OK);
return;
}
if ((pbBlob = (BYTE *) LocalAlloc(LMEM_ZEROINIT,cbBlob)) == NULL)
{
dwResult = ERROR_NOT_ENOUGH_MEMORY;
MessageBox("Error LocalAlloc() failed.", "Information", MB_OK);
return;
}
if (!CryptExportKey(hSessionKey, hKey, SIMPLEBLOB, 0, pbBlob, &cbBlob))
{
dwResult = GetLastError();
MessageBox("Error CryptExportKey() failed.", "Information", MB_OK);
return;
}
if(hSessionKey != 0)
CryptDestroyKey(hSessionKey);
hSessionKey = 0;
FILE *fp = fopen(KEY_FILE, "w+b");
if (fp) {
fwrite(pbBlob, 1, cbBlob, fp);
fclose(fp);
}
I find a junk value written by the above code in "C:\xyz.txt" which is like :
h ¤ zÛ³Wp <ø®lŒoWP¸"Ç^1iM€ÌygUjŽæ#Eì}ÔKËëü’²ôâ  äÃr[X>¾U
Since, the file contained
h ¤ zÛ³Wp <ø®lŒoWP¸"Ç^1iM€ÌygUjŽæ#Eì}ÔKËëü’²ôâ  äÃr[X>¾U string,
I was expecting pbBlob to point to the above content ie.
h ¤ zÛ³Wp <ø®lŒoWP¸"Ç^1iM€ÌygUjŽæ#Eì}ÔKËëü’²ôâ  äÃr[X>¾U
But when I debug, the following line
fwrite(pbBlob, 1, cbBlob, fp)
shows me the value of pbBlob = "||" and cbBlob = 76
What is the problem here. How can I get the junk value in a CString ?
Will some kind of casting help ?
|
|
|
|
|
Go to memory address pointed by pbBlob and have a look at the contents. Watch window will not show you full contents.
and dont compare it with the contents of notepad. Open the file in VC++ IDE it will show you all hex as well as text data then compare it.
Regards,
Sandip.
|
|
|
|
|
Enable dispaly unicode strings settings in the IDE.
|
|
|
|
|
Is this option avaialbe in VC++6.0.
Thanks a lot.
Regards,
Sandip.
|
|
|
|
|
|
The following code snippet worked out for me in getting the junk value (stored in the file) into a CString
value.
CString csEncryptedString(_T(""));
char *pEncryptedString = new char;
for (INT i = 0; i < (int)cbBlob; i++)
{
if (pbBlob[i] == '\0')
{
pEncryptedString[i] = '-';
}
else
{
pEncryptedString[i] = pbBlob[i];
}
}
pEncryptedString[cbBlob + 1] = '\0';
csEncryptedString = pEncryptedString;
Thanks all for your various suggestions and support.
Any other efficient code is always welcome.
|
|
|
|
|
How to get Windows user's Login and Logout time?
Nigah M Manzoor
|
|
|
|
|
Using COM it's possible, though I haven't used it at all, just did a quick search and found this for you...
IADsUser COM interface provides these methods for you, google for more information...
get_LastLogin
get_LastLogoff
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
|
|
|
|
|
|
thanx,
its working
Nigah M Manzoor
|
|
|
|
|
leonigah wrote: thanx,
its working
Welcome.
I am curious to see the code! Is it possible?
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
|
|
|
|
|
You might look into the ISensLogon interface.
"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
|
|
|
|
|
#include <comdef.h>
#include <iads.h>
#include <adshlp.h>
#pragma comment (lib, "ActiveDS.lib")
#pragma comment (lib, "Adsiid.lib")
void CSysInfoDlg::OnOK()
{
IADsContainer *pCont = NULL;
CString str = "WinNT://DOMEN_NAME";
HRESULT hr = ADsGetObject(str.AllocSysString(), IID_IADsContainer, (void**) &pCont );
if(!SUCCEEDED(hr))
return;
ULONG ulFetched = 0L;
_variant_t var;
_variant_t vChild;
IEnumVARIANTPtr pEnum;
ADsBuildEnumerator(pCont,&pEnum);
while((SUCCEEDED(ADsEnumerateNext(pEnum, 1, &vChild, &ulFetched)) && ulFetched==1))
{
IADsUser* pADs = NULL;
hr = V_DISPATCH(&vChild)->QueryInterface(IID_IADsUser, (void**)&pADs);
if(hr!=S_OK)
break;
DATE din = 0;
pADs->get_LastLogin(&din);
COleDateTime d(din);
CString strIn = d.Format("%d-%m-%Y %H:%M");
DATE dout = 0;
pADs->get_LastLogoff(&dout);
COleDateTime d1(dout);
CString strOut = d1.Format("%d-%m-%Y %H:%M");
BSTR bstrName;
pADs->get_Name(&bstrName);
CString strName = bstrName;
SysFreeString(bstrName);
pADs->Release();
pADs = NULL;
MessageBox(strIn+"=="+strOut, strName);
}
if(pCont)
pCont->Release();
}
Nigah M Manzoor
|
|
|
|
|
Hi all,
how can i get the value of pressed key of keyboard .
how can check it is is "A to Z" or "0 tp 9" of special character.
Thanks in advance.
IN A DAY, WHEN YOU DON'T COME ACROSS ANY PROBLEMS - YOU CAN BE SURE THAT YOU ARE TRAVELLING IN A WRONG PATH
|
|
|
|
|
Handle WM_CHAR [^] notification.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
CPallini wrote: Handle WM_CHAR[^] notification.
What if the window had controls like editbox on it? (which is usually the case)
Nobody can give you wiser advice than yourself. - Cicero
.·´¯`·->Rajesh<-·´¯`·.
Codeproject.com: Visual C++ MVP
|
|
|
|
|
Rajesh R Subramanian wrote: What if the window had controls like editbox on it? (which is usually the case)
yes sir
IN A DAY, WHEN YOU DON'T COME ACROSS ANY PROBLEMS - YOU CAN BE SURE THAT YOU ARE TRAVELLING IN A WRONG PATH
|
|
|
|
|
You may over-ride PreTranslateMessage()
BOOL CTrialDlg::PreTranslateMessage(MSG* pMsg)
{
if(pMsg->message == WM_KEYDOWN){
if(pMsg->wParam >= 0x41 && pMsg->wParam <= 0x5A)
{
}
else if(pMsg->wParam >= 0x30 && pMsg->wParam <= 0x39)
{
}
}
return CDialog::PreTranslateMessage(pMsg);
}
Nobody can give you wiser advice than yourself. - Cicero
.·´¯`·->Rajesh<-·´¯`·.
Codeproject.com: Visual C++ MVP
|
|
|
|
|
Rajesh R Subramanian wrote: BOOL CTrialDlg::PreTranslateMessage(MSG* pMsg) { if(pMsg->lParam == WM_KEYDOWN){ if(pMsg->wParam >= 0x41 && pMsg->wParam <= 0x5A) { //something between a and z was pressed } else if(pMsg->wParam >= 0x30 && pMsg->wParam <= 0x39) { //a number was pressed //check 0x60 through 0x69 to trap numbers //from the numpad keys as well } } return CDialog::PreTranslateMessage(pMsg);}
How can use it on purticular EditBox.
IN A DAY, WHEN YOU DON'T COME ACROSS ANY PROBLEMS - YOU CAN BE SURE THAT YOU ARE TRAVELLING IN A WRONG PATH
|
|
|
|
|
if(pMsg->hwnd == <youredit>.m_hWnd)
in your PreTranslateMessage
-@SuDhIrKuMaR@-
|
|
|
|
|