LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Build Application; enable ActiveX but get E_NOINTERFACE errors in C++

Solved!
Go to solution

Hi

 

I have a hopefully easy problem to resolve using the Smart Pointers in C++ (VS2008).  So here goes...

 

 

I build a Labview application (MyExample.exe) based around my virtual instrument (MyExample.VI); and enable ActiveX with the server name 'MyExample'. I run MyExample.exe to register the full IID. In my code I do the following...

 

#import "d:\mypath\myexample.tlb" // to get access to the standard TLB file (same as doing #import "d:\program files\nationalinstruments\labview\...\labview.tlb"

 

MyExample::_ApplicationPtr m_pMyLabviewApp;

MyExample::VirtualInstrumentPtr m_MyLabviewVI;

 

HRESULT hr;

hr = CoInitialize(NULL);

 

// blah blah

hr  = this->m_pMyLabviewApp.CreateInstance("MyExample.Application"); // or with .7 for version specifics!

 

My application loads and starts up... However hr always returns E_NOINTERFACE, and the smart pointer m_pMyLabviewApp is always null.

 

However if I do the exact same code but replace MyExample with LabVIEW then it works perfectly. If I load 'MyExample.Application' in Labview using the ActiveX vi's it also works perfectly.Similarly if I use the Automation commands in Matlab.

 

My hope is that it is something trivial and dumb with the smart pointers... any hints?

 

Thanks

0 Kudos
Message 1 of 3
(2,733 Views)
Solution
Accepted by topic author marc lawrence

Ok digging into the code a little more... the CreateInstance calls a various number of 'CreateInstances'... but the critical bit in comip.h...

line 623...

 

        if (dwClsContext & (CLSCTX_LOCAL_SERVER | CLSCTX_REMOTE_SERVER)) {
            IUnknown* pIUnknown;
            hr = CoCreateInstance(rclsid, pOuter, dwClsContext, __uuidof(IUnknown), reinterpret_cast<void**>(&pIUnknown));

            if (SUCCEEDED(hr)) {
                hr = OleRun(pIUnknown);

                if (SUCCEEDED(hr)) {
                    hr = pIUnknown->QueryInterface(GetIID(), reinterpret_cast<void**>(&m_pInterface));
                }

                pIUnknown->Release();
            }
        }

 

The GetIID() function returns <LabVIEW::_Application>no matter whether I call with MyExample::_ApplicationPtr or LabVIEW::_ApplicationPtr - consequently the Query Interface will obviously be wrong. Now either this is a bug in my header chain (I will need to check all the .h and .cpp files) or there is something else strange with the importing of the .tlb file. 

 

Or I am dumb and should use LabVIEW::_Application even with MyExample!

 

 

0 Kudos
Message 2 of 3
(2,724 Views)

I found the problem; and offending header also accidentilly included the Labview.tlb file. Consequently the call to the static variable GetIID which returns 'return *_IID;' returned the value stored in the Labview.tlb file and not the one from the MyExample.tlb.

 

Removing the incorrect #import "....\Labview.tlb" resolved the issue...

 

 

0 Kudos
Message 3 of 3
(2,718 Views)