Sharing variable between instances of COM object?
-
I need to share values between two instances of a COM object. In most of the C++ COM examples I've read, an
extern UINT g_DllLockCount
is declared in stdafx.h and used to maintain a count of references to the Dll.DllCanUnloadNow()
then uses this to determine if the Dll can be unloaded. I've tried adding anextern BSTR g_bString
to the stdafx.h, and modifyingDllCanUnloadNow()
to returnS_FALSE
ifg_bString
isn'tNULL
. I've added three functions to the COM Server - one to set a string value, one to retreive the string value, and one to set the value toNULL
so the Dll can unload. In my test app, I created the COM object and gave the string a value, destroyed the COM object, created another COM object, retreived the string value, then set the string toNULL
so the Dll can unload. The value retreived is the initialized value ofg_bString
, rather than the one I set. My questions now, are: (1) Is what I'm trying to do even possible with COM ? (2) Is the method outlined above correct, and it's most likely an implementation issue, or is the method itself flawed? Any information or suggested reading ya'll can provide would be greatly appreciated. MZR -
I need to share values between two instances of a COM object. In most of the C++ COM examples I've read, an
extern UINT g_DllLockCount
is declared in stdafx.h and used to maintain a count of references to the Dll.DllCanUnloadNow()
then uses this to determine if the Dll can be unloaded. I've tried adding anextern BSTR g_bString
to the stdafx.h, and modifyingDllCanUnloadNow()
to returnS_FALSE
ifg_bString
isn'tNULL
. I've added three functions to the COM Server - one to set a string value, one to retreive the string value, and one to set the value toNULL
so the Dll can unload. In my test app, I created the COM object and gave the string a value, destroyed the COM object, created another COM object, retreived the string value, then set the string toNULL
so the Dll can unload. The value retreived is the initialized value ofg_bString
, rather than the one I set. My questions now, are: (1) Is what I'm trying to do even possible with COM ? (2) Is the method outlined above correct, and it's most likely an implementation issue, or is the method itself flawed? Any information or suggested reading ya'll can provide would be greatly appreciated. MZR -
you can use share memory when sharing data between EXE and COM or between COM and COM: CreateFileMapping OpenFileMapping MapViewOfFile
Looks like I've got some serious reading to do... Thanks for pointing the way, frx96!