Call questdlg from C S-Function

6 views (last 30 days)
Hello, Is it possible to call questdlg(...) from within a simple C S-Function AND get the resulting answer? Please provide an example. Thank You
  1 Comment
Allen Peacock
Allen Peacock on 14 Apr 2014
Hello and thanks for the quick response. I have followed your reference and this is what I produced:
#include "mex.h"
void
mexFunction( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
mxArray *lhs[1];
char sArray[15] = "Are you sure?";
(void) prhs; /* unused parameter */
/* Check for proper number of input and output arguments */
if (nrhs != 0) {
mexErrMsgTxt("No input arguments required.");
}
if(nlhs > 1){
mexErrMsgTxt("Too many output arguments.");
}
/* Display a question dialog & get response */
mexCallMATLAB(1, lhs, 1, sArray, "questdlg");
}
It mex's without error. Unfortunately I get a Stack Dump/Trace when calling it. Not sure why it fails. Can you help?

Sign in to comment.

Accepted Answer

A Jenkins
A Jenkins on 14 Apr 2014
You can use mxCreateString to hold your string value.
#include "mex.h"
void
mexFunction( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
mxArray *lhs[1];
mxArray *pArray;
const char sArray[] = "Are you sure?";
/* Check for proper number of input and output arguments */
if (nrhs != 0) {
mexErrMsgTxt("No input arguments required.");
}
if(nlhs > 1){
mexErrMsgTxt("Too many output arguments.");
}
/* Create a string array. */
pArray = mxCreateString(sArray);
/* Display a question dialog & get response */
mexCallMATLAB(1, lhs, 1, &pArray, "questdlg");
/* Write the output back to MATLAB */
plhs[0] = lhs[0];
/* When finished with the string array, free its memory. */
mxDestroyArray(pArray);
}
  1 Comment
Allen Peacock
Allen Peacock on 14 Apr 2014
Perfect! It worked like a charm. Thanks A Jenkins.

Sign in to comment.

More Answers (1)

Kaustubha Govind
Kaustubha Govind on 31 Mar 2014
Yes, you can use mexCallMATLAB to call MATLAB functions from a C-MEX S-function. Please refer to the examples in the documentation.
  1 Comment
Allen Peacock
Allen Peacock on 14 Apr 2014
Sorry, I may have put my response/question in the wrong spot. Here it is again: Hello and thanks for the quick response. I have followed your reference and this is what I produced:
#include "mex.h"
void
mexFunction( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
mxArray *lhs[1];
char sArray[15] = "Are you sure?";
(void) prhs; /* unused parameter */
/* Check for proper number of input and output arguments */
if (nrhs != 0) {
mexErrMsgTxt("No input arguments required.");
}
if(nlhs > 1){
mexErrMsgTxt("Too many output arguments.");
}
/* Display a question dialog & get response */
mexCallMATLAB(1, lhs, 1, sArray, "questdlg");
}
It mex's without error. Unfortunately I get a Stack Dump/Trace when calling it. Not sure why it fails. Can you help?

Sign in to comment.

Categories

Find more on Write C Functions Callable from MATLAB (MEX Files) in Help Center and File Exchange

Tags

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!