ezpresso
ezpresso

Reputation: 8126

Passing unsigned integers from C++ COM object to VB6

I am trying to access (from a VB6 application) an unsigned 32 bit integer data type returned by the method of a C++ COM object. The part of an interface is declared like:

...
interface ICOMCanvasPixelBuffer : IUnknown
{
    HRESULT GetWidth([retval][out] DWORD *pWidth);
    HRESULT GetHeight([retval][out] unsigned __int32 *pHeight);
    ...

When I am browsing this interface using the Object Browser in VB6, it shows Function GetWidth() As <Unsupported variant type> hint for both of these methods.

Is there way to pass the unsigned integer data type to VB6?

Upvotes: 0

Views: 491

Answers (2)

Roman Ryltsov
Roman Ryltsov

Reputation: 69632

Here is an excerpt from Wnidows SDK which is really helpful in understanding which types to use:

enum VARENUM {
    VT_EMPTY = 0,
    VT_NULL = 1,
    VT_I2 = 2,
    VT_I4 = 3,
    VT_R4 = 4,
    VT_R8 = 5,
    VT_CY = 6,
    VT_DATE = 7,
    VT_BSTR = 8,
    VT_DISPATCH = 9,
    VT_ERROR = 10,
    VT_BOOL = 11,
    VT_VARIANT = 12,
    VT_UNKNOWN = 13,
    VT_DECIMAL = 14,
    VT_I1 = 16,
    VT_UI1 = 17,
    VT_UI2 = 18,
    VT_UI4 = 19,
    // on and on

You will be absolutely safe staying above 16 (with possibly VT_ARRAY | VT_UI1 for byte arrays, which is also common) and this set is flexible enough to cover a lot of scenarios.

In your particluar case you will want VT_I4 which is type LONG.

Upvotes: 1

Seva Alekseyev
Seva Alekseyev

Reputation: 61341

VB6 does not have unsigned datatypes. Is the COM object yours? Just change the interface to a regular, signed int. Do you really have images with width and height over 2 billion?

If the COM object is not yours, sorry, its interface is not Automation-compliant. You can put together a proxy C++ object that would convert all the unsigned's to int's.

Upvotes: 3

Related Questions