On 1/19/2011 10:54 AM, Lucas Coppio wrote:
I did some of my homework and finally translated the VB script to C++,
but it still don't work, it compiles and start the , but when the
codes reaches the first AutoWrap of my "newly decoded border function"
it crashes the programa.
The code
{
VARIANT xlSolid = {1};
int xlCenter = {-4108};
VARIANT xlBottom = {-4107};
VARIANT xlTop = {-4160};
VARIANT xlRight = {-4152};
VARIANT xlLeft = {-4131};
VARIANT xlCellTypeLastCell = {11};
VARIANT xlThin = {2};
VARIANT xlNone = {-4142};
VARIANT xlContinuous = {1};
VARIANT xlAutomatic = {-4105};
VARIANT xlExpression = {2};
VARIANT root[64] = {0}; // Generic IDispatchs
VARIANT parm[64] = {0}; // Generic Parameters
VARIANT rVal = {0}; // Temporary result holder
int level=0; // Current index into root[]
// Initialize the OLE Library...
// OleInitialize(NULL);
// Line 1: Range B10:I50 . Select
AutoWrap(DISPATCH_METHOD, NULL, root[level].pdispVal, L"B10:I50",
0);
// Line 2: Selection . Borders xlDiagonalDown . LineStyle =
xlNone
VariantCopy(&rVal,&xlNone);
AutoWrap(DISPATCH_PROPERTYGET|DISPATCH_METHOD,&root[level+1],
root[level++].pdispVal, L".", 2, parm[1], parm[0]);
VariantClear(&parm[0]);
VariantClear(&parm[1]);
AutoWrap(DISPATCH_PROPERTYPUT, NULL, root[level].pdispVal,
L"Borders", 2, rVal, parm[0]);
VariantClear(&parm[0]);
VariantClear(&root[level--]);
VariantClear(&rVal);
// Line 3: Selection . Borders xlDiagonalUp . LineStyle = xlNone
VariantCopy(&rVal,&xlNone);
AutoWrap(DISPATCH_PROPERTYGET|DISPATCH_METHOD,&root[level+1],
root[level++].pdispVal, L".", 2, parm[1], parm[0]);
VariantClear(&parm[0]);
VariantClear(&parm[1]);
AutoWrap(DISPATCH_PROPERTYPUT, NULL, root[level].pdispVal,
L"Borders", 2, rVal, parm[0]);
VariantClear(&parm[0]);
VariantClear(&root[level--]);
VariantClear(&rVal);
// Line 4: With Selection . Borders xlEdgeLeft
AutoWrap(DISPATCH_PROPERTYGET|DISPATCH_METHOD,&rVal,
root[level].pdispVal, L".", 2, parm[1], parm[0]);
VariantClear(&parm[0]);
VariantClear(&parm[1]);
VariantCopy(&root[++level],&rVal);
VariantClear(&rVal);
// Line 5: . LineStyle = xlContinuous
VariantCopy(&rVal,&xlContinuous);
AutoWrap(DISPATCH_PROPERTYPUT, NULL, root[level].pdispVal,
L"LineStyle", 1, rVal);
VariantClear(&rVal);
// Line 6: . ColorIndex = 0
rVal.vt = VT_I4;
rVal.lVal = 0;
AutoWrap(DISPATCH_PROPERTYPUT, NULL, root[level].pdispVal,
L"ColorIndex", 1, rVal);
VariantClear(&rVal);
// Line 7: . TintAndShade = 0
rVal.vt = VT_I4;
rVal.lVal = 0;
AutoWrap(DISPATCH_PROPERTYPUT, NULL, root[level].pdispVal,
L"TintAndShade", 1, rVal);
VariantClear(&rVal);
// Line 8: . Weight = xlThin
VariantCopy(&rVal,&xlThin);
AutoWrap(DISPATCH_PROPERTYPUT, NULL, root[level].pdispVal,
L"Weight", 1, rVal);
VariantClear(&rVal);
// Line 9: End With
VariantClear(&root[level--]);
// Line 10: With Selection . Borders xlEdgeTop
AutoWrap(DISPATCH_PROPERTYGET|DISPATCH_METHOD,&rVal,
root[level].pdispVal, L".", 2, parm[1], parm[0]);
VariantClear(&parm[0]);
VariantClear(&parm[1]);
VariantCopy(&root[++level],&rVal);
VariantClear(&rVal);
// Line 11: . LineStyle = xlContinuous
VariantCopy(&rVal,&xlContinuous);
AutoWrap(DISPATCH_PROPERTYPUT, NULL, root[level].pdispVal,
L"LineStyle", 1, rVal);
VariantClear(&rVal);
// Line 12: . ColorIndex = 0
rVal.vt = VT_I4;
rVal.lVal = 0;
AutoWrap(DISPATCH_PROPERTYPUT, NULL, root[level].pdispVal,
L"ColorIndex", 1, rVal);
VariantClear(&rVal);
// Line 13: . TintAndShade = 0
rVal.vt = VT_I4;
rVal.lVal = 0;
AutoWrap(DISPATCH_PROPERTYPUT, NULL, root[level].pdispVal,
L"TintAndShade", 1, rVal);
VariantClear(&rVal);
// Line 14: . Weight = xlThin
VariantCopy(&rVal,&xlThin);
AutoWrap(DISPATCH_PROPERTYPUT, NULL, root[level].pdispVal,
L"Weight", 1, rVal);
VariantClear(&rVal);
// Line 15: End With
VariantClear(&root[level--]);
// Line 16: With Selection . Borders xlEdgeBottom
AutoWrap(DISPATCH_PROPERTYGET|DISPATCH_METHOD,&rVal,
root[level].pdispVal, L".", 2, parm[1], parm[0]);
VariantClear(&parm[0]);
VariantClear(&parm[1]);
VariantCopy(&root[++level],&rVal);
VariantClear(&rVal);
// Line 17: . LineStyle = xlContinuous
VariantCopy(&rVal,&xlContinuous);
AutoWrap(DISPATCH_PROPERTYPUT, NULL, root[level].pdispVal,
L"LineStyle", 1, rVal);
VariantClear(&rVal);
// Line 18: . ColorIndex = 0
rVal.vt = VT_I4;
rVal.lVal = 0;
AutoWrap(DISPATCH_PROPERTYPUT, NULL, root[level].pdispVal,
L"ColorIndex", 1, rVal);
VariantClear(&rVal);
// Line 19: . TintAndShade = 0
rVal.vt = VT_I4;
rVal.lVal = 0;
AutoWrap(DISPATCH_PROPERTYPUT, NULL, root[level].pdispVal,
L"TintAndShade", 1, rVal);
VariantClear(&rVal);
// Line 20: . Weight = xlThin
VariantCopy(&rVal,&xlThin);
AutoWrap(DISPATCH_PROPERTYPUT, NULL, root[level].pdispVal,
L"Weight", 1, rVal);
VariantClear(&rVal);
// Line 21: End With
VariantClear(&root[level--]);
// Line 22: With Selection . Borders xlEdgeRight
AutoWrap(DISPATCH_PROPERTYGET|DISPATCH_METHOD,&rVal,
root[level].pdispVal, L".", 2, parm[1], parm[0]);
VariantClear(&parm[0]);
VariantClear(&parm[1]);
VariantCopy(&root[++level],&rVal);
VariantClear(&rVal);
// Line 23: . LineStyle = xlContinuous
VariantCopy(&rVal,&xlContinuous);
AutoWrap(DISPATCH_PROPERTYPUT, NULL, root[level].pdispVal,
L"LineStyle", 1, rVal);
VariantClear(&rVal);
// Line 24: . ColorIndex = 0
rVal.vt = VT_I4;
rVal.lVal = 0;
AutoWrap(DISPATCH_PROPERTYPUT, NULL, root[level].pdispVal,
L"ColorIndex", 1, rVal);
VariantClear(&rVal);
// Line 25: . TintAndShade = 0
rVal.vt = VT_I4;
rVal.lVal = 0;
AutoWrap(DISPATCH_PROPERTYPUT, NULL, root[level].pdispVal,
L"TintAndShade", 1, rVal);
VariantClear(&rVal);
// Line 26: . Weight = xlThin
VariantCopy(&rVal,&xlThin);
AutoWrap(DISPATCH_PROPERTYPUT, NULL, root[level].pdispVal,
L"Weight", 1, rVal);
VariantClear(&rVal);
// Line 27: End With
VariantClear(&root[level--]);
// Line 28: With Selection . Borders xlInsideVertical
AutoWrap(DISPATCH_PROPERTYGET|DISPATCH_METHOD,&rVal,
root[level].pdispVal, L".", 2, parm[1], parm[0]);
VariantClear(&parm[0]);
VariantClear(&parm[1]);
VariantCopy(&root[++level],&rVal);
VariantClear(&rVal);
// Line 29: . LineStyle = xlContinuous
VariantCopy(&rVal,&xlContinuous);
AutoWrap(DISPATCH_PROPERTYPUT, NULL, root[level].pdispVal,
L"LineStyle", 1, rVal);
VariantClear(&rVal);
// Line 30: . ColorIndex = 0
rVal.vt = VT_I4;
rVal.lVal = 0;
AutoWrap(DISPATCH_PROPERTYPUT, NULL, root[level].pdispVal,
L"ColorIndex", 1, rVal);
VariantClear(&rVal);
// Line 31: . TintAndShade = 0
rVal.vt = VT_I4;
rVal.lVal = 0;
AutoWrap(DISPATCH_PROPERTYPUT, NULL, root[level].pdispVal,
L"TintAndShade", 1, rVal);
VariantClear(&rVal);
// Line 32: . Weight = xlThin
VariantCopy(&rVal,&xlThin);
AutoWrap(DISPATCH_PROPERTYPUT, NULL, root[level].pdispVal,
L"Weight", 1, rVal);
VariantClear(&rVal);
// Line 33: End With
VariantClear(&root[level--]);
// Line 34: With Selection . Borders xlInsideHorizontal
AutoWrap(DISPATCH_PROPERTYGET|DISPATCH_METHOD,&rVal,
root[level].pdispVal, L".", 2, parm[1], parm[0]);
VariantClear(&parm[0]);
VariantClear(&parm[1]);
VariantCopy(&root[++level],&rVal);
VariantClear(&rVal);
// Line 35: . LineStyle = xlContinuous
VariantCopy(&rVal,&xlContinuous);
AutoWrap(DISPATCH_PROPERTYPUT, NULL, root[level].pdispVal,
L"LineStyle", 1, rVal);
VariantClear(&rVal);
// Line 36: . ColorIndex = 0
rVal.vt = VT_I4;
rVal.lVal = 0;
AutoWrap(DISPATCH_PROPERTYPUT, NULL, root[level].pdispVal,
L"ColorIndex", 1, rVal);
VariantClear(&rVal);
// Line 37: . TintAndShade = 0
rVal.vt = VT_I4;
rVal.lVal = 0;
AutoWrap(DISPATCH_PROPERTYPUT, NULL, root[level].pdispVal,
L"TintAndShade", 1, rVal);
VariantClear(&rVal);
// Line 38: . Weight = xlThin
VariantCopy(&rVal,&xlThin);
AutoWrap(DISPATCH_PROPERTYPUT, NULL, root[level].pdispVal,
L"Weight", 1, rVal);
VariantClear(&rVal);
// Line 39: End With
VariantClear(&root[level--]);
// Line 40: End Sub
// Close the OLE Library...
//OleUninitialize();
// */
}