client.cpp

来自「经验交流,从网上下载的好东西望大家分享」· C++ 代码 · 共 42 行

CPP
42
字号
// client.cpp
#define _WIN32_DCOM
#include <iostream.h>
#include "Component\component.h"

void main()
{
	cout << "Client: Calling CoInitialize()" << endl;
	CoInitialize(NULL);
		
	// Always need a bind context
	IBindCtx* pBindCtx;
	CreateBindCtx(0, &pBindCtx);

	// Convert the string to a moniker
	ULONG eaten;
	IMoniker* pMoniker;
	OLECHAR string[] = L"clsid:10000013-0000-0000-0000-000000000001";
	MkParseDisplayName(pBindCtx, string, &eaten, &pMoniker);

	// Bind the moniker to the named object
	IPrimeFactory* pPrimeFactory;
	pMoniker->BindToObject(pBindCtx, NULL, IID_IPrimeFactory, (void**)&pPrimeFactory);

	// Use the custom class object to create a Prime object
	IPrime* pPrime;
	pPrimeFactory->CreatePrime(7, &pPrime);

	// Now we have a Prime object
	int next_prime;
	pPrime->GetNextPrime(&next_prime);
	cout << next_prime << endl; // Displays 11

	// Release all
	pPrimeFactory->Release();
	pPrime->Release();
	pBindCtx->Release();
	pMoniker->Release();

	cout << "Client: Calling CoUninitialize()" << endl;
	CoUninitialize();
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?