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