Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. COM : ATL DLL?

COM : ATL DLL?

Scheduled Pinned Locked Moved C / C++ / MFC
c++comquestion
6 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sam_psycho
    wrote on last edited by
    #1

    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,&param,&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 :)

    S 1 Reply Last reply
    0
    • S sam_psycho

      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,&param,&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 :)

      S Offline
      S Offline
      Stuart Dootson
      wrote on last edited by
      #2

      [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 be VARIANTs 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) using param.

      Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

      S 1 Reply Last reply
      0
      • S Stuart Dootson

        [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 be VARIANTs 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) using param.

        Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

        S Offline
        S Offline
        sam_psycho
        wrote on last edited by
        #3

        I am geting compile time error: Error 1 error C2039: 'nArgs' : is not a member of 'tagDISPPARAMS'

        S 1 Reply Last reply
        0
        • S sam_psycho

          I am geting compile time error: Error 1 error C2039: 'nArgs' : is not a member of 'tagDISPPARAMS'

          S Offline
          S Offline
          Stuart Dootson
          wrote on last edited by
          #4

          Should be cArgs - mix up copying code from where I've used DISPPARAMS.

          Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

          S 1 Reply Last reply
          0
          • S Stuart Dootson

            Should be cArgs - mix up copying code from where I've used DISPPARAMS.

            Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

            S Offline
            S Offline
            sam_psycho
            wrote on last edited by
            #5

            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.

            F 1 Reply Last reply
            0
            • S sam_psycho

              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.

              F Offline
              F Offline
              frx96
              wrote on last edited by
              #6

              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; }

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups