0

我想通过 clsid 在 Win32 中创建一个 COM 控件:{3523C2FB-4031-44E4-9A3B-F1E94986EE7F} 然后使用 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 的一个非常基本的示例将非常有帮助!

4

1 回答 1

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 中完美运行。谢谢大家的想法

于 2016-11-24T23:06:33.040 回答