Search This Blog

Saturday, January 17, 2009

Function delete a Folder or directory with files and subfolders.

There is no API to delete a directory with files and subfolders.
It is the function to delete folders with files using shell operation.


bool DeleteDirectory(LPCTSTR lpszDir)
{
int len = _tcslen(lpszDir);
TCHAR *pszFrom = new TCHAR[len+2];
_tcscpy(pszFrom, lpszDir);
pszFrom[len] = 0;
pszFrom[len+1] = 0;

SHFILEOPSTRUCT fileop;
fileop.hwnd   = NULL;    // no status display
fileop.wFunc  = FO_DELETE;  // delete operation
fileop.pFrom  = pszFrom;  // source file name as double null terminated string
fileop.pTo    = NULL;    // no destination needed
fileop.fFlags = FOF_NOCONFIRMATION|FOF_SILENT;  // do not prompt the user


fileop.fAnyOperationsAborted = FALSE;
fileop.lpszProgressTitle     = NULL;
fileop.hNameMappings         = NULL;

int ret = SHFileOperation(&fileop); 
delete [] pszFrom;  
return (ret == 0);
}

This function return true if it succeed.

Friday, January 16, 2009

Debugging in Release mode

Some application work well in debug mode, but crashes in release mode.
Normally we cannot able to debug in release mode.
Following is the settings to debug in release mode.

1) Open project settings by Alt+F7.
2) Select Release configuration.
3) Select “C/C++” tab. Set “Optimizations” as “Disable Debug” and “Debug Info” as “Program Database”.

4) Select “Link” tab. Enable “Generate Debug Info“.
5) Now From menu bar open "Build"--> "Set active configuration", and select Release build as  default.

6) Rebuild the project by F7.
7) Now you can debug in release mode

Thursday, January 1, 2009

How to include library File without using project seettings

include following line in your program

#pragma comment (lib, "yourLibname.lib")

Example:
#pragma comment (lib, "wbemuuid.lib")

Getting all Titles in Internet explorer running instance using COM

#import "mshtml.tlb" // Internet Explorer 5
#include "msHtml.h"
#include "ExDispID.h"
#import "shdocvw.dll"

#include "ExDisp.h"

void CIETabTiltleDlg::OnBnClickedOk() // Copy the following lines
{
SHDocVw::IShellWindowsPtr m_spSHWinds;
m_spSHWinds.CreateInstance(__uuidof(SHDocVw::ShellWindows));
ASSERT(m_spSHWinds != NULL);

CString strCount,m_strWinCount;
long nCount = m_spSHWinds->GetCount();
strCount.Format("%i", nCount);
m_strWinCount = strCount;

IDispatchPtr spDisp;
for (long i = 0; i <>
{
_variant_t va(i, VT_I4);
spDisp = m_spSHWinds->Item(va);
SHDocVw::IWebBrowser2Ptr spBrowser(spDisp);
if (spBrowser != NULL)
{
//m_ctlListLoc is the name of list box of your application

m_ctlListLoc.AddString(spBrowser->GetLocationName());
MSHTML::IHTMLDocument2Ptr spDoc(spBrowser->GetDocument());
if (spDoc != NULL)
{
//m_ctlListTitle is the name of list box of your application
m_ctlListTitle.AddString(spDoc->Gettitle());
}
}
}
m_spSHWinds=NULL;
}

Windows Vista User Account Control article

A nice article about "Windows Vista User Account Control" tips and problems in your programs about Administrators privileges.

Using DLLs and The Windows API in Visual Basic 6.0

Following Link has tutorials about Using DLLs and The Windows API in Visual Basic 6.0

error C2664: 'void ATL::CStringT::Format(const wchar_t *,...)' : cannot convert parameter 1 from 'const char [3]' to 'const wc

If you are getting following error:
error C2664: 'void ATL::CStringT::Format(const wchar_t *,...)' : cannot convert parameter 1 from 'const char [3]' to 'const wchar_t *'

Solution1:
In Project Menu select your Project Properties.

In Configuration Properties
Set "Character Set" as "Use Multi-Byte Character Set"

Solution2:
where ever you are declaring "CString" variable add Unicode support.
Example:
CString csStr(_T("")); //_T("") is for unicode support