⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 weblogsping.cpp

📁 RPC ping linux remote procedure call
💻 CPP
字号:
// weblogsPing.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"

void sendPing(const wchar_t * weblogName, const wchar_t * weblogUrl);

int main(int argc, char* argv[])
{
	std::cout << "weblogs.com ping demo" << std::endl;

	CoInitialize(NULL);

	sendPing(L"It's Just Code!", L"http://www.pocketsoap.com/weblog/");

	CoUninitialize();
	return 0;
}


void sendPing(const wchar_t * weblogName, const wchar_t * weblogUrl)
{
	USES_CONVERSION;
	// create the Factory object
	CComPtr<IXmlRpcFactory> factory;
	HRESULT hr = factory.CoCreateInstance(CLSID_CoFactory);
	if (FAILED(hr)) {
		std::cout << "failed to create PocketXML-RPC Factory object with error '" << std::hex << hr << "' is PocketXML-RPC installed correctly ?" << std::endl;
		return;
	}

	// use the factory to create the proxy object
	CComDispatchDriver ping ;
	hr = factory->Proxy(CComBSTR(L"http://rpc.weblogs.com/RPC2"),	// url
						CComBSTR(L"weblogUpdates."),				// method prefix
						NULL,										// server username (for authentication)
						NULL,										// server password (for authentication)
						NULL,										// proxy server name
						0,											// proxy server port
						NULL,										// proxy username
						NULL,										// proxy password
						30000,										// timeout in ms
						&ping);										// the resulting proxy
	
	if (FAILED(hr)) {
		std::cout << "failed to create proxy object with error '" << std::hex << hr << "'" << std::endl;
		return;
	}

	// make the call
	// fist off, need to get the DispID of the method we're going to call
	DISPID dispId;
	ping.GetIDOfName(OLESTR("ping"), &dispId);

	// now make the call
	CComVariant param1(weblogName), param2(weblogUrl), retVal ;
	hr = ping.Invoke2(dispId, &param1, &param2, &retVal ) ;
	if (FAILED(hr)) {
		std::cout << "Failed to invoke method, hr=" << std::hex << hr << std::endl ;
		return;
	}

	// get the message child of the resulting struct
	CComPtr<IXmlRpcStruct> res;
	retVal.punkVal->QueryInterface(&res);
	CComVariant msg;
	res->get_Value(CComBSTR(L"message"), &msg);
	msg.ChangeType(VT_BSTR);
	std::cout << "server replied with : " << W2T(msg.bstrVal) << std::endl;
}

⌨️ 快捷键说明

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