From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

COM client in LabView

Hi,
I've made a COM server in C++ and now I've some problems when using it
in LabView. It is working fine in C++, VB and Delphi, but not in
LabView. The problem occurs when I return a VARIANT of type VT_BYREF.
It seems like LabView can't handle that, I get an error message when
Func1 returns saying "Bad variable type" (-2147352568).

In my COM server I have:

class A
{
};

Then I return a pointer to this class, and do that by casting it to a
void pointer and store it in a VARIANT of type VT_BYREF.

STDMETHODIMP COMClass::Func1(/*out*/VARIANT *pHandle)
{
A *pA = new A;

//Fill A with stuff

VariantInit(pHandle);
pHandle->vt = VT_BYREF;
pHandle->byref = (void *)pA;
return S_OK;
}

I've tried to remove the line "pHandle->vt = VT_BYREF;"
, and then the
function succeeds, but the next function fails.

STDMETHODIMP COMClass::Func2(/*in*/VARIANT *pHandle)
{
if(pHandle)
{
if(!pHandle.byref)
AfxMessageBox("byref empty!");
// The message box appears and another control shows that
pHandle.vt == 0.
}
}

How can I pass a void * in COM so LabView can handle it? The user
isn't supposed to do anything with the pointer just pass it back to
the next function.

Thanks,
/Therese
0 Kudos
Message 1 of 2
(2,311 Views)
Since you are just sending a void pointer, try setting

pHandle->vt = VT_PTR;
pHandle->byRef = (void*)pA;
0 Kudos
Message 2 of 2
(2,311 Views)