Measurement Studio for VC++

cancel
Showing results for 
Search instead for 
Did you mean: 

Calling NI objects from aa Afx thread

Hi,

I have a Dialog class in Visual c++ 2003 "TESTDlg.h and TestDlg.cpp"
In TestDlg.h i have publikc members:
public:
   CNiButton m_nbool1;
    CNiButton m_nbool2;
    CNiButton m_nbool3;
    CNiButton m_nbool4;
    CNiButton m_nbool5;
in TestDlg.cpp i have a worker thread: CWinThread* pThread = AfxBeginThread( MyFunc_, this, THREAD_PRIORITY_NORMAL, 0, 0,NULL);
MyFunc function gets the "this" pointer and obtains a reference to the Dialog.
I can access all the Public members within TestDlg but the NIButtons(although they are also public)
My code returns with error:
Unhandled exception at 0x7c812a5b in TestDlg.exe: Microsoft C++ exception: NI::CNiOleException @ 0x01bafb54.

How can i fix that?

0 Kudos
Message 1 of 5
(8,029 Views)
Lachezar,
 
Could you post a small example that demonstrate this behavior?
 
Regards,
 
Song D
Application Engineer
National Instrument
Regards,

Song Du
Systems Software
National Instruments R&D
0 Kudos
Message 2 of 5
(8,004 Views)
It is fixed now.I had to use :

//Main Worker Thread
UINT TestDlg::WorkerThread(LPVOID pParam)
{
 ::CoInitialize(NULL) ;//NI construct to allow controls from a Thread-Iput in the very beginning

//My code here

     ::CoUninitialize(); //NI construct to allow controls from a Thread - put this at the end of the thread

}

That fixed it!

0 Kudos
Message 3 of 5
(7,983 Views)

I realise that this is some time ago, but I'm working on a similar project and need some MFC assistance.

I've created a DLL with MFC, but I need to use Multithreading to collect some data.

Since all the calls look similar to

 

_declspec(dllexport) HRESULT __cdecl OpenPort ( unsigned char DeviceID )
{
 return ( m_pBrickInput->OpenDevice ( DeviceID ) );
}

 

I haven't had any reason to create any instances of the class.

Now, when I try to do this...

static void StartRead(void)
{
 CBrickApp *MyApp;

  MyApp = new (CBrickApp);
  MyApp->StartReader();
}

void CBrickApp::StartReader(void)
{
CWinThread  *pReaderThread;

//  this->Data.SetSize(0);

  pReaderThread = AfxBeginThread (ReadThread, (void *)this, THREAD_PRIORITY_HIGHEST,
          0, 0, NULL );

}

 

the MFC Linker complains...

 

Any suggestions ?

 

DOK 

 

0 Kudos
Message 4 of 5
(7,301 Views)

DOK has created a new forum post with this question. See this link for additional resources.

 

Measurement Studio for VC++ (http://forums.ni.com/ni/board/message?board.id=231&message.id=6360&jump=true#M6360)

 

Regards,

 

Steven Zittrower

Applications Engineer

National Instruments

http://www.ni.com/support

0 Kudos
Message 5 of 5
(7,288 Views)