problem dealing with unicode in mexFunction
1 view (last 30 days)
Show older comments
I made a mexfunction to find the Hwnd of a window if its wiindow title matches a string. This was done by using a mexFunction "getWinHwnd.cc". E.g., After mex 'getWinHwnd', in matlab call getWinHwnd('untitled - notepad.exe') will get the hwnd number of a window: untitled - notepad.exe .
The problem is that if the window title has non-ascii unicode characters, the hwndNew = FindWindow(NULL,TEXT(windowNameBuf)) failed. I do not know where is the problem. Thanks in advance.
#include <windows.h>
#include "mex.h"
// The gateway routine
void mexFunction(int nlhs, mxArray *plhs[],
int nrhs, const mxArray *prhs[])
{
// Input argument is a buffer to hold the window name
mxArray *Reply = NULL;
char *windowNameBuf;
mwSize buflen1;
const mxArray *string_array_ptr1 = prhs[0];
buflen1 = mxGetNumberOfElements(string_array_ptr1) + 1;
windowNameBuf = (char *) mxCalloc(buflen1, sizeof(char));
mxGetString(string_array_ptr1, windowNameBuf, buflen1);
// Call the C subroutine.
HWND hwndNew = FindWindow(NULL,TEXT(windowNameBuf));
Reply = mxCreateNumericMatrix(1, 1, mxUINT64_CLASS, mxREAL);
*(uint64_T *) mxGetData(Reply) = (uint64_T) hwndNew;
plhs[0] = Reply;
}
0 Comments
Accepted Answer
More Answers (0)
See Also
Categories
Find more on Write C Functions Callable from MATLAB (MEX Files) in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!