Using CComCreator

Easiest way to construct a COM interface from it’s co class. [sourcecode language=’cpp’]ISomeInterfacePtr sipPtr; HRESULT hRes = CComCreator< CComObject< CSomeCoClass > >::CreateInstance( 0, IID_ISomeInterface, reinterpret_cast( void**,¬†&sipPtr )); ASSERT( SUCCEEDED( hRes ));[/sourcecode] Must be an ATL/COM Project.
Continue reading…

 

Enable/Disable XP Visual Styles for your application

Via resource editor For VC6 add this one line to your .rc file, open it in a text editor…. CREATEPROCESS_MANIFEST_RESOURCE_ID RT_MANIFEST “YourAppName.exe.manifest” YourAppName.exe.manifest should be your application’s manifest file. Or you can paste YourAppName.exe.manifest to your application folder and XP themes gets enabled. From VC8 onwards manifest file should only be in your res folder, […]
Continue reading…

 

Type of Exe(Console, Windows, MS-DOS application).

How to find out the type of an executable file, i.e. whether it’s a windows application or a console application or an MS-DOS application… [sourcecode language=’cpp’]void¬†GetFileType( LPCTSTR lpctszFilePath_i, CString& csFileType_o ) { ¬†¬†¬† // Get exe file type ¬†¬†¬† const DWORD dwRetVal = SHGetFileInfo( lpctszFilePath_i, ¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬† FILE_ATTRIBUTE_NORMAL, ¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬† 0, ¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬† 0, ¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬† SHGFI_EXETYPE ); ¬†¬†¬† […]
Continue reading…

 

Extracting version information of modules!

Use GetFileVersionInfoSize, GetFileVersionInfo and VerQueryValue. [sourcecode language=’cpp’]DWORD dwHandle = 0; // Get version size const DWORD dwSize = GetFileVersionInfoSize( lptszFileName, &dwHandle ); // Is size valid if( !dwSize ) { ¬†¬†¬†¬†return false; } // Allocate version data buffer PUCHAR* pVersionData = new UCHAR[ dwSize ]; if( !pVersionData ) { ¬†¬†¬† return false; } if( !GetFileVersionInfo( […]
Continue reading…

 

GetLastInputInfo

To know the tickcount of last input event¬†use GetLastInputInfo api. Here is a demo… [sourcecode language=’cpp’]// Prepare last input information structure LASTINPUTINFO lipInfo = { 0 }; lipInfo.cbSize = sizeof( LASTINPUTINFO ); // Sleep for one second Sleep( 1000 ); // Get¬†last input tick count GetLastInputInfo( &lipInfo ); // Milliseconds elapsed since last event const […]
Continue reading…

 

Creating SafeArray of bytes.

How to create a safearray of bytes… [sourcecode language=’cpp’]// An array having some data unsigned char ucBytes[2048];¬† //¬†Create ole safe array object¬† COleSafeArray cosaByteArray; // Copy bytes to safe array cosaByteArray.CreateOneDim( VT_UI1, sizeof( ucBytes ), ucBytes ); // Get safe array in variant form _variant_t vtByteArray = cosaByteArray.Detach();[/sourcecode]
Continue reading…

 

__declspec( novtable )

If a class is not meant to be intanstiated directly, using __declspec( novtable ) will help in reducing size of code generated for the class. MSDN says this: This form of _declspec can be applied to any class declaration, but should only be applied to pure interface classes, that is classes that will never be […]
Continue reading…