How can I access a library using LOADLIBRARY when the header file contains data types such as DWORD, HWND, LPSTR, BYTE, LPDWORD?

I want to use LOADLIBRARY to access a DLL. The header file that I have looks like this:
DWORD InitController (DWORD ControllerMode, HWND UserWin, UINT AsyncMsg);
DWORD SetDecimalSeparator(BYTE DecimalSep);
DWORD GetReply(LPSTR Reply);
DWORD GetError(LPDWORD Error);
When I try to load the library as follows:
[notfound,warnings] = loadlibrary('MyLib','MyLib.h')
I get a lot of warnings such as the following:
ERROR: Type 'DWORD' was not found. Defaulting to type error.
Found on line 1 of input from line 1 of file MyLib.h
Type 'HWND' was not found. Defaulting to type error.
Found on line 1 of input from line 1 of file MyLib.h
Type 'BYTE' was not found. Defaulting to type error.
Found on line 2 of input from line 1 of file MyLib.h
Type 'LPSTR' was not found. Defaulting to type error.
Found on line 3 of input from line 1 of file MyLib.h
Type 'LPDWORD' was not found. Defaulting to type error.
Found on line 4 of input from line 1 of file MyLib.h

 Accepted Answer

The data types DWORD, HWND, LPSTR, BYTE, LPDWORD are defined in the header file "windows.h". Therefore, a possible solution would be to include this header file as follows:
#include <windows.h>
Another solution would be to substitute these Windows' data types with regular primitive data types (long, int, etc.). To do this, consider the data types that have the "LP" prefix, which stands for "Long Pointer". All these data types can be replaced with the data type long. 
The data type BYTE needs to be handled in a special way, as described here:
"Because the architecture of the 80x86 stack is segmented into word boundaries, the smallest type pushed onto the stack will be a word. Therefore, both the BYTE and the integer will be pushed onto the stack in the same manner, and require the same amount of memory. This is the reason you can use an integer data type for a BYTE data type in these types of procedure calls."
So a possible solution in this case would be to add the following lines to the header file:
#define DWORD long
#define HWND long
#define BYTE int
#define LPSTR long
#define LPDWORD long

More Answers (0)

Products

Release

R2008a

Community Treasure Hunt

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

Start Hunting!