Using Dlls and The Windows Api: Dr. John Nosek
Using Dlls and The Windows Api: Dr. John Nosek
Select the type of item you want to view from the API Types list.
To add procedures to your Visual Basic code
•Click the procedure you want to copy in the
Available Items list.
•To remove all entries from the Selected Items list box,
click Clear.
To copy the selected items to the clipboard
End Sub
Window Handles
• Windows shorthand ID for an object
• read only property - hWnd
• Accessed only at run time
• Pass to API call to identify object to
perform some action.
Passing Parameters
• Important to declare ByVal if passing by
value - otherwise memory location used as
value
Using Classes with APIs
• Encapsulate functionality
• neater
• TestMM.vbp
mciSendString
The mciSendString function sends a command string
to an MCI device. The device that the command is sent to
is specified in the command string.
MCIERROR mciSendString(
LPCTSTR lpszCommand,
LPTSTR lpszReturnString,
UINT cchReturn,
HANDLE hwndCallback
);
Parameters
lpszCommand
Address of a null-terminated string that specifies an
MCI command string. For more information about
the command strings, see Command Strings.
lpszReturnString
Address of a buffer that receives return information.
If no return information is needed, this parameter
can be NULL.
cchReturn
Size, in characters, of the return buffer specified
by the lpszReturnString parameter.
hwndCallback
Handle of a callback window if the "notify" flag
was specified in the command string.
Callbacks
• The API function can reference a procedure
in your code while the API is running.
– Declare function the API will call as Public
– Use “AddressOf” in call to API
– Example:
– Public Function MyCallback…
– nResult = SomeAPIFunction(Param1,
AddressOf MyCallback)