rename_namespace ( #import )

When importing a type library it could be at times cumbersome to use the default namespace name. #import provides a nice option called rename_namespace. Use… [sourcecode language=’cpp’]#import “SomeTypelib.tlb” rename_namespace( “NibuNamespace” )[/sourcecode] Using no_namespace is lazy programming 😐 . Namespaces reduces name collision hence usage should be encouraged.
Continue reading…

 

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…

 

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…