unable to call windows API "FindWindow" and errors in using calllib

10 ビュー (過去 30 日間)
QiQin Zhan
QiQin Zhan 2015 年 3 月 19 日
コメント済み: QiQin Zhan 2015 年 3 月 22 日
I want to use the windows api of "FindWindow" to get the handle of an opened window. The following is the code.
addpath('C:\WINDOWS\system32');
addpath('C:\Program Files (x86)\Windows Kits\8.0\Include\um');
loadlibrary('user32.dll', 'Windows.h','alias','user');
libfunctions('user','-full')
calllib('user','FindWindow','SunAwtCanvas','MATLAB R2014b');
unloadlibrary('user')
But somehow when I want to list the functions contained in user32 using the "libfunctions", Matlab tells me that "No methods for class lib.user". And then an error comes out:
Error using calllib
Method was not found.
It confuses me a lot. What's wrong with calllib? Any suggestions would be appreciated.

採用された回答

Philip Borghesani
Philip Borghesani 2015 年 3 月 20 日
編集済み: Philip Borghesani 2015 年 3 月 20 日
Loading a Windows dll via windows.h is not a simple task and is quite slow. The best solution for a few functions is to create you own header for the functions you wish to call and use that. For FindWindow this could just contain:
void * FindWindowA ( char* lpClassName , char * lpWindowName );
Note that the usable function from matlab is FindWindowA.
The reason you found no functions was that most of the functions in user32 are in the header "WinUser.h" which must be added with the addheader option to loadlibrary. I determined this by searching for FindWindow in all the windows headers. I was able to load many functions from user32.dll using this process:
  1. Create a prototype file: [nf,warn]=loadlibrary('user32.dll', 'C:\Program Files (x86)\Windows Kits\8.0\Include\um\windows.h','alias','user','includepath','C:\Program Files (x86)\Windows Kits\8.0\Include\um\','includepath','C:\Program Files (x86)\Windows Kits\8.0\Include\shared\','addheader','WinUser','mfilename','user_proto');
  2. Unload the library
  3. Edit the prototype file 'user_proto.m' to remove the first few functions that come through with calltypes of 'cdecl' and 'stdcall'
  4. Load the library:
[nf,warn]=loadlibrary('user32.dll', @user_proto,'alias','user');
In future MATLAB sessions only step 4 is needed.
  1 件のコメント
QiQin Zhan
QiQin Zhan 2015 年 3 月 22 日
Thank you for your answer and that's exactly what I want. Hope that those who meet the same problems will see your answer

サインインしてコメントする。

その他の回答 (1 件)

QiQin Zhan
QiQin Zhan 2015 年 3 月 20 日
Does anyone have some ideas?

カテゴリ

Help Center および File ExchangeC Shared Library Integration についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by