COM : ATL DLL?
-
Hi Experts, I have ATL DLL with Addition() method, I calling this function from another MFC application with no argument Code goes like : Assume no syntax errors CLSID cls_id; CLSIDFromProgID(L"DLLTest.MyObject",&cls_id); CComPtr<IDispatch> pService; HRESULT hr = pService.CoCreateInstance(cls_id, NULL, CLSCTX_INPROC_SERVER|CLSCTX_LOCAL_SERVER); if(hr == S_OK) { DISPID Disp_id; CString bsvalue; CComVariant Result; OLECHAR *member=_T("Addition"); DISPPARAMS param = {NULL,NULL,0,0}; hr = pService->GetIDsOfNames(IID_NULL,&member,1,LOCALE_SYSTEM_DEFAULT,&Disp_id); if(S_OK == hr) hr = pService->Invoke(Disp_id,IID_NULL,LOCALE_SYSTEM_DEFAULT,DISPATCH_METHOD,¶m,&Result,NULL,NULL); else MessageBox(L"Could not get disp id",L"MSG",MB_OK); } else MessageBox(L"No Interface",L"MSG",MB_OK); This code works fine but, now I want to call same function Addition() with two arguments, I have made respective chages in DLL, so please give me solution or hint :)
-
Hi Experts, I have ATL DLL with Addition() method, I calling this function from another MFC application with no argument Code goes like : Assume no syntax errors CLSID cls_id; CLSIDFromProgID(L"DLLTest.MyObject",&cls_id); CComPtr<IDispatch> pService; HRESULT hr = pService.CoCreateInstance(cls_id, NULL, CLSCTX_INPROC_SERVER|CLSCTX_LOCAL_SERVER); if(hr == S_OK) { DISPID Disp_id; CString bsvalue; CComVariant Result; OLECHAR *member=_T("Addition"); DISPPARAMS param = {NULL,NULL,0,0}; hr = pService->GetIDsOfNames(IID_NULL,&member,1,LOCALE_SYSTEM_DEFAULT,&Disp_id); if(S_OK == hr) hr = pService->Invoke(Disp_id,IID_NULL,LOCALE_SYSTEM_DEFAULT,DISPATCH_METHOD,¶m,&Result,NULL,NULL); else MessageBox(L"Could not get disp id",L"MSG",MB_OK); } else MessageBox(L"No Interface",L"MSG",MB_OK); This code works fine but, now I want to call same function Addition() with two arguments, I have made respective chages in DLL, so please give me solution or hint :)
[Hint]If you post your code formatted in a <pre> block, we can read it easier, which means we're more likely to answer you question...[/Hint] You want to add parameters to the
param
variable. They will beVARIANT
s packaged as follows (note: I'm presuming they're 32-bit integer arguments, of value 12 and 45 respectively):VARIANTARG args[2];
V_VT(&args[0]) = VT_I4;
V_I4(&args[0]) = 12;
V_VT(&args[1]) = VT_I4;
V_I4(&args[1]) = 45;
param.nArgs = 2;
param.rgvarg = args;Add this code between a) declaring
param
and b) usingparam
.Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
-
[Hint]If you post your code formatted in a <pre> block, we can read it easier, which means we're more likely to answer you question...[/Hint] You want to add parameters to the
param
variable. They will beVARIANT
s packaged as follows (note: I'm presuming they're 32-bit integer arguments, of value 12 and 45 respectively):VARIANTARG args[2];
V_VT(&args[0]) = VT_I4;
V_I4(&args[0]) = 12;
V_VT(&args[1]) = VT_I4;
V_I4(&args[1]) = 45;
param.nArgs = 2;
param.rgvarg = args;Add this code between a) declaring
param
and b) usingparam
.Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
I am geting compile time error: Error 1 error C2039: 'nArgs' : is not a member of 'tagDISPPARAMS'
-
I am geting compile time error: Error 1 error C2039: 'nArgs' : is not a member of 'tagDISPPARAMS'
Should be
cArgs
- mix up copying code from where I've usedDISPPARAMS
.Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
-
Should be
cArgs
- mix up copying code from where I've usedDISPPARAMS
.Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
Done!!! I made slide changes 'cos of application was crashing due to invalid arguments. VARIANTARG args[2]; V_VT(&args[0]) = VT_I4; V_I4(&args[0]) = 12; V_VT(&args[1]) = VT_I4; V_I4(&args[1]) = 45; param.cArgs = 2; param.rgvarg = args;
param.cNamedArgs=0;
param.rgdispidNamedArgs=0;thanx for replying.
-
Done!!! I made slide changes 'cos of application was crashing due to invalid arguments. VARIANTARG args[2]; V_VT(&args[0]) = VT_I4; V_I4(&args[0]) = 12; V_VT(&args[1]) = VT_I4; V_I4(&args[1]) = 45; param.cArgs = 2; param.rgvarg = args;
param.cNamedArgs=0;
param.rgdispidNamedArgs=0;thanx for replying.
IDispatch* DllBase::CreateClassComDispatch(BSTR sClassName) { CLSID clsid; IUnknown *pUnk; IDispatch *pDisp; HRESULT hr; CLSIDFromProgID(sClassName, &clsid); hr = CoInitialize(NULL); if(FAILED(hr)) return FALSE; hr = CoCreateInstance(clsid,NULL,CLSCTX_ALL,IID_IUnknown,(void**)&pUnk); if(FAILED(hr)) return FALSE; hr = pUnk->QueryInterface(IID_IDispatch, (void **)&pDisp); if(FAILED(hr)) { pUnk->Release(); return FALSE; } return pDisp; } GetPrinterList(char* printLib, char* printersUrl, char* username, char* password) { char* retValue = NULL; HRESULT hr; DISPID idd; VARIANTARG varResult; IDispatch *pDisp; try { VariantInit(&varResult); retValue = NULL; //lib _bstr_t bstrLib = _bstr_t(printLib); pDisp = CreateClassComDispatch(bstrLib.GetBSTR()); if(pDisp == NULL) return NULL; //function LPOLESTR str = L"GetPrinterList"; //params int ParamsNumber = 3; VARIANTARG avarParams[3]; for(int i=0;i<paramsnumber;i++){> ::VariantInit( &avarParams[i] ); } _bstr_t bstrTemp1 = _bstr_t(password); avarParams[0].vt = VT_BSTR; avarParams[0].bstrVal = bstrTemp1.copy(); _bstr_t bstrTemp2 = _bstr_t(username); avarParams[1].vt = VT_BSTR; avarParams[1].bstrVal = bstrTemp2.copy(); _bstr_t bstrTemp3 = _bstr_t(printersUrl); avarParams[2].vt = VT_BSTR; avarParams[2].bstrVal = bstrTemp3.copy(); DISPPARAMS params = { avarParams, NULL, ParamsNumber, 0 }; //get ID hr = pDisp->GetIDsOfNames(IID_NULL,&str,1,NULL,&idd); if(!FAILED(hr)) { hr = pDisp->Invoke(idd, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_METHOD, ¶ms, &varResult, NULL, NULL); if(FAILED(hr)) retValue = NULL; else { _bstr_t retvalue = _bstr_t(varResult.bstrVal); retValue = strdup((char*)retvalue); } } else { retValue = NULL; } for(int j=0;j<paramsnumber;j++){> ::VariantClear( &avarParams[j] ); } ::VariantClear( &varResult ); return retValue; } catch(...) { } return NULL; }