I am not so familiar with the Microsoft COM Technology. In a nutshell I have an Microsoft Out-of-process COM Server that is implemented in the executable file foo.exe
. The environment is C++ and the Microsoft Foundation Classes Framework (MFC).
There is a client bar.exe
which uses functionality within foo.exe over the Microsoft COM Technology. Within foo.exe there are some Dynamic Link Libraries involved which uses also functionality provided by the COM Server foo.exe (for example fooBar.dll
).
So far so good. I am on the road of searching a way to determine if the client of the COM Server foo.exe is in an other process or even within the same process as foo.exe such as fooBar.dll in the example above. Does anyone knows such a way?
Edit:
With other words: Obvious the COM Server foo.exe
can act as an in-process or an out-of-process COM Server. To add up to the comment of Hans Passant and the answer of Joe Willcoxson who is proposing to address the calling DLL via GetModuleHandle
to determine if the COM Server acts currently as in-process Server, in case when I got the handle and in case when I not got the handle as out-of-process Server. So it seams that when the COM Server is aware of well-known DLLs which uses functionality from that server within the same process, we could say that the COM Server acts in this moment as in-process Server and in other case as out-of-process Server. Do I misunderstand something or are these considerations correct?
My investigations for the moment are not mentionable so I hoping there is a Microsoft COM Expert in the community who knows how the barrow runs.
Thank you very much for help!
Within the COM Server foo.exe
you can do following.
CTheApp::InitInstance()
{
[...]
bool runAsOutOfProcessServer = false;
CCommandLineInfo commandInfo;
ParseCommandLine(commandInfo);
if(commandInfo.m_bRunEmbedded || commandInfo.m_bRunAutomated)
{
runAsOutOfProcessServer = true;
}
[...]
if(runAsOUtOfProcessServer)
AfxMessageBox("Out of Process Invocation");
}
Obvious there are two members in CCommandLineInfo which indicates that the process is started up as OLE Automation Server or started up to edit an embedded OLE item. With ParseCommandLine you got the information over call by reference to the local variable commandInfo
. Then you can check if the members m_bRunEmbedded
or m_bRunAutomated
are set to determine if the COM Server within foo.exe
is started up. Then at the end you can pop up your message box only if the local variable runAsOutOfProcessServer
is true.