我想通过clsid:{3523C2FB-4031-44E4-9A3B-F1E94986EE7F}在Win32中创建一个COM控件,然后使用api QueryInterface向它发送命令。在MFC项目中,这将在4行代码中非常简单:
m_wndMsTsc.CreateControl(L"{3523C2FB-4031-44E4-9A3B-F1E94986EE7F}", NULL, WS_VISIBLE, CRect(10, 10, 470, 280), this,0))
LPUNKNOWN lpUnk = m_wndMsTsc.GetControlUnknown();
lpUnk->QueryInterface(IID_IMsRdpClient5, (void**)&m_pMsTsc);
lpUnk->QueryInterface(IID_IMsRdpClientNonScriptable5, (void**)&pns);
在Win32中我到目前为止所尝试的内容:
container = ::CreateWindow(L"EDIT",L"", WS_CHILD | WS_VISIBLE, 0, 0, rect.right, rect.bottom, mainWindow, 0, hInstance, 0);
IMsRdpClient5 *rdpClient = NULL;
// Then initialize com control
CoInitialize(0);
CoCreateInstance(CLSID_MsRdpClient5, 0, CLSCTX_ALL, IID_IMsRdpClient5, (void**)&rdpClient);
// Attach
AtlAxAttachControl(rdpClient, container, 0);
IUnknown *pUnk = NULL;
AtlAxGetControl(container, &pUnk);
pUnk->QueryInterface(IID_IMsRdpClient5, (void**)&rdpClient);
如何通过clsid创建控件并将其附加到IUnknown的一个非常基本的示例将非常有用!
答案 0 :(得分:2)
HRESULT hr = AtlAxWinInit();
HWND hWnd = CreateWindow(_T("AtlAxWin"), _T("{3523C2FB-4031-44E4-9A3B-F1E94986EE7F}"), WS_CHILD | WS_VISIBLE, 10, 10, 400, 300, hwnd, (HMENU)102, NULL, NULL);
IUnknown *unkn;
hr = AtlAxGetControl(hWnd, &unkn);
unkn->QueryInterface(IID_IMsRdpClient5, (void**)&rdpClient);
unkn->QueryInterface(IID_IMsRdpClientNonScriptable5, (void**)&rdpClientNonScriptable);\
此方法在Win32中完美运行。感谢大家的想法