About Site Map Submit Contact Us Log in | Create an account
Create an account Log In
Average Rating
User Rating:
Visitors Rating:
My rating:

Write review
  • Last update: 5 years ago
  • Total downloads: 68
  • Operating system: Linux, Mac OS X, Win All, BSD, Solaris
  • Publisher: Jim Glidewell
See full specifications

scripts default iconCalling MFC from mex functions (Scripts) Publisher's description

I recently had a requirement to make MFC calls within a mex function

I recently had a requirement to make MFC calls within a mex function. After looking around I was unable to find a single example, so I had to develop my own. Hopefully this will make the job easier for you. The procedure is actually pretty easy once you know how. This discussion assumes that you already know how to write mex functions and are famliar with MFC.

This simple demo creates a mex function called "mexDemo", which passes a single number as an argument. This data is then displayed in a dialog box. The user can modify the number and then hit "OK". This new value is then returned to MATLAB.

First, in order to process MFC messages you need a CWinApp class. Because both the mex Function and the CWinApp class require their own dll entry point, I couldn't find a way to put them both in the same file, so I had to create two separate dll's, the mex function and the actual MFC dll.

The demo contains three files. "mexDemo" defines the mex funtion. This simply takes the value passed in, calls the dialog, and then returns the new value.

The file "mexDialogDemo" defines the CWinApp class. To create this class simply create a new project by selecting "MFC AppWizard (dll). You can choose either static or dynamic linking. I choose static so that the MFC code will be self-contained.

The file "mexDialog" defines the dialog and is the most important part since this provides the interface to the mex function. This dialog was added to the mexDialogDemo program like any other dialog would be.

Access to the dialog is provided through an export function call "mexDialog", which in turn brings up the dialog. This intermediate function is required because the mex function cannot directly call the dialog.

This export function must be declared as a C callable dllexport function:

#ifdef __cplusplus
extern "C"{

__declspec (dllexport) float mexDialog (float data)
CmexDialog dlg;
dlg.m_data = data;
data = dlg.m_data;
return data;
#ifdef __cplusplus

This function must also be declared within the mex function, but this time it is declared as an import function:

#ifdef __cplusplus
extern "C"{

__declspec (dllimport) float mexDialog(float data);

#ifdef __cplusplus

This dll function is called from within the mex function just like any other function:

data2 = mexDialog (data1);

System Requirements:

MATLAB 7.8 (R2009a)
Program Release Status: New Release
Program Install Support: Install and Uninstall

Calling MFC from mex functions (Scripts) Tags:

Click on a tag to find related softwares

Is Calling MFC from mex functions (Scripts) your software?

Manage your software

Most Popular

scripts default icon ASK, OOK, FSK, BPSK, QPSK, 8PSK modulation 1.1
ASK, OOK, FSK, BPSK, QPSK, 8PSK modulation contain several functions for digital modulation simulation
scripts default icon Simulink Communication Labs 1.1
Simulink Communication Labs allows you to learn communication systems in greater depth.
scripts default icon M-QAM modulation and demodulation 1.1
M-QAM modulation and demodulation is the QAM modulation and demodulation tech.
scripts default icon LZW Compression/Decompression 1.1
LZW Compression/Decompression - Updated LZW compressor and decompressor with reasonable performance
scripts default icon InSPIRE utility to plot a 2D displacement field (Scripts) 1.0
This program plots the deformation field (displace vectors) contained in vector.txt.