from
http://progtutorials.tripod.com/COM.htm
- Configuring a Server to be Invoked Remotely
- Authentication Level
- Security
- Server Identify
- Configuring a Client to Call Remote Server
1 Configuring a Server to be Invoked Remotely
There are three major issues to configure for a server to be invoked remotely. The first two can be configured machine-wide, so that you decide the settings for the machine, and all servers which has not been specifically configured take the machine-wide settings. All these things can be done through dcomcnfg.exe.
1.1 Authentication Level
Determines how often and how strict does the COM run time check for the server the identification of the client.
1.2 Security
Includes Access Permission, Launch Permission and Configuration Permission. Each server has an AppID to store server-wide attributes. In System Registry, each AppID has a Access Control List (ACL), which lists which client has which permssion.
1.3 Server Identify
A server is launched with an user account identity. It has three options:
- The Interactive User: all servers in a machine are launched with the identity of the person who is logged on to this machine. This is only used in debugging session when you want the server to display some GUI such as a message box. If you do not choose this option the server can not display any GUI on the machine and will appear pending.
- The Launching User: the server always has the identify of the person who launched it. As a side effect, the SCM will launch a new instance of the server for each client.
- This User: proper for production application. You select one or a group of users as the identity of the server.
2 Configuring a Client to Call Remote Server
The server should be registered on the client machine. You can configure the client to call remote server with dcomcnfg.exe. Choose a server and double-click it to bring up the properties of the server. In the "Location" tab, choose correct option. You can tick either or both of the options: "Run application on this computer" or "Ran application on the following computer", and enter the name of the remote computer. If you choose both, the SCM will choose the nearest one. The name of the computer will be assigned to a new entry RemoteServerName under HKCR\AppID. When SCM sees this entry, it knows that it's going remote.
You can also configure a client through function CoCreateInstanceEx. It will suppress the dcomcnfg.exe settings:
COSERVERINFO serverInfo = {0};
serverInfo.pwszName = L"FLIU";
MULTI_QI interfaces[2] = {0};
interfaces[0].pIID = &IID_IFirst;
interfaces[1}.pIID = &IID_ISecond;
CoCreateInstanceEx(
CLSID_MyClass,
NULL,
CLSCTX_REMOTE_SERVER,
&serverInfo,
2, // Size of the MULTI_QI array
interfaces);
if(FAILED(interfaces[0].hr))
{
::MessageBox(NULL, "Query for IID_IFirst failed!", "Client", MB_OK);
return;
}
else if(FAILED(interfaces[1].hr))
{
::MessageBox(NULL, "Query for IID_IFirst failed!", "Client", MB_OK);
return;
}
IFirst * pf = (IFirst *)interfaces[0].pItf;
ISecond * ps = (ISecond *)interfaces[1].pItf;
... To be able to call the DOM functions in COM library such as CoInitialize, CoInitializeEx or CoCreateInstanceEx, you should put the following line before including <windows.h> or in the project-wide #define settings:
#define _WIN32_DCOM
Function CoCreateInstanceEx uses two structures:
WINOLEAPI CoCreateInstanceEx(
REFCLSID Clsid,
IUnknown * punkOuter, // only relevant locally. Normally NULL
DWORD dwClsCtx, // CLSCTX
COSERVERINFO * pServerInfo, // contains server computer name
DWORD dwCount, // size of MULTI_QI array
MULTI_QI * pResults ); // array of MULTI_QI
Structure COSERVERINFO holds the server computer name:
typedef struct _COSERVERINFO
{
DWORD dwReserved1;
LPWSTR pwszName;
COAUTHINFO __RPC_FAR *pAuthInfo;
DWORD dwReserved2;
} COSERVERINFO; The array of structure MULTI_QI hold the IIDs of the wanted interfaces, the returned IUnknown pointers and HRESULTs:
typedef struct tagMULTI_QI
{
const IID __RPC_FAR *pIID;
IUnknown __RPC_FAR *pItf;
HRESULT hr;
} MULTI_QI;
SeriousMoin v1 (koMoinMoin 1.0a4 Modified)