0

I have a function that expects a short* as an argument. I would need to convert this to a VARIANT_BOOL*. Can anybody tell me a reliable way to do this?

I can even pass the VARIANT_BOOL* to the function, but then the VARIANT_BOOL* is not filled with the correct value.

Thank you very much for the help!

STDMETHODIMP CWrapper::get_IsOpen(VARIANT_BOOL* uIsOpen, LONG* pVal)
{
    if (_c)
    {
        *pVal=_c->IsOpen(uIsOpen); //_c->IsOpen expects short* as argument
        return S_OK;
    }
    else
    {
        return S_FALSE;
    }
}
tmighty
  • 10,734
  • 21
  • 104
  • 218
  • Check out [BOOL vs. VARIANT_BOOL vs. BOOLEAN vs. bool](http://blogs.msdn.com/b/oldnewthing/archive/2004/12/22/329884.aspx). – herohuyongtao Feb 27 '14 at 12:02

2 Answers2

3

VARIANT_BOOL is defined as:

typedef short VARIANT_BOOL; 

So if you want to pass a VARIANT_BOOL to a function that takes a short*, you need to take its address using &. If you want turn the short that a short* points at into a VARIANT_BOOL, you need to perform indirection using *.

VARIANT_BOOL vb = VARIANT_TRUE;

short* sp = &vb; // VARIANT_BOOL to short*

VARIANT_BOOL vb2 = *sp; // short8 to VARIANT_BOOL
Joseph Mansfield
  • 108,238
  • 20
  • 242
  • 324
0

Put the VARIANT_BOOL in a short, call the function, put the short back into the VARIANT_BOOL.

XTF
  • 1,091
  • 1
  • 13
  • 31