Category: C++

ipps90legacy.h not found error

Goto https://software.intel.com/en-us/articles/intel-ipp-legacy-libraries and download the links for your OS. Then follow the installation text file inside the zipped file. The password is specified in the installation file. Once downloaded extract the headers and libs into the proper folder. e.g. /opt/intel/include…

Continue Reading →

MFC / Javascripts / CSS Integrations

Nowadays it feels like everywhere and everyone is using HTML. So why not use it for building a MFC based application by using lesser and lesser MFC dialogs. Lets start by creating a MFC application using visual studio any version is fine. Open up visual studio as below, and create a new MFC based application

Continue Reading →

ARC – Disabling arc for specific files

Sometimes while including projects or files not developed by you, it would be necessary to go ahead and disable this option. To do this, goto your project settings, build phases, expand compile sources, click on a specific file and add this option to the compiler settings -fno-objc-arc That should do the trick. happy coding.

Continue Reading →

Heapsort implementation in C++

// // heapSort.cpp // learnCpp // // Copyright 2011 __MyCompanyName__. All rights reserved. // #include using namespace std; void display(int a[], int n) { cout<<” ————— “<<endl; for (int i=0;i<5; ++i) { cout<<a[i]<<endl; } } void heapify(int a[], int n) { int i,j,k,item; for(k=1; k0 && item > a[j]) { // if parent exists and

Continue Reading →

Resolve C2872 errors: ambiguous symbol

4>g:worktest.cpp(119): error C2872: ‘CRegKey’ : ambiguous symbol 4> could be ‘g:workwindowscregkey.h(33) : CRegKey’ 4> or ‘c:program files (x86)microsoft visual studio 10.0vcatlmfcincludeatlbase.h(5459) : ATL::CRegKey’ In case you have such issues, the easiest way to resolve them would be to use ::CRegKey in front of the keyword. This will call the local libraries first.

Continue Reading →

Iterate through all the tabs in Internet Explorer Windows

I found this code useful when you want to go through each tab and then look into their URLs and so on. You can also quit each tab individually. [sourcecode lang=”cpp”] // Implementation #include #include typedef BOOL (CALLBACK * IEENUMPROC)(HWND hwnd, LPVOID pif, LPARAM lParam); static BOOL CALLBACK EnumIEChildWindows(HWND hwnd, LPARAM lParam) { TCHAR szClassName[100];

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 →

Using Virtual Box COM APIs to list the Virtual machine snapshots

int Helper_ReturnVms(IVirtualBox *virtualBox) { HRESULT rc; bool bFound=false; /* * First we have to get a list of all registered VMs */ SAFEARRAY *machinesArray = NULL; rc = virtualBox->get_Machines(&machinesArray); if(FAILED(rc)) { SafeArrayDestroy (machinesArray); return -1; } IMachine **machines; rc = SafeArrayAccessData (machinesArray, (void **) &machines); if(FAILED(rc)) { SafeArrayUnaccessData (machinesArray); SafeArrayDestroy (machinesArray); return -1; } for

Continue Reading →

Static analysis of C/C++ code using cppcheck

Download cppcheck from here: http://cppcheck.sourceforge.net/ some of the things you can find out by running cppcheck on your code is: 1) Summary: Possible inefficient checking for ‘idList’ emptiness. Message: Checking for ‘idList’ emptiness might be inefficient. Using idList.empty() instead of idList.size() can be faster. idList.size() can take linear time but idList.empty() is guaranteed to take

Continue Reading →

difference between lua find and c++ find

Lua: string.find(“testthis”, 5,5,7) this is going to give you “th”. Meaning it will start from the 5th letter and give the next letters between 5 and 7. C++ / C string str=”testthis” str.find(5,5); this will start from the fifth element and give you the next 5 letters. Basically in lua, it gives the letters between

Continue Reading →

loading C++ libs in linux with Qt

1) Create ur qt project. 2) include all the header files in your project. 3) Use appropriate namespaces 4) Important part: linking against your libraries In your .pro file, use : LIBS += -L”/home/test/Desktop/test-build-desktop/” -lLibrary1 -lLibrary2 Here library1 and 2 are the names of the libraries i link against. 5) Now from the command prompt

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 →

