Access violation error using smart pointer stored in GIT

Tech-Archive recommends: Speed Up your PC by fixing your registry



Hello,

I am getting the access violation error while trying to access a smart
pointer stored in GIT. I have a simple configuration class, that
registers a pointer in Global Interface Table in the constructor as
follow:

CConfig::CConfig()
{
// COM smart interface pointer
_CommunicationPtr pConfig;
HRESULT hRes = pConfig.CreateInstance(__uuidof(Communication));
_ASSERT(SUCCEEDED(hRes));

_id = pConfig.GetIID();

// create Global Interface Table(GIT)
hRes = CoCreateInstance(CLSID_StdGlobalInterfaceTable,
NULL,
CLSCTX_INPROC_SERVER,
IID_IGlobalInterfaceTable, (LPVOID*)&_pGIT);
_ASSERT(SUCCEEDED(hRes) && _pGIT);

// store interface in GIT
hRes = _pGIT->RegisterInterfaceInGlobal(
pConfig.GetInterfacePtr(),
_id,
&_gdwCookie);
_ASSERT(SUCCEEDED(hRes));

pConfig = NULL;
}

When in the method I retreive this pointer from GIT and try to use it.
That is where I am getting "Access violation" error.

char *CConfig::CustomerID(void)
{
CoInitialize(NULL);

// COM smart interface pointer
_CommunicationPtr *pConfig = NULL;

// get proxy to interface from GIT
HRESULT hRes = _pGIT->GetInterfaceFromGlobal(_gdwCookie,
_id,
(LPVOID*)&pConfig);

_ASSERT(SUCCEEDED(hRes) && pConfig);

char* value = NULL;

// THIS IS WHERE ERROR OCCURS
value = (*pConfig)->CustomerID;

pConfig = NULL;
CoUninitialize();

return value;
}

Please advice.

Thanks in advance,

Alex.

.



Relevant Pages

  • Re: RPC_E_WRONG_THREAD on accessing interface pointer from GIT
    ... The thread that gets the interface (allow me to call it ... IObjectInterface pointer is retrieved from the GIT from another COM ... successfully retrieve the pointer to the other object from the GIT, ...
    (microsoft.public.win32.programmer.ole)
  • Re: Access violation error using smart pointer stored in GIT
    ... You don't store smart pointers in GIT (you can't as it's a COM ... interface so you can only pass COM types, ... a smart pointer again, see Kim's post. ...
    (microsoft.public.vc.atl)
  • Re: Global interface table release issue
    ... You obtain IGlobalInterfaceTable pointer with CoCreateInstance. ... CoCreateInstance to obtain an interface pointer (GIT or otherwise), ...
    (microsoft.public.vc.language)
  • Re: C# DLL mittels COM-Interop aus C aufrufen
    ... Have u tried the IDispatch interface, which is used for those language ... which doesnot have capability of maintaining VTables. ... The __cplusplus symbol is defined automatically when you're compiling C ... appropriate function pointer type. ...
    (microsoft.public.de.german.entwickler.dotnet.csharp)
  • Re: Pointers in derived types, help needed
    ... subroutine/function must have an explicit interface. ... C is not a pointer. ... then probably the best thing to do is use allocatables. ...
    (comp.lang.fortran)