How can the caller's process be identified in an ATL COM+ out-of-proc server application?
Asked Answered
M

1

2

I have an ATL service running as an out-of-proc server that has several COM classes that the clients are expected to be using. Because of a change in requirements, I need to be able to identify which process owns which instances of the objects. I'm trying to use some of the COM functions to find out this information but I can't find the right ones. CoGetCallContext only returns information about the user who called the method, not which process it came from. Same with CoQueryClientBlanket. What function can I use to find out this information?

Mia answered 1/3, 2016 at 16:53 Comment(3)
Determine the Process ID of the Client Process communicating with a COM RPC ServerCarborundum
Thanks @RomanR., I thought it might be here but I didn't see it before.Mia
You best bet is changing the interfaces so that when an object is being created the caller passes his id.Abshier
C
2

I know that I'm 6.5 years late but just answering this in case anyone in the future needed it.

So there's a way to do this.... but through a private built-in COM interface, which is ICallingProcessInfo

Interface definition:

MIDL_INTERFACE("68C6A1B9-DE39-42C3-8D28-BF40A5126541")
ICallingProcessInfo : public IUnknown
{
public:
    virtual STDMETHOD(OpenCallerProcessHandle)(DWORD dwDesiredAccess, HANDLE* handle) = 0;
};

Usage:

HANDLE handle;
ComPtr<ICallingProcessInfo> callingProcessInfo; // ComPtr is from WRL, you can use the interface directly instead
CoGetCallContext(__uuidof(ICallingProcessInfo), (void**)callingProcessInfo.GetAddressOf());
callingProcessInfo->OpenCallerProcessHandle(PROCESS_QUERY_LIMITED_INFORMATION, &handle);

I tested this on a WinRT OOP Server but since WinRT Servers are just COM Servers it should work with normal COM Servers too

Chromaticity answered 10/9, 2022 at 0:3 Comment(1)
Thanks! Although I've long since moved on from this project, hopefully it will be helpful to others in the future :-DMia

© 2022 - 2024 — McMap. All rights reserved.