www.digitalmars.com         C & C++   DMDScript  

D - DMD 0.79 com server and template problems - comserver.zip

I noticed that the sample self registering inprocess com server dll example had
a strange behaviour :
when the dll is unloaded (not sure why CoFreeLibrary was called and no
FreeLibrary) the console IO also stopped.
this can be solved by keeping the dll loaded until the app exits, this I assume
is due to the runtime lib shutdown code closing stdin/out/err
which my be an indiccator that there are other issues with dll's written in D
(apart from the multipul GC's that will be running [not nec a bad thing])


also I tried to use the template T(alias A) syntax to ease calling
CoCreateInstance

template ComCreate(alias clz_guid, alias if_guid, IFACE ) {
IFACE newInstance() {
HRESULT hr;
IFACE   obj;
hr = CoCreateInstance( &clz_guid, null, CLSCTX_ALL, &if_guid, &obj );
if ( FAILED( hr ) )
{
throw new Exception( "unable to create new instance" );
}
return obj;
}
}

called with 
pIHello = ComCreate!(CLSID_Hello, IID_IHello, IHello).newInstance();

this however gives the error 
OPTLINK (R) for Win32  Release 7.50B1
Copyright (C) Digital Mars 1989 - 2001  All Rights Reserved

dclient.obj(dclient)
Error 42: Symbol Undefined _D7dclient10IID_IHelloS3std1c7windows3com4GUID
dclient.obj(dclient)
Error 42: Symbol Undefined _D7dclient11CLSID_HelloS3std1c7windows3com4GUID
--- errorlevel 2

is this a problem with the compiler or with my code ?

the work around was to do

template ComCreate( IFACE ) {
IFACE newInstance(GUID * clz_guid, GUID * if_guid ) {
HRESULT hr;
IFACE   obj;
hr = CoCreateInstance( clz_guid, null, CLSCTX_ALL, if_guid, &obj );
if ( FAILED( hr ) )
{
throw new Exception( "unable to create new instance" );
}
return obj;
}
}

pIHello = ComCreate!(IHello).newInstance(&CLSID_Hello, &IID_IHello);
Feb 11 2004