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. desparate help needed in making a param array

desparate help needed in making a param array

Scheduled Pinned Locked Moved C / C++ / MFC
questionhelpdata-structuresperformance
4 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
    safee ullah
    wrote on last edited by
    #1

    hi there thanks for the time! the problem i am facing is that i wanted to create a Dispatch parameter array..Once i have created a var of the type using "new", how can i create an array of a given size and be able to assign variables and vts??? here is the code: This code throws bad memory exception after the method is invoked a couple of times :)) void Spread::AddSelection(long nRow1, long nCol1, long nRow2, long nCol2) { DISPPARAMS DispParam; EXCEPINFO excep; UINT nArgErr; DispParam1.cArgs = 4; //number of arguments DispParam1.cNamedArgs = 0;// Number of named arguments. DispParam1.rgdispidNamedArgs = NULL ; // Dispatch IDs of named arguments. DispParam1.rgvarg = new VARIANTARG(); //here i create a new ptr, but how do i create an array which may have variables of different vts and make this pointer point to it? DispParam1.rgvarg->vt = VT_ARRAY; DispParam1.rgvarg[3].vt = VT_I4; DispParam1.rgvarg[3].lVal = nRow1; DispParam1.rgvarg[2].vt = VT_I4; DispParam1.rgvarg[2].lVal = nCol1; DispParam1.rgvarg[1].vt = VT_I4; DispParam1.rgvarg[1].lVal = nRow2; DispParam1.rgvarg[0].vt = VT_I4; DispParam1.rgvarg[0].lVal = nCol2; ISpread::Invoke(ID_AddSelection , IID_NULL , 0 , 1, &DispParam1, NULL , &excep, &nArgErr); } please help thanks regards

    R 1 Reply Last reply
    0
    • S safee ullah

      hi there thanks for the time! the problem i am facing is that i wanted to create a Dispatch parameter array..Once i have created a var of the type using "new", how can i create an array of a given size and be able to assign variables and vts??? here is the code: This code throws bad memory exception after the method is invoked a couple of times :)) void Spread::AddSelection(long nRow1, long nCol1, long nRow2, long nCol2) { DISPPARAMS DispParam; EXCEPINFO excep; UINT nArgErr; DispParam1.cArgs = 4; //number of arguments DispParam1.cNamedArgs = 0;// Number of named arguments. DispParam1.rgdispidNamedArgs = NULL ; // Dispatch IDs of named arguments. DispParam1.rgvarg = new VARIANTARG(); //here i create a new ptr, but how do i create an array which may have variables of different vts and make this pointer point to it? DispParam1.rgvarg->vt = VT_ARRAY; DispParam1.rgvarg[3].vt = VT_I4; DispParam1.rgvarg[3].lVal = nRow1; DispParam1.rgvarg[2].vt = VT_I4; DispParam1.rgvarg[2].lVal = nCol1; DispParam1.rgvarg[1].vt = VT_I4; DispParam1.rgvarg[1].lVal = nRow2; DispParam1.rgvarg[0].vt = VT_I4; DispParam1.rgvarg[0].lVal = nCol2; ISpread::Invoke(ID_AddSelection , IID_NULL , 0 , 1, &DispParam1, NULL , &excep, &nArgErr); } please help thanks regards

      R Offline
      R Offline
      Ryan Binns
      wrote on last edited by
      #2

      You're trying to set 4 parameters, but only allocating memory for 1. You need to allocation 4 structures, not 1:

      DispParam1.rgvarg = new VARIANTARG[4];

      Remember to call

      delete [] DispParm1.rgvarg;

      after the Invoke() method call. Hope this helps,

      Ryan

      "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"

      A 1 Reply Last reply
      0
      • R Ryan Binns

        You're trying to set 4 parameters, but only allocating memory for 1. You need to allocation 4 structures, not 1:

        DispParam1.rgvarg = new VARIANTARG[4];

        Remember to call

        delete [] DispParm1.rgvarg;

        after the Invoke() method call. Hope this helps,

        Ryan

        "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"

        A Offline
        A Offline
        Anonymous
        wrote on last edited by
        #3

        thanks a lot for this timely help! kindest regards safee

        R 1 Reply Last reply
        0
        • A Anonymous

          thanks a lot for this timely help! kindest regards safee

          R Offline
          R Offline
          Ryan Binns
          wrote on last edited by
          #4

          You're welcome :)

          Ryan

          "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"

          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