Hello community. I am writing a program that will use multiple threads to run MATLAB functions inside of Cpp by using the MATLAB compiler to create a DLL. I have already written the MATLAB DLL and I have everything linked up just fine, but now I need to split this program into multiple threads (one for 'real time' data collection and the other for 'signal smoothing'). I have been told by my boss man that I need to use cWinThread (worker threads) in order to do this. I was wondering if anyone could tell me how to interface with the MFC libraries in my console application?

here is my preprocessor:

#include <cstdio>
#include "procSinkLib.h"
//#include <afx.h> why can't I include this without errors?

when I try to #include afx.h so that I can build threads via AfxBeginThread I get the following error:
afxv_w32.h(16) : fatal error C1189: #error : WINDOWS.H already included. MFC apps must not #include <windows.h>

well fine... so I go into afxv_w32.h and comment out windows.h... no dice It still throws the error.

here is what I'm attempting to put into a thread:

//the thread that eats processor
int callProcessThread(void){
         double mins = 0;
         std::cout << "How many minutes? ";
         std::cin >> mins;
         
      mxDouble flips(-1.);
      int nlhs = 4, nrhs = 4;

      mwArray output(1,1,mxDOUBLE_CLASS, mxREAL);
      mwArray input(1,1,mxDOUBLE_CLASS,mxREAL);
	  mxDouble mxMin(mins);

      input.SetData(&mxMin,1);

	  //this guy needs to go into a cWinThread worker thread...
	  procsink(1, output, input);

      output.GetData(&flips,1);
      std::cout << "Inversions: " << flips << std::endl;

         return 0;
}

any ponters or help would be greatly appreciated. Thank you for your time.

>>when I try to #include afx.h so that I can build threads via AfxBeginThread I get the following error:

why are you including afx.h ? If you are using a Microsoft compiler and using precompiled headers then that is already included in stdafx.h

>>I was wondering if anyone could tell me how to interface with the MFC libraries in my console application?

Microsoft compilers can generate a console program that accesses SOME MFC (but not all). Console programs are limited to using only no-GUI related MFC classes, such as CString and CFile.

If you want to create threads in a console application use the win32 api function CreateThread().

Problem is the boss wants cWinThreads.... cos of their built-in thread safeties.

do I need to #include stdafx.h ? VS 2k5 professional edition keeps telling me I don't have that library...

Using VC++ 6.0 you can create a console program that supports MFC. This is what the VC++ 6.0 IDE creates in stdafx.h

// stdafx.h
#define VC_EXTRALEAN		// Exclude rarely-used stuff from Windows headers

#include <afx.h>
#include <afxwin.h>         // MFC core and standard components
#include <afxext.h>         // MFC extensions
#include <afxdtctl.h>		// MFC support for Internet Explorer 4 Common Controls
#ifndef _AFX_NO_AFXCMN_SUPPORT
#include <afxcmn.h>			// MFC support for Windows Common Controls
#endif // _AFX_NO_AFXCMN_SUPPORT

#include <iostream>

And this is the *.cpp file it generates

/////////////////////////////////////////////////////////////////////////////
// The one and only application object
#include "stdafx.h"

CWinApp theApp;

using namespace std;

int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
	int nRetCode = 0;

	// initialize MFC and print and error on failure
	if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
	{
		// TODO: change error code to suit your needs
		cerr << _T("Fatal Error: MFC initialization failed") << endl;
		nRetCode = 1;
	}
	else
	{
		// TODO: code your application's behavior here.
		CString strHello;
		strHello.LoadString(IDS_HELLO);
		cout << (LPCTSTR)strHello << endl;
	}

	return nRetCode;
}

Using the above program you can test for yourself whether it will support CWinThread or not.

Neat. I couldn't find an option to create an MFC console application when I was looking. Do you just create a win32 app and there's some setting I'm missing somewhere?

*runs off to try that*

Do you just create a win32 app and there's some setting I'm missing somewhere?

*runs off to try that*

yeah... it's a check box, you dope. Hey! Don't insult me! o.O

Neat. I couldn't find an option to create an MFC console application when I was looking. Do you just create a win32 app and there's some setting I'm missing somewhere?

*runs off to try that*

That option exists in VC++ 6.0, I don't know if they removed in in 2005 or not. All it is is a standard console application (NOT a win32 application) with the files as I posted.

This question has already been answered. Start a new discussion instead.