question

MrutyunjayaMahapatra-6181 avatar image
0 Votes"
MrutyunjayaMahapatra-6181 asked RLWA32-6355 commented

IUnknow base vptr meory is getting lost

I have one project where I am creating one COM component. I am trying to get pointer to interface which is derived from IUnknown and After 10/15 mins of getting pointer to interface, Base interface (Iunknown ) Vptr memory locations are getting lost/


class ATL_NO_VTABLE CIndustrial_IT_HistoryHandler :
public CClientHelper,
public CComCoClass<CIndustrial_IT_HistoryHandler, &CLSID_Industrial_IT_HistoryHandler>,
public IIndustrial_IT_HistoryHandler,
public IConnectionPointContainerImpl<CIndustrial_IT_HistoryHandler>,
public CProxy_IIndustrial_IT_HistoryHandlerEvents<CIndustrial_IT_HistoryHandler>
{
.....

}

I am trying to get pointer to IIndustrial_IT_HistoryHandler which is derived from IUnknown . After 10/15 mins Iunknown vptr memory locations, means vptr[0], vptr[1], vptr[2] memory locations are getting lost


Can anybody please suggest How can I track in runtime how is it getting lost ?

windows-apiwindows-platform-network
· 6
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Its not clear what you are trying to do or what you mean by "Vptr memory locations are getting lost".

Are you calling QueryInterface to obtain the desired interface pointer?

0 Votes 0 ·

And could you please show a minimal, reproducible sample without private information ?

0 Votes 0 ·

Component Class
class ATL_NO_VTABLE CIndustrial_IT_HistoryHandler :
public CClientHelper,
public CComCoClass<CIndustrial_IT_HistoryHandler, &CLSID_Industrial_IT_HistoryHandler>,
public IIndustrial_IT_HistoryHandler,
public IConnectionPointContainerImpl<CIndustrial_IT_HistoryHandler>,
public CProxy_IIndustrial_IT_HistoryHandlerEvents<CIndustrial_IT_HistoryHandler>
{
.....

}

IDL File

interface IIndustrial_IT_HistoryHandler : IUnknown
{
}

Creating Instance :

CComPtr<IIndustrial_IT_HistoryHandler> pHistHdlr;
pHistHdlr.CoCreateInstance(CLSID_Industrial_IT_HistoryHandler)


After 10/15 base IUnknown pointers are getting lost..



0 Votes 0 ·
XiaopoYang-MSFT avatar image XiaopoYang-MSFT MrutyunjayaMahapatra-6181 ·

With this snippet, I am afraid I cannot reproduce your problem and understand what do the words After 10/15 mean. Could you please show a minimal, sound sample without private information ?

0 Votes 0 ·
Show more comments
MrutyunjayaMahapatra-6181 avatar image
0 Votes"
MrutyunjayaMahapatra-6181 answered

This is during initialization...

99116-untitled.png


After 10/15 mins / Crash..
99057-untitled1.png



untitled.png (73.4 KiB)
untitled1.png (66.6 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

RLWA32-6355 avatar image
0 Votes"
RLWA32-6355 answered RLWA32-6355 commented

The posted images indicate that hsHistSvcInterfaces.dll has been unloaded. That would be the source of your "missing" vptr entries. You need to debug some more to find out why this problem has occurred.

Update:
It also seems wrong that before the dll is unloaded the IUnknown vtable entries point to hsHistSvcInterfaces!DllUnregisterServer instead of to QueryInterface, AddRef and Release.

99110-vptr.png



vptr.png (18.9 KiB)
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi, Yes hsHistSvcInterfaces.dll was getting unloaded. I fixed by changing


 HRESULT hr = PrxDllCanUnloadNow();
 if (FAILED(hr))
     return hr;


to:

 HRESULT hr = PrxDllCanUnloadNow();
 if (hr != S_OK)
     return hr;


May I know what could be the reason of (FAILED(hr)) which was failing to validate hr value S_FALSE returned by PrxDllCanUnloadNow().

0 Votes 0 ·
RLWA32-6355 avatar image RLWA32-6355 MrutyunjayaMahapatra-6181 ·
  HRESULT hr = PrxDllCanUnloadNow();
  if (FAILED(hr))
      return hr;

The above code is incorrect and has been changed from the code that is generated by the ATL project template when the merge proxy/stub option has been selected. The default code is

 // Used to determine whether the DLL can be unloaded by OLE.
 _Use_decl_annotations_
 STDAPI DllCanUnloadNow(void)
 {
 #ifdef _MERGE_PROXYSTUB
     HRESULT hr = PrxDllCanUnloadNow();
     if (hr != S_OK)
         return hr;
 #endif
     return _AtlModule.DllCanUnloadNow();
 }

Additionally note that DllCanUnloadNow should not return anything other than S_OK or S_FALSE. Both of these are success codes that will not be treated as errors by the FAIL macro. Refer to the docs for this function at DllCanUnloadNow function


0 Votes 0 ·