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. COM
  4. Passing variants in Fire_xxx methods

Passing variants in Fire_xxx methods

Scheduled Pinned Locked Moved COM
c++debugginghelpquestion
2 Posts 2 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.
  • A Offline
    A Offline
    Aby Philip
    wrote on last edited by
    #1

    Hi, I am working on this ATL dll, which has one object that implements connection points. I added some methods in the event interface that take VARIANT as parameters, so that I may receive the variants in events when I use the same from VB. In IDL file it is like //////////////////////////////////////////////////// [id(3), helpstring("method SampleRecordPkt")] HRESULT SampleRecordPkt([in] VARIANT vBytes); //////////////////////////////////////////////////// Now, I am trying to fire this from my code as follows - (All the hard coded stuff I did for debug only.) //////////////////////////////////////////////////// BYTE bytes[] = {5, 123, 9, 0, 5, 0, 0, 191, 157}; COleSafeArray saBytes1; saBytes1.CreateOneDim(VT_UI1,sizeof(bytes)); for(long i = 0; i < sizeof(bytes);i++) { BYTE val = bytes[i]; saBytes1.PutElement(&i,&val); } file://fire off the appropriate event VARIANT var = saBytes1.Detach(); Fire_SampleRecordPkt(var); ///////////////////////////////////////////////////// However, inside "Fire_SampleRecordPkt(var)", the application crashes. The crash occurs at the line given below (wizard generated code, when "implement connection point" is chosen.) //////////////////////////////////////////////////// DISPPARAMS disp = { pvars, NULL, 1, 0 }; pDispatch->Invoke(0x3, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_METHOD, &disp, &varResult, NULL, NULL); //////////////////////////////////////////////////// Can some body help me identify where I am wrong? Any help is appreciated. Thank you aby

    L 1 Reply Last reply
    0
    • A Aby Philip

      Hi, I am working on this ATL dll, which has one object that implements connection points. I added some methods in the event interface that take VARIANT as parameters, so that I may receive the variants in events when I use the same from VB. In IDL file it is like //////////////////////////////////////////////////// [id(3), helpstring("method SampleRecordPkt")] HRESULT SampleRecordPkt([in] VARIANT vBytes); //////////////////////////////////////////////////// Now, I am trying to fire this from my code as follows - (All the hard coded stuff I did for debug only.) //////////////////////////////////////////////////// BYTE bytes[] = {5, 123, 9, 0, 5, 0, 0, 191, 157}; COleSafeArray saBytes1; saBytes1.CreateOneDim(VT_UI1,sizeof(bytes)); for(long i = 0; i < sizeof(bytes);i++) { BYTE val = bytes[i]; saBytes1.PutElement(&i,&val); } file://fire off the appropriate event VARIANT var = saBytes1.Detach(); Fire_SampleRecordPkt(var); ///////////////////////////////////////////////////// However, inside "Fire_SampleRecordPkt(var)", the application crashes. The crash occurs at the line given below (wizard generated code, when "implement connection point" is chosen.) //////////////////////////////////////////////////// DISPPARAMS disp = { pvars, NULL, 1, 0 }; pDispatch->Invoke(0x3, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_METHOD, &disp, &varResult, NULL, NULL); //////////////////////////////////////////////////// Can some body help me identify where I am wrong? Any help is appreciated. Thank you aby

      L Offline
      L Offline
      Lim Bio Liong
      wrote on last edited by
      #2

      Hello Aby, I have some clues as to what might have gine wrong but I need some more information from you first : Is the events proxy code implemented somewhat like the following ? : HRESULT Fire_SampleRecordPkt(VARIANT vBytes) { CComVariant varResult; T* pT = static_cast(this); int nConnectionIndex; CComVariant* pvars = new CComVariant[1]; int nConnections = m_vec.GetSize(); for (nConnectionIndex = 0; nConnectionIndex < nConnections; nConnectionIndex++) { pT->Lock(); CComPtr sp = m_vec.GetAt(nConnectionIndex); pT->Unlock(); IDispatch* pDispatch = reinterpret_cast(sp.p); if (pDispatch != NULL) { VariantClear(&varResult); pvars[0] = &vBytes; // <-- important. DISPPARAMS disp = { pvars, NULL, 1, 0 }; pDispatch->Invoke(0x1, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_METHOD, &disp, &varResult, NULL, NULL); } } delete[] pvars; return varResult.scode; } Please note the line in which I added the comment "// <-- important.". Please let me know because I suspect your problem may be a case of wrong code generated by the wizard. Please revert, Bio.

      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