Search This Blog

Thursday, May 24, 2012

Linker Errors when using InetIsOffline


Some times we will get linker errors like below when you are usnig InetIsOffline() Function.
 error LNK2019: unresolved external symbol __imp__InetIsOffline@4 referenced in function

To solve this problem add the following code after Header files include.

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

(OR)

Otherwise add "url.lib" in the Linker input of your project settings.

Wednesday, June 16, 2010

xtreme toolkit Sample Dialog Gradient Window Example



//In Header File

#include "c:\program files\codejock software\mfc\xtreme toolkitpro v13.0.0\source\controls\xtbutton.h"
#define HIGH_DLG_CLR RGB(163,194,236)
#define LOW_DLG_CLR RGB(220,235,253)


//public:
//Add Two buttons
CXTButton m_btnOK;
CXTButton m_edBTNNN;




//In CPP File
BOOL CextremeSampleDlg::OnInitDialog()
{
CDialog::OnInitDialog();

// Add "About..." menu item to system menu.

// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);

CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
BOOL bNameValid;
CString strAboutMenu;
bNameValid = strAboutMenu.LoadString(IDS_ABOUTBOX);
ASSERT(bNameValid);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}

m_btnOK.SetTheme( new CXTButtonThemeOffice2003 ( TRUE ) );
m_edBTNNN.SetTheme( new CXTButtonThemeOfficeXP ( TRUE ) );
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon



return TRUE; // return TRUE unless you set the focus to a control
}


void CextremeSampleDlg::OnPaint()
{
CPaintDC dc(this); // device context for painting
CXTPClientRect rc(this);
CXTPPaintManager::SetTheme(xtpThemeOffice2003);
CXTPOffice2003Theme *pPaintManager = (CXTPOffice2003Theme *)XTPPaintManager();
/*pPaintManager->GradientFill(&dc, rc,
pPaintManager->m_clrCommandBar.clrLight,
pPaintManager->m_clrCommandBar.clrDark ,
NULL);*/

pPaintManager->GradientFill(&dc, rc,LOW_DLG_CLR, HIGH_DLG_CLR , NULL);
}

Thursday, April 1, 2010

Download a webpage using WinInet



#include <wininet.h>


BOOL DownloadWebContentUsingWinInet(CString csURL,CString &csDownloadedContent)
{

if ( csURL.IsEmpty() )
return FALSE;
HINTERNET hINet, hFile;
hINet = InternetOpen("InetURL/1.0", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0 );
if ( !hINet )
{
AfxMessageBox("InternetOpen Failed");
return FALSE;
}
hFile = InternetOpenUrl( hINet, csURL, NULL, 0, 0, 0 ) ;
if ( hFile )
{
CHAR buffer[1024];
DWORD dwRead;
while ( InternetReadFile( hFile, buffer, 1023, &dwRead ) )
{
if ( dwRead == 0 )
break;
buffer[dwRead] = 0;
csDownloadedContent += buffer;
}
InternetCloseHandle( hFile );
}
InternetCloseHandle( hINet );

return TRUE;
}

Sunday, March 21, 2010

Check whether a file exist

//Check whether a file exist
//Portable to linux

#include <sys/stat.h>
#include <string>
using namespace std;

bool FileExists(string strFilename)
{
struct stat stFileInfo;
bool blnReturn= false;
int intStat=-1;
// Attempt to get the file attributes
intStat = stat(strFilename.c_str(),&stFileInfo);
if(intStat == 0)
{
// We were able to get the file attributes
blnReturn = true;
}
else
{
// We were not able to get the file attributes.
blnReturn = false;
}
return blnReturn;
}

Thursday, January 21, 2010

Stealing icon of another appliaction.



HICON hIcon;
hIcon = ExtractIcon( AfxGetApp()->m_hInstance, "C:\\WINDOWS\\system32\\calc.exe", 0 );
SetIcon( hIcon, FALSE );
//Do at destroy of dialog
//To avoid Resourse Leak
//DestroyIcon(hIcon);

Tuesday, December 15, 2009

Linker Errors when using winservice

Some times we will get linker errors like below when creating winservice.
To solve this add following code.



#pragma comment (lib, "advapi32.lib")
#pragma comment (lib, "user32.lib")


Or

include user32.lib and advapi32.lib in linker input of project settings



error LNK2019: unresolved external symbol __imp__CloseServiceHandle@4 referenced in function
error LNK2019: unresolved external symbol __imp__CreateServiceA@52 referenced in function
error LNK2019: unresolved external symbol __imp__OpenSCManagerA@12 referenced in function
error LNK2019: unresolved external symbol __imp__DeleteService@4 referenced in function
error LNK2019: unresolved external symbol __imp__OpenServiceA@12 referenced in function
error LNK2019: unresolved external symbol __imp__ControlService@12 referenced in function
error LNK2019: unresolved external symbol __imp__StartServiceA@12 referenced in function
error LNK2019: unresolved external symbol __imp__StartServiceCtrlDispatcherA@4 referenced in function
error LNK2019: unresolved external symbol __imp__SetServiceStatus@8 referenced in function
error LNK2019: unresolved external symbol __imp__RegisterServiceCtrlHandlerA@8 referenced in function
error LNK2019: unresolved external symbol __imp__PostThreadMessageA@16 referenced in function

Wednesday, December 2, 2009

Remove Duplicates From Vector Template Example



#include <vector>
#include <algorithm>
using namespace std;
// Add this header files

/*
Template function to Remove Duplicates
From a vector */


template <class T>
void RemoveDuplicates(vector<T> &vecContents)
{
vector<T> ::iterator vItr;

sort(vecContents.begin(),vecContents.end());
vItr=unique(vecContents.begin(),vecContents.end());
if(vItr!=vecContents.end())
vecContents.erase(vItr,vecContents.end());
}




//Usage Example 1

vector<CString> vNames;
vNames.push_back("John");
vNames.push_back("Victor");
vNames.push_back("Nancy");
vNames.push_back("William");
vNames.push_back("Nancy");

RemoveDuplicates(vNames);


//Usage Example 2
vector<int> vNos;
vNos.push_back(1);
vNos.push_back(1);
vNos.push_back(4);

RemoveDuplicates(vNos);