1> DISPPARAMS配合BSTR使用,在调用的函数结束后释放内存
2> DISPPARAMS配合BSTR使用,在调用的函数中释放释放内存
3> DISPPARAMS配合SAFEARRAY的使用,利用CComSafeArray来管理内存
1> DISPPARAMS配合BSTR使用,在调用的函数结束后释放内存
2> DISPPARAMS配合BSTR使用,在调用的函数中释放释放内存
3> DISPPARAMS配合SAFEARRAY的使用,利用CComSafeArray来管理内存
--END--
2> DISPPARAMS配合BSTR使用,在调用的函数中释放释放内存
3> DISPPARAMS配合SAFEARRAY的使用,利用CComSafeArray来管理内存
1> DISPPARAMS配合BSTR使用,在调用的函数结束后释放内存
- LRESULT CMainDlg::OnOK(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
- {
- // TODO: Add validation code
- DISPPARAMS param;
- param.cArgs = 3;
- param.cNamedArgs = 0;
- param.rgdispidNamedArgs = NULL;
- param.rgvarg = new VARIANTARG[3];
- param.rgvarg[0].vt = VT_BSTR;
- param.rgvarg[0].bstrVal = SysAllocString(L"A000");
- param.rgvarg[1].vt = VT_BSTR;
- param.rgvarg[1].bstrVal = SysAllocString(L"A111");
- param.rgvarg[2].vt = VT_BSTR;
- param.rgvarg[2].bstrVal = SysAllocString(L"A222");
- UserDispparams(¶m);
- SysFreeString(param.rgvarg[0].bstrVal);
- SysFreeString(param.rgvarg[1].bstrVal);
- SysFreeString(param.rgvarg[2].bstrVal);
- delete [] param.rgvarg;
- CloseDialog(wID);
- return 0;
- }
- // ... ...
- HRESULT CMainDlg::UserDispparams(DISPPARAMS* pDispParams)
- {
- if (!pDispParams)
- return E_INVALIDARG;
- if (3 != pDispParams->cArgs)
- return E_INVALIDARG;
- wstring strMsg;
- strMsg = strMsg + pDispParams->rgvarg[0].bstrVal + L", ";
- strMsg = strMsg + pDispParams->rgvarg[1].bstrVal + L", ";
- strMsg = strMsg + pDispParams->rgvarg[2].bstrVal + L".";
- MessageBox(strMsg.c_str(), L"UserDispparams", 0x20);
- return S_OK;
- }
- LRESULT CMainDlg::OnOK(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
- {
- // TODO: Add validation code
- DISPPARAMS param;
- param.cArgs = 3;
- param.cNamedArgs = 0;
- param.rgdispidNamedArgs = NULL;
- param.rgvarg = new VARIANTARG[3];
- param.rgvarg[0].vt = VT_BSTR;
- param.rgvarg[0].bstrVal = CComBSTR(L"A000").Detach();
- param.rgvarg[1].vt = VT_BSTR;
- param.rgvarg[1].bstrVal = CComBSTR(L"A111").Detach();
- param.rgvarg[2].vt = VT_BSTR;
- param.rgvarg[2].bstrVal = CComBSTR(L"A222").Detach();
- UserDispparams(¶m);
- delete [] param.rgvarg;
- CloseDialog(wID);
- return 0;
- }
- // ... ...
- HRESULT CMainDlg::UserDispparams(DISPPARAMS* pDispParams)
- {
- if (!pDispParams)
- return E_INVALIDARG;
- if (3 != pDispParams->cArgs)
- return E_INVALIDARG;
- wstring strMsg;
- CComBSTR bstr0, bstr1, bstr2;
- bstr0.Attach(pDispParams->rgvarg[0].bstrVal);
- bstr1.Attach(pDispParams->rgvarg[1].bstrVal);
- bstr2.Attach(pDispParams->rgvarg[2].bstrVal);
- strMsg += bstr0;
- strMsg += L", ";
- strMsg += bstr1;
- strMsg += L", ";
- strMsg += bstr2;
- strMsg += L".";
- MessageBox(strMsg.c_str(), L"UserDispparams", 0x20);
- return S_OK;
- }
- LRESULT CMainDlg::OnOK(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
- {
- // TODO: Add validation code
- DISPPARAMS param;
- param.cArgs = 4;
- param.cNamedArgs = 0;
- param.rgdispidNamedArgs = NULL;
- param.rgvarg = new VARIANTARG[4];
- param.rgvarg[0].vt = VT_BSTR;
- param.rgvarg[0].bstrVal = CComBSTR(L"A000").Detach();
- param.rgvarg[1].vt = VT_BSTR;
- param.rgvarg[1].bstrVal = CComBSTR(L"A111").Detach();
- param.rgvarg[2].vt = VT_BSTR;
- param.rgvarg[2].bstrVal = CComBSTR(L"A222").Detach();
- CComSafeArray<BSTR> sa;
- sa.Add(CComBSTR(L"B000").Detach());
- sa.Add(CComBSTR(L"B111").Detach());
- sa.Add(CComBSTR(L"B222").Detach());
- param.rgvarg[3].vt = VT_ARRAY;
- param.rgvarg[3].parray = sa.Detach();
- UserDispparams(¶m);
- delete [] param.rgvarg;
- _CrtDumpMemoryLeaks();
- CloseDialog(wID);
- return 0;
- }
- HRESULT CMainDlg::UserDispparams(DISPPARAMS* pDispParams)
- {
- if (!pDispParams)
- return E_INVALIDARG;
- if (4 != pDispParams->cArgs)
- return E_INVALIDARG;
- wstring strMsg;
- CComBSTR bstrA0, bstrA1, bstrA2;
- CComBSTR bstrB0, bstrB1, bstrB2;
- CComSafeArray<BSTR> sa;
- bstrA0.Attach(pDispParams->rgvarg[0].bstrVal);
- bstrA1.Attach(pDispParams->rgvarg[1].bstrVal);
- bstrA2.Attach(pDispParams->rgvarg[2].bstrVal);
- sa.Attach(pDispParams->rgvarg[3].parray);
- bstrB0.Attach(sa.GetAt(0));
- bstrB1.Attach(sa.GetAt(1));
- bstrB2.Attach(sa.GetAt(2));
- strMsg += bstrA0;
- strMsg += L", ";
- strMsg += bstrA1;
- strMsg += L", ";
- strMsg += bstrA2;
- strMsg += L".";
- strMsg += bstrB0;
- strMsg += L", ";
- strMsg += bstrB1;
- strMsg += L", ";
- strMsg += bstrB2;
- strMsg += L".";
- MessageBox(strMsg.c_str(), L"UserDispparams", 0x20);
- return S_OK;
- }
--END--