The call to get_HWND is just fine and it randomly fails as the instance being killed. Why?
The call to CoCreateInstance with CLSID_InternetExplorer will instantiate a process with low integrity level. If the URL you navigate to is bound to a low integrity level (true for internet sites) there will be no problem. On the other hand, if you navigate to a URL that is bound to medium integrity level (true for intranet/trusted sites), then your process will be killed and a new process with medium integrity level will be created (seamlessly in IE8 and up). This operation is called a “Virtual Tab switch.”
For more information about the problem and how to solve it:
http://blogs.msdn.com/b/ieinternals/archive/2011/08/03/internet-explorer-automation-protected-mode-lcie-default-integrity-level-medium.aspx
http://msdn.microsoft.com/en-us/library/aa752084%28v=vs.85%29.aspx
Windows Internet Explorer 8. On Windows Vista, to create an instance
of Internet Explorer running at a medium integrity level, pass
CLSID_InternetExplorerMedium (defined in exdisp.idl) to
CoCreateInstance. The resulting InternetExplorerMedium object supports
the same events, methods, and properties as the InternetExplorer
object.
You probably want to verify this is indeed the issues you are facing. Here is how to run a quick test:
- Open IE
- Go to settings
- Security tab
- Local intranet
- Click the "Sites" button
- Uncheck “automatically detect intranet network”
That should suppress the Virtual Tab switch

Here is an additional info about Protected Mode (taken from the book Pro Internet Explorer 8 & 9 Development: Developing Powerful Applications for the Next Generation of IE by Matthew Crowley):
Windows Vista introduced the concept of MICs, which use integrity
levels (ILs) to differentiate filesystem objects, registry locations,
and APIs by trust and privilege levels and User Account Control (UAC)
to funnel elevation requests to users. This architecture helps to
protect system and user files against malicious access by untrusted
applications.
The integrity levels present on Windows Vista and higher fall into
four major categories:
System: Core operating system (NTAUTHORITY); system components, files, and data
High: Machine-level access (administrators); program files and local machine registry hive
Medium: User-level access (users); user files and settings and current user registry hive
Low: Untrusted content, temporary files, and data