#include <windows.h>
#include <ole2.h>
#include <iostream>
#include <string>
// 转换宽字符字符串到多字节字符串
std::string WideToMultiByte(const std::wstring& wstr) {
int len = WideCharToMultiByte(CP_UTF8, 0, wstr.c_str(), -1, NULL, 0, NULL, NULL);
if (len == 0) {
return "";
}
char* buffer = new char[len];
WideCharToMultiByte(CP_UTF8, 0, wstr.c_str(), -1, buffer, len, NULL, NULL);
std::string result(buffer);
delete[] buffer;
return result;
}
// 转换多字节字符串到宽字符字符串
std::wstring MultiByteToWide(const std::string& str) {
int len = MultiByteToWideChar(CP_UTF8, 0, str.c_str(), -1, NULL, 0);
if (len == 0) {
return L"";
}
wchar_t* buffer = new wchar_t[len];
MultiByteToWideChar(CP_UTF8, 0, str.c_str(), -1, buffer, len);
std::wstring result(buffer);
delete[] buffer;
return result;
}
int main() {
// 初始化COM库
HRESULT hr = CoInitialize(NULL);
if (FAILED(hr)) {
std::cerr << "无法初始化COM库,错误码: " << hr << std::endl;
return 1;
}
// 创建WPS应用程序对象
CLSID clsid;
hr = CLSIDFromProgID(L"wps.Application", &clsid);
if (FAILED(hr)) {
std::cerr << "无法获取WPS应用程序的CLSID,错误码: " << hr << std::endl;
CoUninitialize();
return 1;
}
IDispatch* pWpsApp = NULL;
hr = CoCreateInstance(clsid, NULL, CLSCTX_LOCAL_SERVER, IID_IDispatch, (
11-03
1334
1334
10-20
749
749
10-16
872
872


被折叠的 条评论
为什么被折叠?



