Category Archives: COM

Running Object Table leads to memory leak

“When an object is registered, the ROT always calls AddRef on the object.”, but IRunningObjectTable::Revoke will not call Release method of registered object if there is client using the object, so later when all clients released its reference, the COM … Continue reading

Posted in COM | Leave a comment

Changing the Startup type and description of VC++ 2008 service project

#include <stdio.h>#include <sstream>#include <xutility>#include <exception>#include <iomanip>typedef std::basic_stringstream<TCHAR> tsstream;typedef std::basic_string<TCHAR> tstring;#ifdef _UNICODE#define __FUNCTIONT__ __FUNCTIONW__#else#define __FUNCTIONT__ __FUNCTION__#endif class COzSvcModule : public CAtlServiceModuleT< COzSvcModule, IDS_SERVICENAME >{public :    DECLARE_LIBID(LIBID_OzSvcLib)    DECLARE_REGISTRY_APPID_RESOURCEID(IDR_OZSVC, "{08E6E609-0FBD-4098-8006-D703FCEB8C17}")    HRESULT InitializeSecurity() throw()    {        // TODO : Call CoInitializeSecurity and provide the appropriate … Continue reading

Posted in COM | Leave a comment

dynamic_cast with COM interface pointer

When I use c cast to get a pointer to an implementation class of an interface and call its method, it reports access violation upon the entry of the method, even if the method only contains one line: "return S_OK". … Continue reading

Posted in COM | Leave a comment

ROT and typelib

If typelib is not properly registered, a COM object can be registered to ROT, but subsequent GetObject would fail with error : "Invalid Pointer". It is valid to have two typelib in one executable, but the registeration has to be … Continue reading

Posted in COM | Leave a comment

RPC_E_CANTCALLOUT_ININPUTSYNCCALL Error with Out-of-Proc COM Server

Steps to reproduce: Create an out-of-proc COM server, add one method STDMETHODIMP ExeMsg::Test(long process_id, long thread_id){    std::stringstream ss;    ss  << "ExeMsg::Test() Called from process " << process_id        << " caller thread " << thread_id        << " callee process " << … Continue reading

Posted in COM | Leave a comment

Purify reports memory leak in UpdateRegistryFromResource method

Rational Purify reported memory leak in UpdateRegistryFromResource method, which is introduced by DECLARE_REGISTRY_RESOURCEID(…) macro. After I rebuilt with _ATL_STATIC_REGISTRY enabled, Rational Purify is happy.

Posted in COM | Leave a comment

Wrapper class for using UDT (User Defined Type) in COM

UDTs must be freed by caller, just like BSTR. So I created a template to ease the work of caller.template <typename UDT >class UDTWrapper : public UDT{public: UDTWrapper() { HRESULT hr = S_OK; CComPtr<ITypeLib> pTypelib; CComPtr<ITypeInfo> pTypeInfo; hr = LoadRegTypeLib(lib_id, … Continue reading

Posted in COM | Leave a comment

COM Client Method Call Fails with ERROR_NOACCESS(0xC0000005)

I encountered this problem in recent project development. It is very likely to be the same problem as documented in MSDN Q273721. Only one method failed, because it contains a parameter of IUnknown*. Another related KB article may be Q149231 … Continue reading

Posted in COM | Leave a comment

Share COM objects between threads/processes

The CoCreateFreeThreadedMarshaler function enables an object to efficiently marshal interface pointers between threads in the same process. The IGlobalInterfaceTable interface is an efficient way for a process to store an interface pointer in a memory location that can be accessed … Continue reading

Posted in COM | Leave a comment

Add ATL object to existing MFC SDI project

I met the following mistakes:missing [out] specifier in IDL file, so the method can’t be called by vbscript;messing up CLSID and LIBID.AfxGetApp() and AfxGetMainWnd() return NULL — workaround is to use theApp object, store HWND as a member of theApp … Continue reading

Posted in COM | 1 Comment