problem dealing with unicode in mexFunction
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!