Call skills between VB5.0 and Windows APIs

Source: Internet
Author: User
Tags integer

Generally use the window API, it is because the VB itself does not provide some features, but the program needs and must be, for example: Read the data in registry, VB only provide SaveSetting, GetSetting and other series of instructions, However, it can only read the values of a particular region, and it cannot be used to read, delete, or alter the values of other regions. Another example: Take a closer look at the events in combo box, where there is no mousemove, but this is often used on an event, then how? Yes, that's only through the Winodow API. And the VB Call Window API generally does not use API inspector, directly to the corresponding API copy to our program is good, that also use what skill? In fact, because of the VB data format problems, coupled with VB itself no indicators, in many places need some small skills to solve, and we often in response to different needs, the API inspector's announcement copy come over and make some changes, the most important, if there is a. DLL file, which is not defined in the API inspector, then you have to find a way to do it yourself.

One, the whole number of three

Windows API32 bit VB

============================== =============================

int, int ByVal Long

Unit, DWORD ByVal Long

BOOL ByVal Long ture to 1

WPARAM, LPARAM, Lresult ByVal Long

Handle (e.g. hkey) ByVal Long

WORD, ATOM, short ByVal Integer

Byte, CHAR ByVal byte

Eg.

-----------------------------------------------------------------------------

Windows API Declaration

Short getkeystate (int nvirtkey)

corresponding to the VB declaration

Declare Function getkeystate Lib "user32" (ByVal Nvirtkey as Long) as Integer

-----------------------------------------------------------------------------

This API can be used to view some key (such as Insert key, Num Lock, CapsLock, etc.) is on/off. The program is as follows: This example should be very clear to see the declaration correspondence between the integers.

-----------------------------------------------------------------------------
Dim InsertMode as Integer
InsertMode = GetKeyState(vbKeyInsert) And vbShiftMask
If InsertMode = 1 then
  Debug.print "表示 Insert Mode"
Else
  Debug.print "表示 OverWrite Mode"
End If
-----------------------------------------------------------------------------

Indicators to point to integers

Windows API 32-bit VB

============================ ==========================

Lpint (BYREF) Long

Lpunit (BYREF) Long

Lpbool (BYREF) Long

Lpdword (BYREF) Long

Lphandle (such as: Phkey) (BYREF) Long

Lpword (BYREF) Integer

Lpshort (BYREF) Integer

Lpbyte (BYREF) Byte

VB default is to use the address call, so byref can be omitted, that is to say

Func (ByRef param1 as type)

And

Func (param1 as type)

Is the same, the way to use a call is to pass the three numbers to the API and pass the results back. However, the long form of the call in VB also accounted for a considerable amount of weight, since the 32-bit metric is a long type, the structure of the string and the self-stereotypes are passed in metrics in the Windows API, and the passing of the metric is in fact a long value. But the long value of the past, in the win API will be used as an address, and then with the indicators to operate the content of the indicators, this concept will be very important in the back.

For example:

-----------------------------------------------------------------------------
LONG RegOpenKeyEx(
   HKEY    hKey,      // handle of open key
   LPCTSTR   lpszSubKey,   // address of name of subkey to open
   DWORD    dwReserved,   // reserved
   REGSAM   samDesired,   // security access mask
   PHKEY    phkResult    // address of handle of open key
  );
相对应的VB 宣告
Declare Function RegOpenKeyEx Lib "advapi32.dll" Alias "RegOpenKeyExA" _
     (ByVal hKey As Long, _
     ByVal lpSubKey As String, _
     ByVal ulOptions As Long, _
     ByVal samDesired As Long, _
     phkResult As Long) As Long  '//最後一个叁数是ByRef之宣告
-----------------------------------------------------------------------------

We often want to use programs to read data from registry, for example: what do we want to know about WIN95 's product ID? Here are a few ideas to be clear: first: where is ProductID? The ProductID under the Hkey_local_machine\software\microsoft\windows\currentverson. What we want to achieve is that key is HKEY_LOCAL_MACHINE

subkey for Software\microsoft\windows\currentverson

VALUENAME is the value of ProductId

However, to obtain the value of ProductID is not so direct, first to obtain subkey Keyhandle and Keyhandle is the use of Regquerykeyex API. The program part is introduced in the introduction of the win API string.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.