NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

Modifying DBLog.dll to Add a RemoveConnection function

Hi,

 

I am looking at modifying DBLog.dll to add a RemoveConnectioin function, which upon calling, it will close the database connection and set "m_pDatalink" to zero.  However, I am having problem in compiling the code that it is complaining the following error message:

 

1>c:\program files\microsoft visual studio 8\vc\atlmfc\include\atlcom.h(1792) : error C2259: 'ATL::CComObject<Base>' : cannot instantiate abstract class

1> with

1> [

1> Base=CTSDBLog

1> ]

1> due to following members:

1> 'HRESULT ITSDBLog::CloseConnection(IDispatch *,unsigned char *)' : is abstract

1> c:\program files\national instruments\teststand 4.2\components\models\teststandmodels\database\dblog\dblog.h(137) : see declaration of 'ITSDBLog::CloseConnection'

1> c:\program files\microsoft visual studio 8\vc\atlmfc\include\atlcom.h(1781) : while compiling class template member function 'HRESULT ATL::CComCreator<T1>::CreateInstance(void *,const IID &,LPVOID *)'

1> with

1> [

1> T1=ATL::CComObject<CTSDBLog>

1> ]

1> c:\program files\microsoft visual studio 8\vc\atlmfc\include\atlcom.h(1872) : see reference to class template instantiation 'ATL::CComCreator<T1>' being compiled

1> with

1> [

1> T1=ATL::CComObject<CTSDBLog>

1> ]

 

In the code, I have the following declarations and definitions:

 

1. TSDBLog.h

class CTSDBLog {

...

STDMETHOD(CloseConnection)(/*[in]*/IDispatch *seqContextDisp, /*[in]*/_bstr_t sessionName);

..

}

2. TSDBLog.h

class CTSDatalink {

...

STDMETHOD(CloseConnection)(IDispatch *seqContextDisp, _bstr_t sessionName);

...

}

3. DBLog.idl

interface ITSDBLog : IDispatch  {

...

[id(5), helpstring("method CloseConnection")] HRESULT CloseConnection(IDispatch *seqContextDisp, char* sessionName);

...

}

4. TSDatalink.cpp

STDMETHODIMP CTSDatalink::CloseConnection(IDispatch *seqContextDisp, _bstr_t sessionName) {

...

}

5. TSDBLog.cpp

STDMETHODIMP CTSDBLog::CloseConnection(IDispatch *seqContextDisp, _bstr_t sessionName) {

...

}

6. dblog.h

MIDL_INTERFACE(...) ITSDBLog : public IDispatch {

...

virtual /* [helpstring][id] */ HRESULT STDMETHODCALLTYPE CloseConnection(

IDispatch *seqContextDisp,

unsigned char *sessionName) = 0;

...

}

7. dblog.h

...

/* [helpstring][id] */ HRESULT STDMETHODCALLTYPE ITSDBLog_CloseConnection_Proxy(

ITSDBLog * This,

IDispatch *seqContextDisp,

unsigned char *sessionName);

 

void __RPC_STUB ITSDBLog_CloseConnection_Stub(

IRpcStubBuffer *This,

IRpcChannelBuffer *_pRpcChannelBuffer,

PRPC_MESSAGE _pRpcMessage,

DWORD *_pdwStubPhase);

...

 

Did I miss anything?!

 

 

Peggy

 

0 Kudos
Message 1 of 11
(3,930 Views)

Hi PeggyC,

 

This article on MSDN may be helpful for you to take a look at.  It gives snippets of code that exhibit the error as well as suggestions on how to fix it.

Cheers,
Kelly R.
Applications Engineer
National Instruments
0 Kudos
Message 2 of 11
(3,913 Views)

Thanks...

 

I found there was a mismatch in the parameter....

 

Peggy

0 Kudos
Message 3 of 11
(3,903 Views)

Hi,

 

I think I wrote the earlier message too quick.  After I have the code compiled, now in TestStand, I inserted an Action Step, but the calling of this new function has the following error:

 

