Error: identifier "VOID" is undefined. When using mex to access c++ functions from winuser.h

5 vues (au cours des 30 derniers jours)
I want to use the tools that are provided inside winuser.h
For this i used the steps given in "Steps to Publish a MATLAB Interface to a C++ Library"
Since C++ code from VisualStudio only works with that compiler i use the Visual C++ 2022 Compiler. I had to install Visual Studio 20 as it was instructed with "2. Microsoft Visual C++ is included with Visual Studio Build Tools, Community, Professional, and Enterprise. The Visual Studio installers group functionality into workloads; the "Desktop development with C++" workload is required for MEX and associated functionality." at the end of the site:
When i test the compiler with the test case from the MinGW64 C++ compiler it works.
mex -setup CPP %sets up mex for C++
copyfile(fullfile(matlabroot,'extern','examples','mex','yprime.c'),'.','f') %Example file for Compiler testing
mex yprime.c %Compilation of example file
yprime(1,1:4) %Test of compiled function
% The stuff that matters:
% Here i am unsure wether it matters that there is a space in the Filepath
% There is a warning in the descripton of MinGW64 that this compiler should
% be installed on a path without spaces. However the example file works and on my System its called
% "Programme" without spaces because its german.
headerFile="C:\Program Files\MATLAB\R2024b\sys\lcc64\lcc64\include64\winuser.h";
libFile="C:\Program Files\MATLAB\R2024b\sys\lcc64\lcc64\lib64\user32.lib";
libName="winuser";
clibgen.generateLibraryDefinition(headerFile,"Libraries",libFile,"PackageName",libName);
When i try to compile winuser.h (with Visual C++ or MinGW) i get errors:
Errors parsing interface generation files.
C:\Program Files\MATLAB\R2024b\sys\lcc64\lcc64\include64\winuser.h(12):
error: identifier "HANDLE" is undefined
C:\Program Files\MATLAB\R2024b\sys\lcc64\lcc64\include64\winuser.h(13):
error: identifier "VOID" is undefined
C:\Program Files\MATLAB\R2024b\sys\lcc64\lcc64\include64\winuser.h(14):
error: identifier "VOID" is undefined
C:\Program Files\MATLAB\R2024b\sys\lcc64\lcc64\include64\winuser.h(20):
error: identifier "PVOID" is undefined
C:\Program Files\MATLAB\R2024b\sys\lcc64\lcc64\include64\winuser.h(21):
error: identifier "PVOID" is undefined
C:\Program Files\MATLAB\R2024b\sys\lcc64\lcc64\include64\winuser.h(27):
error: identifier "CALLBACK" is undefined
C:\Program Files\MATLAB\R2024b\sys\lcc64\lcc64\include64\winuser.h(27):
error: identifier "HWND" is undefined
C:\Program Files\MATLAB\R2024b\sys\lcc64\lcc64\include64\winuser.h(27):
error: identifier "UINT" is undefined
C:\Program Files\MATLAB\R2024b\sys\lcc64\lcc64\include64\winuser.h(27):
error: identifier "WPARAM" is undefined
C:\Program Files\MATLAB\R2024b\sys\lcc64\lcc64\include64\winuser.h(27):
error: identifier "LPARAM" is undefined
C:\Program Files\MATLAB\R2024b\sys\lcc64\lcc64\include64\winuser.h(27):
error: function returning function is not allowed
C:\Program Files\MATLAB\R2024b\sys\lcc64\lcc64\include64\winuser.h(45):
error: identifier "FARPROC" is undefined
C:\Program Files\MATLAB\R2024b\sys\lcc64\lcc64\include64\winuser.h(46):
error: identifier "FARPROC" is undefined
C:\Program Files\MATLAB\R2024b\sys\lcc64\lcc64\include64\winuser.h(47):
error: identifier "FARPROC" is undefined
C:\Program Files\MATLAB\R2024b\sys\lcc64\lcc64\include64\winuser.h(48):
error: identifier "FARPROC" is undefined
C:\Program Files\MATLAB\R2024b\sys\lcc64\lcc64\include64\winuser.h(49):
error: identifier "FARPROC" is undefined
C:\Program Files\MATLAB\R2024b\sys\lcc64\lcc64\include64\winuser.h(50):
error: identifier "FARPROC" is undefined
C:\Program Files\MATLAB\R2024b\sys\lcc64\lcc64\include64\winuser.h(51):
error: identifier "FARPROC" is undefined
C:\Program Files\MATLAB\R2024b\sys\lcc64\lcc64\include64\winuser.h(52):
error: identifier "FARPROC" is undefined
C:\Program Files\MATLAB\R2024b\sys\lcc64\lcc64\include64\winuser.h(53):
error: identifier "FARPROC" is undefined
I wasted so much time on this and now i honestly have no idea where to go from here.

Réponses (1)

Abhaya
Abhaya le 23 Déc 2024
Hi Alexander,
The datatypes HANDLE, VOID, FARPROC, etc., used in 'winuser.h' file, are defined across multiple files. As a result, when MATLAB ‘clibgen.generateLibraryDefinition’ function is trying to parse the ‘winuser.h’ file independently, it is not able to find the respective datatypes.
To resolve this issue and use the tools defined in ‘winuser.h’ file, you can follow these steps:
  • Create a new header file, for example, ‘example.h’.
  • Include ‘windows.h’ header file, as it contains all the necessary files and allows you to access the tools defined in ‘winuser.h’.
  • Use clibgen.generateLibraryDefinition(‘example.h’) to a definition file ‘defineexample.m’.
Refer to the code given below for a better understanding.
#include<windows.h>
//%accessing the types defined in winuser.h
typedef VOID TVOID;
typedef DLGPROC DG;
typedef HDWP PTR;
class Mat{
public:
TVOID setMat();
};
For more information on MATLAB 'clibgen.generateLibraryDefinition’ function, please refer to the following MATLAB documentation.
Hope this solves you query.

Catégories

En savoir plus sur MATLAB Compiler SDK dans Help Center et File Exchange

Produits


Version

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by