Hacking into DLLs [ COM ]

This is especially useful when you want to use someone else’s dlls. 1) Open the dll in windows dependency viewer: You should see the following, if its a COM dll. This basically is related to COM. If you go through COM tutorials you will know about this. 1)  next open the dll you need in

Continue Reading →

Replace switch statement by function pointers

//———————————————————————————— // 1.2 Introductory Example or How to Replace a Switch-Statement // Task: Perform one of the four basic arithmetic operations specified by the // characters ‘+’, ‘-‘, ‘*’ or ‘/’. // The four arithmetic operations … one of these functions is selected // at runtime with a switch or a function pointer float Plus

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 →

Compiler Error C2733 – second C linkage of overloaded function 'function' not allowed

I got this from http://stefanobolli.blogspot.com/2010/10/compiler-error-c2733-second-c-linkage.html Compiler Error C2733 – second C linkage of overloaded function ‘function’ not allowed If we try to compile with Microsoft Visual C++ 2010 Express a project that includes old Microsoft Platform SDK headers and against old libraries, we have to modify Additional include Directories and Additional library Directories. When we

Continue Reading →

Using extern in C++

Easiest way to add global variables inside a C++ program is use extern. First add this in the header file: extern string globalVar; Then add the the same variable inside the cpp file you are using but u need to remove the extern. string globalVar; In this way your able to pass around the variable

Continue Reading →

Making a .sis file for Nokia [download makesis and Comdlg32.ocx]

The easiest way to create a .sis file would be to use the tool makesis. You can download the tool from here: http://www.kmdarshan.com/makesis/Makesis_v1.0_by_Gip.rar http://www.kmdarshan.com/makesis/Makesis_v1.0.zip Also you would need to download this dll, and put it in your C:WindowsSystem32 for this tool to work. you can download the dll here: http://www.kmdarshan.com/makesis/Comdlg32.zip good luck packaging.

Continue Reading →

Using Qtimer instead of Sleep

Sample code to use Qtimer in Qt instead of Sleep if you want a stoppage in your code: slideShowtimer = new QTimer(this); selectedPicture = 0; //QTimer::singleShot(5000, this, SLOT(slideShowHelper())); connect(slideShowtimer, SIGNAL(timeout()), this, SLOT(slideShowHelper())); slideShowtimer->start(1000);

Continue Reading →

Implementing simple multithreading in C++

Bare steps to implement multi threading in C++: a. Declare a global variable, to hold the reference counts. b. Declare CRITICAL SECTION code: CRITICAL_SECTION cs_test; int loadCnt=0; c. Now everytime you access the code you want to be protected when multiple threads access them InitializeCriticalSection(&cs_test); EnterCriticalSection(&cs_test); if(loadCnt >0) { loadCnt++; return }else{ //your code here

Continue Reading →

Windows developer tools you need to have

Some tools which I really find helpful are: a. Multimon – Support for multiple monitors b. Process Monitor c. Process Explorer d. Desktops – Desktops allows you to organize your applications on up to four virtual desktops. e. OleView – For COM purposes f. Spy++ – For windows GUI handling g. Resource hunter – Reading

Continue Reading →

Tip 1: Optimize code to run faster

1. Use constants with reference when passing values in between methods. Advantage: It will reduce space and will be faster. If you use a new variable then an additional copy is made and there is a small memory hit. Ex: method(string val) optimal usage: method(const string &val) Here we are passing the value by reference.

Continue Reading →

ACL: Denying read access to a file in VC++

Snippet of the code to set the permissions and create a file while not granting read access to it: DWORD dwRes; PSID pEveryoneSID = NULL, pAdminSID = NULL; PACL pACL = NULL; PSECURITY_DESCRIPTOR pSD = NULL; EXPLICIT_ACCESS ea[2]; SID_IDENTIFIER_AUTHORITY SIDAuthWorld = SECURITY_WORLD_SID_AUTHORITY; SID_IDENTIFIER_AUTHORITY SIDAuthNT = SECURITY_NT_AUTHORITY; SECURITY_ATTRIBUTES sa; // Create a well-known SID for the

Continue Reading →