Re: marshalling
On Jan 29, 11:37 am, "Igor Tandetnik" <itandet...@mvps.org> wrote:
but why do i get an error then? When both processes run in apartment
thread it works, but when one is free threaded, I get error 0x800706F4
a null reference was passed to the stub (When passing IA1 to IA2)?
Show your code. Also show the IDL definition of the two interfaces.
--
//
// to position the structure cursor inside the aspect directory
//
bool CdpADO::bPositionCursor
(
/* in */ CComPtr<IAfwStructureCursor> &pCursor,
/* in */ const std::string &sPath
)
{
bool bOK = true;
HRESULT hr = S_OK;
ENTER( LogFile() );
try
{
LogFile().logInfo( __FUNCTION__ " - %s", sPath.c_str() );
long lCount = 0;
////////////////////////////////////////////////////////////
The following line fails (exception) if CoInitializeEx(NULL,
COINIT_MULTITHREADED ) is used but works if APARTMENT_THREADED
////////////////////////////////////////////////////////////
hr = pCursor->InitFromPathName( m_pObjManager,
CComBSTR(sPath.c_str()), NULL, &lCount );
if (FAILED(hr))
{
//-----------------------------
//// here we get, with hr=0x800706F4
//-----------------------------
LogFile().logInfo( __FUNCTION__ "::InitPathName returned hr=%X,
'%s'", hr, sPath.c_str() );
bOK = false;
}
<snipped rest>
}
//-----------------------------
// throws an exception if path(s) not found
//
void CdpADO::tryPositionCursor( CComPtr<IAfwStructureCursor>
&pCursor )
{
const string sRoot( "[Control Structure]IP800xA" );
const string sPath( "[Control Structure]IP800xA/LAB" );
// try finding lab folder, if that is not there we go for the root
folder
bool bPositioned = bPositionCursor( pCursor, sPath );
if ( !bPositioned ) // didn't find it, try root
{
bPositioned = bPositionCursor( pCursor, sRoot );
}
if ( !bPositioned )
{
throw internal_exceptions::path_invalid();
}
}
bool CdpADO::retrieveOracleInformation(oracleinfo_t &oracleInfo)
{
bool bOK = false;
try
{
CDescOpcError Desc;
HRESULT hr = E_FAIL;
CComPtr<IAfwStructureCursor> pCursor; // cursor to maneuver up the
parent chain
hr = pCursor.CoCreateInstance( L"ABB.AfwStructureCursor" );
if ( FAILED(hr) )
{
LogFile().logErr( "Failed creating cursor
retrieveOracleInformation, hr=0x%X, %s",
hr, Desc.getHrErrorText(hr) );
throw internal_exceptions::no_cursor();
}
// try finding right spot in aspect directory
tryPositionCursor( pCursor );
// position cursor in machines folder, look for oracle aspect, if
not found, go up one level until found
do // loop over all tree levels
{
<snipped>
}
while ( !bOK && SUCCEEDED(hr) );
pCursor.Release();
}
catch(const exception &ex)
{
}
catch(...)
{
}
return bOK;
}
//-----------------------------
code showing the connection to object manager
//-----------------------------
bool CdpADO::connectToObjectManager()
{
bool bOK = false;
HRESULT hr = E_FAIL;
try
{
const AfwSystemContextId* pSysCtxId = NULL; // connect to default
system
const AfwKeyId* pDataMode =NULL; // live data active
const BOOL displayDlg(FALSE); // no dialog if connection cannot
be established
const BOOL localThread(TRUE); // shallow version of object
manager - loads faster, less performance
hr =
m_pObjManager.Create(pSysCtxId,pDataMode,displayDlg,localThread);
}
catch(...)
{
...
}
return bOK;
}
//-----------------------------
m_pObjManager declared as
CComPtr<IAfwObjectManager> m_pObjManager;
These IDL-files a very large and protected by copyright so I can only
show small part - hopefully the right part.
...
#define AFW_INTERFACE_STATUS 1408E154-ABF5-43Af-A11E-8F8964C5BFC0
#define AFW_STATUS_COMMITTED "committed"
..
//----------------------------
/// IDL
//----------------------------
[
object,
uuid(E4FD44F8-C773-11D0-8094-93F1B82D8B1E),
helpstring("IAfwObjectManager Interface"),
custom(AFW_INTERFACE_STATUS,AFW_STATUS_COMMITTED),
pointer_default(unique)
]
interface IAfwObjectManager : IUnknown
{
snipped lots of methods
};
//----------------------------
the other, where the IAfwObjectManager ptr is passed to:
//----------------------------
[
object,
uuid(AA98459F-DE27-11D2-8F21-000000000000),
helpstring("IAfwStructureCursor Interface"),
custom(AFW_INTERFACE_STATUS,AFW_STATUS_COMMIT),
pointer_default(unique)
]
interface IAfwStructureCursor : IUnknown
{
...
HRESULT InitFromPathName(
[in] IAfwObjectManager* pObjMgr,
[in] const BSTR pathName,
[in] const AfwStructureId* pStructId,
[out, retval] long* pSNCount);
...
};
tia
Anders.