typedef struct _COSERVERINFOThe code of the Instantiate function will be the following:
{
DWORD dwReserved1;
LPWSTR pwszName; //Pointer to the name of the machine to be used.
COAUTHINFO *pAuthInfo; // for the default security package (NTLMSSP) set it to NULL. For more details see Microsoft® documentation.
DWORD dwReserved2;
} COSERVERINFO;
IOPCServer* InstantiateServer(wchar_t szCLSID_OPCServer[]) // szCLSID_OPCServer has to be of the form:You need to define REMOTE_SERVER_NAME:
{ // L"{12345678-1234-1234-123456789ABC}"
CLSID CLSID_OPCServer;
HRESULT hr;// get the CLSID from the OPC Server Name:
hr = CLSIDFromString(szCLSID_OPCServer, &CLSID_OPCServer);
_ASSERT(!FAILED(hr));
//queue of the class instances to create
LONG cmq = 1; // nbr of class instance to create.
MULTI_QI queue[1] =
{{&IID_OPCServer,
NULL,
0}};//Server info:
COSERVERINFO CoServerInfo =
{
/*dwReserved1*/ 0,
/*pwszName*/ REMOTE_SERVER_NAME,
/*COAUTHINFO*/ NULL,
/*dwReserved2*/ 0
};// create an instance of the IOPCServer
hr = CoCreateInstanceEx(CLSID_OPCServer, NULL, CLSCTX_SERVER,
&CoServerInfo, cmq, queue);
_ASSERT(!hr);// return a pointer to the IOPCServer interface:
return(IOPCServer*) queue[0].pItf;
}
#define REMOTE_SERVER_NAME L"your path"Because the name of the server will not be present in the Windows registry, the string to give in parameter to the Instantiate function has to be the CLSID of the Server formated as following:
L"{12345678-1234-1234-123456789ABC}"Remark that the same function, CLSIDFromString is used to convert the server name to CLSID or the CLSID in string form to the CLSID in the form of a structure.