NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

I want to use the expression edit control in a VC++ DLL, how?

Solved!
Go to solution

Good morning,

 

as mentioned I want to use the expression edit control in my DLL written with VSC++ 2005 MFC. But I ran into some problems:

If I just add the ExpressionEdit control from the toolbar to my dialog then the dialog will not be shown during runtime. As soon as I delete the control the dialog shows up.

In the TS examples is one called 'TCL' (...National Instruments\TestStand 4.1.1\Examples\Tcl\source\EditSubstep). This is programmed in C++ and uses the expression edit control.

The original dll works fine but as soon as I compile the editsubstep with my VS 2005 I get a runtime error (see image).

 

What do i have to do to be able to use this control?

Has anybody an working example for me?

 

Cheers Frank

0 Kudos
Message 1 of 9
(3,697 Views)

Hi,

 

maybe you are using the worng libs

VC7 = Visual Studio 2003

VC8 = Visual Studio 2005

try to use the libs from VC8.

 

Also try to set some break-points to find out which parent function calls this assert

or if this is nor possible i would use a log-file.

 

Hope this helps

 

juergen

 

 

--Signature--
Sessions NI-Week 2017 2016
Feedback or kudos are welcome
0 Kudos
Message 2 of 9
(3,646 Views)

Dialogs which contain ActiveX controls must be run in an STA (Single Threaded Apartment) thread. This is a requirement of COM/ActiveX. If your dll is specified as an editsubstep and you invoke the edit substep on a step, TestStand automatically uses an STA thread to make the call so that ActiveX controls on edit substep dialogs will work, however if you are calling your DLL directly from a sequence, TestStand defaults to using an MTA (Multithreaded Apartment) thread. You can specify that TestStand call a sequence in an STA thread instead of an MTA thread by using a sequence call step set to call a sequence in a new thread and by specifying the advanced setting "Use Single-Threaded Apartment". If you want the calling sequence to wait for the new thread to finish before continuing you should also use a Wait step after the sequence call to wait for the new thread which you have created.

 

Hope this helps,

-Doug

0 Kudos
Message 3 of 9
(3,630 Views)

Hello!

 

Did the postings above solve the problem, or do i have to do further investigations?

 

Regards

Moritz M.

0 Kudos
Message 4 of 9
(3,626 Views)

@juergen: how do I know which lib I am using?

I am using this COM-Control: c:\programme\national Instruments\testStand 4.1.1\bin\exprEdit.dll

 

@Doug: I created the sequence as you described and used this for debugging to find out where the problem is.

 

I found out, that the problem must be somewhere here:

dlgcore.cpp

BOOL CWnd::CreateDlgIndirect(LPCDLGTEMPLATE lpDialogTemplate,

CWnd* pParentWnd, HINSTANCE hInst)

Line 314:

hWnd = ::CreateDialogIndirect(hInst, lpDialogTemplate,

pParentWnd->GetSafeHwnd(), AfxDlgProc);

 

Without the ExpEdit-control hWnd has a Value

with control hWnd is 0.

 

This is what I found out so far.

Frank

0 Kudos
Message 5 of 9
(3,610 Views)

Frank,

 

Using an STA thread is the way to make the dialog work, not for debugging. Did it work when you put the call to your dll in a separate sequence and called that sequence from a new thread with the "Single-Threaded Apartment" advanced option on the sequence call set? CreateDialogIndirect failing is consistent with this issue if you are calling your dialog from an MTA thread instead of an STA thread. It is just a fundamental requirement of ActiveX controls (of which the expression control is one) that their containers/dialogs be created in an STA thread.

 

-Doug

0 Kudos
Message 6 of 9
(3,599 Views)
No it didn't work neither as editstep (this is what I actually want to do) nor with STA thread sequence call
Message Edited by frankne on 06-11-2009 09:55 AM
0 Kudos
Message 7 of 9
(3,591 Views)

Ah ok. It's not the threading model then. Would it be possible for you to attach example code, project, and sequence to this post that reproduces the problem?

 

Thanks,

-Doug

0 Kudos
Message 8 of 9
(3,577 Views)
Solution
Accepted by topic author frankne

Hi, I found the solution and now it works fine.

I just had to enable support for OLE controls in my dll.

 

Nevertheless thanks for your help!!

 

 

BOOL CMyDLLApp::InitInstance()

{

CWinApp::InitInstance();

AfxEnableControlContainer();  //enable support for OLE controls

return TRUE;

}

 

Cheers Frank

Message 9 of 9
(3,563 Views)