ATL 9.0 displayed in the middle of an Activex control

Recently a customer of mine faced this issue. So he had an ActiveX control and when displaying the ActiveX control in browser a string is displayed right in the middle of the control: “ATL 9.0”. So this issue happens because you didn’t override CComControlBase::OnDraw  function. The default code for CComControlBase::OnDraw looks like the following… [sourcecode language=”cpp”]HRESULT CComControlBase::YourClassName::OnDraw(_In_ ATL_DRAWINFO& […]
Continue reading…

 

Set resource handle in MFC and ATL

When working in MFC/ATL and then using a resource dll can at times cause bugs because resource handle is not properly set. For e.g. if you have a dialog resource in a dll and you instantiate a CDialog which results in an error because resource cannot be located in this application or dll since it’s in […]
Continue reading…

 

How to convert ANSI string to UNICODE string and vice versa?

Well quite simple,  but still quite frequently asked in forums… 🙂 There are two macros that does this for us. They are as follows. Note: You must include atlconv.h A2W – ANSI to UNICODE W2A – UNICODE to ANSI Before using these two macros you have to use this macro too… USES_CONVERSION Here is a […]
Continue reading…

 

Dynamically determining the base class of a class using templates

Well nearly dynamically! When working on the ATL COM framework I came across a piece of framework code which makes a template parameter as the base class of a class which looked quite useful to me. Here is a demo… [sourcecode language=’cpp’]template class SomeWnd : public BaseClass {     public: LRESULT WindowProc(UINT uMessage, WPARAM wParam, […]
Continue reading…

 

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…

 

MIDL “string” attribute

Sometime back I was wondering about whether there was a way to transfer our good ol’ NULL terminated strings using COM apart from using BSTR’s. That’s how I bumped into “string” attribute provided by MIDL. Here is how we use it… [sourcecode language=’cpp’]typedef [string] char NormalString[1024]; [id(1), helpstring( “Displays null terminated UNICODE strings” )] HRESULT […]
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…