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

📄 readip.cpp

📁 经验交流,从网上下载的好东西望大家分享
💻 CPP
字号:
#define _WIN32_DCOM
#include <windows.h>
#include <iostream.h>
#include <stdio.h>
#include <io.h>
#include <fcntl.h>
#include "Component\component.h"

HRESULT HexStringToIP(char* output, REFIID riid, void** pObject)
{
	int max = strlen(output) / 2;
	char* pointer = (char*)CoTaskMemAlloc(max);

	for(int count = 0; count < max; count++)
	{
		//	0 - 9 (48 - 57)     a - f (97 - 102)
		int a1 = output[count*2];
		if(a1 > 47 && a1 < 58)
			a1 = output[count*2] - 48;
		else if(a1 > 96 && a1 < 103)
			a1 = output[count*2] - 87;

		int a2 = output[(count*2)+1];
		if(a2 > 47 && a2 < 58)
			a2 = output[(count*2)+1] - 48;
		else if(a2 > 96 && a2 < 103)
			a2 = output[(count*2)+1] - 87;

		pointer[count] = a1 * 16 + a2;
	}

	HRESULT hr;
	IStream* pStream = 0;
	hr = CreateStreamOnHGlobal(pointer, TRUE, &pStream);
	hr = CoUnmarshalInterface(pStream, riid, pObject);
	pStream->Release();
	return hr;
}

void main()
{
	CoInitialize(NULL);

	char output[1024];
	int fh = _open("c:\\ip.txt", _O_TEXT|_O_RDONLY);
	int read = _read(fh, output, 1024);
	_close(fh);
	output[read] = 0;

	printf("%s\n", output);
	ISum* pSum;
	HexStringToIP(output, IID_ISum, (void**)&pSum);

	int addition;
	pSum->Sum(4, 2, &addition);
	cout << "4 + 2 = " << addition << endl;

	pSum->Release();

	CoUninitialize();
}

⌨️ 快捷键说明

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