08-03-2009 10:35 AM
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
Solved! Go to Solution.
08-03-2009 11:45 AM
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!
08-04-2009 01:33 AM
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...