Category: Visual Studio

vs2005: fatal error C1083: Cannot open include file: 'Mscat.h': No such file or directory

add the following code: extern “C” { typedef HANDLE HCATADMIN; typedef HANDLE HCATINFO; typedef struct CATALOG_INFO_ { DWORD cbStruct; WCHAR wszCatalogFile[MAX_PATH]; } CATALOG_INFO; BOOL WINAPI IsCatalogFile( HANDLE hFile, WCHAR* pwszFileName ); BOOL WINAPI CryptCATAdminAcquireContext( HCATADMIN* phCatAdmin, const GUID* pgSubsystem, DWORD dwFlags ); BOOL WINAPI CryptCATAdminCalcHashFromFileHandle( HANDLE hFile, DWORD* pcbHash, BYTE* pbHash, DWORD dwFlags ); HCATINFO

Continue Reading →

IHTMLCollection iterating through HTML frames / GUI manipulation

LRESULT lResult; UINT nMsg = ::RegisterWindowMessage( _T(“WM_HTML_GETOBJECT”) ); ::SendMessageTimeout( handleToInternetExplorerWindow, nMsg, 0L, 0L, SMTO_ABORTIFHUNG, 1000, (DWORD*)&lResult); LPFNOBJECTFROMLRESULT pfObjectFromLresult = (LPFNOBJECTFROMLRESULT)::GetProcAddress( hInst, “ObjectFromLresult” ); HRESULT hr; CComPtr htmlDoc2; hr = (*pfObjectFromLresult)( lRes, IID_IHTMLDocument2, 0, (void**)&htmlDoc2); if ( SUCCEEDED(hr) ) { IHTMLFramesCollection2 *p; htmlDoc2->get_frames(&p); long lLen; p->get_length(&lLen); for (long i = 0; i < lLen; i++) {

Continue Reading →

_SECURE_SCL issues

Be careful when using _SECURE_SCL option when integrating your DLLs with DLLs you received from someone else. If you have compiled your dlls with this option but the dlls you use havent, you are most likely going to get a runtime application compatibility error. To fix this just remove this option. When secure SCL is

Continue Reading →

Getting the parent id of a process

Below is the code to return the parent id of a process, given a process id. This can be helpful in circumstances when we have to scan all the running processes to find out the spawned processes from another process. [code language=”cpp”] // change this method signature according to your requirements BOOL GetParentPID( DWORD dwParentId,

Continue Reading →

reading messages from message table

Sometimes data is also stored as message instead of resources. the easiest way to read this is as below: ofstream myfile; myfile.open (“example.txt”); HMODULE handle = LoadLibrary(“AgentRes.dll”); // dll for reading the file DWORD err=::GetLastError(); for(int i=0;i<10000;i++) { LPTSTR    lpMsgBuffer=NULL; DWORD dwRet=FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_HMODULE, handle, i, // number of the corresponding message // you

Continue Reading →

Windows debugging using windbg

Sometimes or most times when you get a crash dump from your customer, its always good to know how to reproduce the crash and point out where the actual crash happens. Today I was debugging some bug with my lead, I found this very useful: Here are the steps: First of all open the windows

Continue Reading →

Using DebugBreak()

I learnt this from my manager. DebugBreak is powerful tool you can use when debugging applications. I had this scenario where I need to use a java app which was internally calling C++ methods, basically JNI functions. The error in question was in the C++ side, so not really an option to use debugger. Therefore

Continue Reading →

Detecting memory leaks in VC++

One of the simplest ways to detect a leak in your code would be to use debugCRT. Simple usage: a. Create you project in visual studio b. run the project in debug mode, then only you will find the memory leak dumps int main() { _CrtSetDbgFlag(_CRTDBG_CHECK_ALWAYS_DF | _CRTDBG_ALLOC_MEM_DF); //below call will break where the leak

Continue Reading →