How can I get width and depth of component instance in Api C++?

Please post code correctly for the forum. See:
[How to] Post correctly formatted and colorized code on the forum?

And is your code working ? I see a spades symbol …

Perhaps standard C printf() does not know how to convert a SUTypedValueRef to a String as you are using a %s replacement parameter ?

I think you need to put the printf() statements inside the type checking clauses of the if statements.
Something like this (although I’m not that good with C language):

        if(tvt == SUTypedValueType_Float || tvt == SUTypedValueType_Double) {
            double x;
            SUTypedValueGetFloat(val_x, &x);
            printf("val_x is : %f \n", x);
            // Do something with the X value ...
        } else if(tvt == SUTypedValueType_String)  {
            char x[100]; // make big enough for value
            SUTypedValueGetString(val_x, &x);
            printf("val_x is : %s \n", x);
            // Do something with the X value ...
        } else if(tvt == SUTypedValueType_Empty) {
            print("val_x is empty);
        } else {
            print("val_x is unknown typed value);

You can also get String values by using SUComponentInstanceCreateDCInfo() to get the DC instance’s SUDynamicComponentInfoRef struct, from which you can get the attribute array via SUDynamicComponentInfoGetDCAttributes().

Then you can iterate the array of SUDynamicComponentAttributeRef structs and get the String value via SUDynamicComponentAttributeGetDisplayValue().

Lastly convert the String to a double using val_x = strtod(s,NULL).