[Error - An error occurred calling 'CloseConnection' in 'ITSDBLog' of 'zNI TestStand Database Logging'

 

 

What's wrong?!

 

 

Peggy

 

0 Kudos
Message 4 of 11
(3,901 Views)

Hi Peggy,

 

I think that it would be helpful for you to be able to step into the DLL to get more information on where the error is occurring.  Within Visual Studio, we can go to Debug --> Attach to Process to attach to the sequence editor.  We can run your sequence and use normal troubleshooting procedures (e.g. breakpoints, stepping through your code) to better determine where this error is coming from and why.

Cheers,
Kelly R.
Applications Engineer
National Instruments
0 Kudos
Message 5 of 11
(3,879 Views)

I attached the Visual Studio with "SeqEdit.exe" process.  From TestStand, I placed a breakpoint on the step that calls DBLog.dll RemoveConnection function.  When Test Stand execution halts, I select "Step Into (F8)". 

 

I am not able to step into the Visual Studio development environment.  Did I missing any step?!

 

I am using Visual C++ 2005, and TestStand 4.2.

 

Peggy

 

0 Kudos
Message 6 of 11
(3,875 Views)

Hi Peggy,

 

Also, here are additional instructions on another method that you could try that I found on a Knowledgebase on our website. This will work for you if you have Measurement Studio installed.  If not, there is another article linked to it that will be helpful and gives step by step instructions.

Message Edited by Kelly R on 03-03-2010 06:18 PM
Cheers,
Kelly R.
Applications Engineer
National Instruments
0 Kudos
Message 7 of 11
(3,872 Views)

Thanks, Kelly.  The instruction you point to is exactly of what I did, except I am not able step into the .NET assembly code.

 

However, I did some troubleshoot by incrementally build the function with messageBox to check the variables.  I come down to the the following code:

 

 

STDMETHODIMP CTSDBLog::CloseConnection(IDispatch *seqContextDisp, IDispatch *optionsDisp)

{

    HRESULT result = S_OK;

    TS::SequenceContextPtr pContext(seqContextDisp);

    PRE_API_FUNC_CODE

    AFX_MANAGE_STATE(AfxGetStaticModuleState())

    if( m_pDatalink ) {

        SM::IInstrSessionMgrPtr pSMgr;

        SM::IInstrSessionPtr pSession;

 

        // Get Database Schema Name to create the unique Datalink property name

        TS::PropertyObjectPtr pOptions(optionsDisp);

        _bstr_t propName(EXECUTION_DATALINK_PROPERTY);

        _bstr_t schemaName = pOptions->GetValString("DatabaseSchema.Name", 0);

        if (!(!schemaName))

            propName += schemaName;

 

        // FindAndReplace '.' with '_' and any other odd characters

        MakeValidName(propName);

        m_pDatalink = 0;

 

        // Open session manager

        result = pSMgr.CreateInstance(__uuidof(SM::InstrSessionMgr));

        if (result)

            RAISE_ERROR_WITH_DESC(TSDBLogErr_SessionManagerError, result, "");

            pSession = pSMgr->GetInstrSession(propName, false);

        if( pSession )

            pSession->DetachData(DATALINK_ATTACH_NAME);

        else

            MessageBox(NULL,"unable to get session","DBLog",0);

        m_dLastChangeCount++;

    }

    POST_API_FUNC_CODE(IID_ITSDBLog, pContext->Engine)

 }

 

This code builds, and closes the database file.  However, because this is my first attemp trying to modify the TestStand DLL, I wonder, if is possible, that you can help to review the code and see if I missed anything.

 

Thanks.

 

Peggy

 

 

 

0 Kudos
Message 8 of 11
(3,866 Views)

Hi Peggy,

 

Just to clarify, you were able to successfully build the code, close the database connection, and achieve your original task, correct?

Cheers,
Kelly R.
Applications Engineer
National Instruments
0 Kudos
Message 9 of 11
(3,806 Views)

I think so, as I can see Access' temporary file closed.

 

Peggy

0 Kudos
Message 10 of 11
(3,804 Views)