- 註冊時間
- 2002-4-9
- 線上時間
- 0 小時
- 閱讀權限
- 150
- 積分
- 513
- 主題
- 22
- 精華
- 0
- 文章
- 465
該用戶從未簽到 - 文章
- 465
|
呼叫一個同事寫的OLE SERVER...
可是當我進行到呼叫Invoke時, 傳回的HRESULT值老是E_INVALIDARG
我左看右看看不出錯誤
請問有誰知道問題在那嗎??
void LaunchTTR(QUEUE_TYPE& item)
{
// initial com
if (FAILED(CoInitialize(NULL))) {
MessageBox(NULL, _T("Can not initial COM"), _T("Batch"), MB_OK);
return;
}
// 取得CLSID
CLSID id;
if (FAILED(CLSIDFromProgID(CA2W("SearchOleSrv.TSearchServer"), &id))) {
MessageBox(NULL, _T("Can not initial OLE Server"), _T("Batch"), MB_OK);
return;
}
// 建立物件的instance
LPUNKNOWN pUnknown = NULL;
if (CoCreateInstance(id, NULL, CLSCTX_INPROC_SERVER | CLSCTX_LOCAL_SERVER, IID_IUnknown, (void**)&pUnknown) != S_OK) {
MessageBox(NULL, _T("Can not initial OLE Server"), _T("Batch"), MB_OK);
return;
}
// query interface
IDispatch* pDisp = NULL;
if (pUnknown->QueryInterface(IID_IDispatch, (void **)&pDisp) != S_OK) {
MessageBox(NULL, _T("Can not get IDispatch interface!"), _T("Batch"), MB_OK);
return;
}
// release IUnknown
pUnknown->Release();
VARIANT vResult;
HRESULT hr;
DISPID dispID;
VariantInit(&vResult);
LPOLESTR szName = L"CreateReport";
// 取得函數的id
hr = pDisp->GetIDsOfNames(IID_NULL, &szName, 1, LOCALE_USER_DEFAULT, &dispID);
if(FAILED(hr)) {
MessageBox(NULL, _T("Can not get function name!"), _T("Batch"), MB_OK);
return;
}
// 設定要執行的參數
DISPPARAMS DispParams;
VARIANTARG vararg[5];
DispParams.rgvarg = vararg;
DispParams.cNamedArgs = 0;
DispParams.rgdispidNamedArgs = NULL;
DispParams.cArgs = 5;
VariantInit(&DispParams.rgvarg[4]);
VariantInit(&DispParams.rgvarg[3]);
VariantInit(&DispParams.rgvarg[2]);
VariantInit(&DispParams.rgvarg[1]);
VariantInit(&DispParams.rgvarg[0]);
DispParams.rgvarg[4].vt = VT_I4;
DispParams.rgvarg[4].iVal = 0;
DispParams.rgvarg[3].vt = VT_BSTR;
DispParams.rgvarg[3].bstrVal = SysAllocString(CA2W("20030101"));
DispParams.rgvarg[2].vt = VT_BSTR;
DispParams.rgvarg[2].bstrVal = SysAllocString(CA2W("C:\\test.cfg"));
DispParams.rgvarg[1].vt = VT_BSTR;
DispParams.rgvarg[1].bstrVal = SysAllocString(CA2W("C:\\test2.rpt"));
VARIANT vMsg;
VariantInit(&vMsg);
DispParams.rgvarg[0].vt = VT_VARIANT;
DispParams.rgvarg[0].pvarVal = &vMsg;
// 執行函數
hr = pDisp->Invoke(dispID, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_METHOD, &DispParams, &vResult, NULL, NULL);
if(FAILED(hr)) {
MessageBox(NULL, _T("Can not execute function!"), _T("Batch"), MB_OK);
return;
}
pDisp->Release();
CoUninitialize();
}
每次呼叫完Invoke後傳回值都是E_INVALIDARG
CreateReport的proto type為
HRESULT _stdcall CreateReport(long iBatchType, BSTR strReportDateParam, BSTR strCfgFileName, BSTR strOutReportFileName, VARIANT * strOutErrMsg );
請問到底是那邊寫錯了??? |
|