Matlab API problems with DLL-file

15 vues (au cours des 30 derniers jours)
Michael Neumann
Michael Neumann le 7 Juil 2017
i want to use a api with Matlab. I have a DLL-File where I use functions for my interface in Matlab but I can't load the dll-file.
this is what I receive: Warning: Message from C preprocessor: C:\Program Files... warning: #pragma once in main file
pragma once
^
In loadlibrary In MI_LoadDLL (line 25) then many of this: Function pointer types are unsupported in structures HRESULT ( * QueryInterface )( ILayoutStorage * . Found on line 44385 of input from line 13358 of file C:/ProgramData/MATLAB/SupportPackages/R2017a/MW_MinGW_4_9/x86_64-w64-mingw32/include/objidl.h
and this:
Failed to parse type '( cdecl )) MI_HasLastError (' original input '( cdecl )) MI_HasLastError (' Found on line 63515 of input from line 88 of file C:\Program Files\... Error parsing argument for function attribute function may be invalid
my script:
if libisloaded('DLL-Datei')
Success = 1;
else
Success = 0;
% Looking for the necessary files.
path(path,'C:\..\');
if exist('Datei.dll','file')==0 || exist('Datei.h','file')==0
error(['Please copy all Datei.dll and Daatei.h to the same folder as "Programm.exe" (usually "C:\...\").']);
end;
% Loading the library.
disp('Loading Datei.dll ...')
[notfound, warnings] = loadlibrary('Datei', 'Datei.h');
if libisloaded('Datei')
Success = 1;
end;
end
if you have questions ask me. I don't now how to formate code so it could be good read.
sry guys but my English is unfortunately not so good but I hope u can help me. Every help would be nice! Thank you!

Réponses (2)

Manish Annappa
Manish Annappa le 10 Juil 2017
Modifié(e) : Manish Annappa le 10 Juil 2017
The error you are receiving when trying to load the DLL in MATLAB may be due to using a function pointer inside a struct in the header file, which is not supported in MATLAB. Some header files are not able to be properly read by MATLAB because they contain some non-standard function signatures or use syntax that MATLAB's parsing script fails to recognize. For more information, refer to the following documentation
Make sure you do not have above mentioned limitations in the shared library interface you are using. If you are following all the guidelines in the above link, then reply back with the following information.
  1. Item one MATLAB release (version) you are using
  2. Item two Bitness of MATLAB (32/64 - bit)
  3. Item three Shared library interface header file.
  1 commentaire
Eddie Irvine
Eddie Irvine le 5 Mai 2020
Modifié(e) : Eddie Irvine le 5 Mai 2020
Hi:) Any help is appreciated on using .NET functions and loading user32.dll, User32.h, WinUser.h, Windows.h to be used in MATLAB:
i) I am using Matlab2020a (Same problem as described below was seen in Matlab 2016a)
ii) Windows 10, 64bit
iii) Windows.h
iv) Windows SDK 10 is installed. Typing "mex -setup" in the Command Window gives:
"MEX configured to use 'Microsoft Visual C++ 2019 (C)' for C language compilation."
I try to load user32.dll but the library is loaded (instantly-in less than a second) with like infinitely many and similar messages like given below.
Before the messages I receive, this is my code (Attemp1):
--------------------------------------
mex -setup:C:\Users\User\AppData\Roaming\MathWorks\MATLAB\R2020a\mex_C++_win64.xml C++
addpath('C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um')
[nf,warn]=loadlibrary('C:\Windows\System32\user32.dll','C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\Windows.h','alias','user32')
screenSize=get(0,'ScreenSize');
calllib('user32','SetCursorPos',screenSize(3)/2,screenSize(4)/2); %center cursor on screen
--------------------------------------
Result is Error1 (I call it as Error1):
"Error using calllib
Method was not found."
--------------------------------------
libisloaded('user32') gives "1"
"nf" is "1×0 empty cell array"
"warn" gives a long list which is partially copy-pasted below.
--------------------------------------
Thank you for your interest,
EI
--------------------------------------
Note: If I continue with the lines below, after Error1 above, using C compiler, it takes like 2-3 minutes and produces so many errors (Attempt2). The error list obtained as a result of Attempt2 is given below the second line of '%%%' below:
--------------------------------------
unloadlib('user32')
mex -setup:C:\Users\User\AppData\Roaming\MathWorks\MATLAB\R2020a\mex_C_win64.xml C
addpath('C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um')
[nf,warn]=loadlibrary('C:\Windows\System32\user32.dll','C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\Windows.h','alias','user32')
--------------------------------------
Some part of the "warn" content as obtained after Attempt1 described above is given below between two discrete lines of '%%%' and '%%%' :
"warn" content after Attempt1:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Windows.h
...
Type 'intWCHAR__unalignedPtr' was not found. Defaulting to type voidPtr.
Found on line 12163 of input from line 524 of file C:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\um\winnt.h
Type 'intUCSCHAR__unalignedPtr' was not found. Defaulting to type voidPtr.
Found on line 12166 of input from line 527 of file C:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\um\winnt.h
Type 'intUCSCHAR__unalignedPtr' was not found. Defaulting to type voidPtr.
Found on line 12168 of input from line 529 of file C:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\um\winnt.h
Type 'intUCSCHAR__unalignedPtr' was not found. Defaulting to type voidPtr.
Found on line 12169 of input from line 530 of file C:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\um\winnt.h
found parens in LowPart ; LONG HighPart ; } ; struct { DWORD LowPart ; LONG HighPart ; } u ; LONGLONG QuadPart ; } LARGE_INTEGER
Match: DWORD LowPart ; LONG HighPart ;
Final string:LowPart ; LONG HighPart ; } ; struct u ; LONGLONG QuadPart ; } LARGE_INTEGER
Failed to parse type 'union _LARGE_INTEGER { struct { DWORD LowPart ; LONG HighPart ; } ; struct { DWORD LowPart ; LONG HighPart ; } u ; LONGLONG QuadPart ; } LARGE_INTEGER' original input 'union _LARGE_INTEGER { struct { DWORD LowPart ; LONG HighPart ; } ; struct { DWORD LowPart ; LONG HighPart ; } u ; LONGLONG QuadPart ; } LARGE_INTEGER'
Found on line 12491 of input from line 852 of file C:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\um\winnt.h
Type 'LARGE_INTEGERPtr' was not found. Defaulting to type voidPtr.
Found on line 12494 of input from line 855 of file C:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\um\winnt.h
found parens in LowPart ; DWORD HighPart ; } ; struct { DWORD LowPart ; DWORD HighPart ; } u ; ULONGLONG QuadPart ; } ULARGE_INTEGER
Match: DWORD LowPart ; DWORD HighPart ;
Final string:LowPart ; DWORD HighPart ; } ; struct u ; ULONGLONG QuadPart ; } ULARGE_INTEGER
Failed to parse type 'union _ULARGE_INTEGER { struct { DWORD LowPart ; DWORD HighPart ; } ; struct { DWORD LowPart ; DWORD HighPart ; } u ; ULONGLONG QuadPart ; } ULARGE_INTEGER' original input 'union _ULARGE_INTEGER { struct { DWORD LowPart ; DWORD HighPart ; } ; struct { DWORD LowPart ; DWORD HighPart ; } u ; ULONGLONG QuadPart ; } ULARGE_INTEGER'
Found on line 12511 of input from line 872 of file C:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\um\winnt.h
Type 'ULARGE_INTEGERPtr' was not found. Defaulting to type voidPtr.
Found on line 12514 of input from line 875 of file C:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\um\winnt.h
found parens in __C_ASSERT__ [((( LONG )( LONG_PTR )&((( struct { char x ; LARGE_INTEGER test ; } *) 0 )-> test )) == 8 )? 1 :- 1 ]
Match: char x ; LARGE_INTEGER test ;
Final string:__C_ASSERT__ [((( LONG )( LONG_PTR )&((( struct *) 0 )-> test )) == 8 )? 1 :- 1 ]
No match found for enum value expression LONG in ((( LONG )( LONG_PTR )&((( struct { char x ; LARGE_INTEGER test ; } *) 0 )-> test )) == 8 )? 1 :- 1 expression ignored.
Found on line 15852 of input from line 2487 of file C:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\um\winnt.h
Failed to parse type 'struct ) _M128A { ULONGLONG Low ; LONGLONG High ; } M128A' original input 'struct ) _M128A { ULONGLONG Low ; LONGLONG High ; } M128A '
Found on line 15946 of input from line 2581 of file C:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\um\winnt.h
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
ATTEMPT2 ERRORS BELOW:
PART OF THE ERRORS (PART OF THOSE REMAINING IN THE COMMAND WINDOW - I guess the list is much longer since I cannot see my code lines for Attempt2 anymore when I go to the top line in the command window): A long list like:
^~~~~~~~~~~~~~~~~~~~~~
C:\Program
Files
(x86)\Windows
Kits\10\Include\10.0.18362.0\um/winnt.h:15782:27:
error:
declaration
for
parameter
'PPOWER_SESSION_CONNECT'
but no
such
parameter
}
POWER_SESSION_CONNECT,
*PPOWER_SESSION_CONNECT;
^~~~~~~~~~~~~~~~~~~~~~
C:\Program
Files
(x86)\Windows
Kits\10\Include\10.0.18362.0\um/winnt.h:15782:3:
error:
declaration
for
parameter
'POWER_SESSION_CONNECT'
but no
such
parameter
}
POWER_SESSION_CONNECT,
*PPOWER_SESSION_CONNECT;
^~~~~~~~~~~~~~~~~~~~~
and more listed errors like
:/ProgramData/MATLAB/SupportPackages/R2020a/3P.instrset/mingw_w64.instrset/x86_64-w64-mingw32/include/basetsd.h:30:24:
error: declaration for parameter 'INT16' but no such parameter
typedef signed short INT16,*PINT16;
^~~~~
C:/ProgramData/MATLAB/SupportPackages/R2020a/3P.instrset/mingw_w64.instrset/x86_64-w64-mingw32/include/basetsd.h:29:29:
error: declaration for parameter 'PINT8' but no such parameter
typedef signed char INT8,*PINT8;
^~~~~
C:/ProgramData/MATLAB/SupportPackages/R2020a/3P.instrset/mingw_w64.instrset/x86_64-w64-mingw32/include/basetsd.h:29:23:
error: declaration for parameter 'INT8' but no such parameter
typedef signed char INT8,*PINT8;
^~~~
user32_thunk_pcwin64.c:28:0: error: expected '{' at end of input
#ifdef LCC_WIN64
>>

Connectez-vous pour commenter.


Michael Neumann
Michael Neumann le 14 Juil 2017
Hi,
i solve this problem now. I just installed an older version of matlab and visual studio 2010. Then it works. So my Question now is: Is there a way to run the DLL with Matlab 2017a and Visual Studio 2017. Or i have to change the Header-File and the DLL to make it run on Matlab 2017a ? Thank you for your help !!!

Catégories

En savoir plus sur Argument Definitions dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by