Question

I'm trying to build a function to assign VARIANTARG types to a DISPPARAMS structure, and I'm having some issues figuring out how to check the actual type of the arg.

myFunc(int count, const BYTE* types, ...)
{
    DISPPARAMS dParams;
    //Initialization stuff goes here

    for(int x = 0;x < count;x++)
    {
        BYTE vt = types[0];
        dParams.rgvarg[x].vt = vt;
        if(vt == VTS_I4)
        {
            dParams.rgvarg[x].lVal = ...;
        }
    }
}

BYTE params[] = {VTS_I4};
myFunc(1, params, 123);

When I compile this, I get two errors at the if statement:

error C2446: '==' : no conversion from 'const char *' to 'int'
error C2040: '==' : 'int' differs in levels of indirection from 'const char [2]'

So I'm fairly confused here: why can I assign a BYTE value from the VTS_I4, but I can't compare it later? If I cast VTS_I4 to a BYTE then I can compare it, but it has a different value so the if statement isn't triggered. The other thing I can do since VTS_I4 is defined in afxdisp.h as "\x03" is check if(vt == 0x03), and that works fine, but has to be wrong somehow.

Another way to ask this question might be why I can do this:

BYTE a[] = VTS_I4;

but not this:

BYTE b = VTS_I4; //'initializing' : cannot convert from 'const char [2]' to 'BYTE'  

Thanks

Was it helpful?

Solution

As mentioned in the comments, the problem was that I was using the wrong constant; I needed to use VT_I4 instead of VTS_I4.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top