Hello all friends. I am a VB-API beginner. I want to know hoe to find
its constants for a API Declare. For example:
When we declare a function:
Private Declare Function RegCreateKey Lib "advapi32.dll" Alias
"RegCreateKeyA" (ByVal hKey As Long, ByVal lpSubKey As String,
phkResult As Long) As Long
Const ERROR_SUCCESS = 0&
Const ERROR_BADDB = 1009&
Const ERROR_BADKEY = 1010&
Const ERROR_CANTOPEN = 1011&
Const ERROR_CANTREAD = 1012&
Const ERROR_CANTWRITE = 1013&
Const ERROR_REGISTRY_RECOVERED = 1014&
Const ERROR_REGISTRY_CORRUPT = 1015&
Const ERROR_REGISTRY_IO_FAILED = 1016&
Const HKEY_CLASSES_ROOT = &H80000000
Const HKEY_CURRENT_USER = &H80000001
Const HKEY_LOCAL_MACHINE = &H80000002
The questions are:
1. Why we just make those constants in the code?
2. What is relevance with those constants and this API function?
3. How can I find which constants will be used in a API function?
4. I´ve heard that in the C++ head file (.h file) can be found this
relation, but I don´t know hoe to find it yet.
5. Do you have any tools to refer it? The VB API viewer can find those
Declares, but I can´t find each API will use which constants.
Waiting you answer.thank you!!
Best Regards.
Simon
VB installs an API Viewer.
Go to Options then to AddIn Manager. Click on that and look for VB6 API
Viewer. Double click on that and click okay.
Then go back to options and you'll find it down at the bottom.
You'll have to open the WINAPI 32 text file and then select Constants from
the dropdown box.
Hello all friends. I am a VB-API beginner. I want to know hoe to find
its constants for a API Declare. For example:
When we declare a function:
Private Declare Function RegCreateKey Lib "advapi32.dll" Alias
"RegCreateKeyA" (ByVal hKey As Long, ByVal lpSubKey As String,
phkResult As Long) As Long
Const ERROR_SUCCESS = 0&
Const ERROR_BADDB = 1009&
Const ERROR_BADKEY = 1010&
Const ERROR_CANTOPEN = 1011&
Const ERROR_CANTREAD = 1012&
Const ERROR_CANTWRITE = 1013&
Const ERROR_REGISTRY_RECOVERED = 1014&
Const ERROR_REGISTRY_CORRUPT = 1015&
Const ERROR_REGISTRY_IO_FAILED = 1016&
Const HKEY_CLASSES_ROOT = &H80000000
Const HKEY_CURRENT_USER = &H80000001
Const HKEY_LOCAL_MACHINE = &H80000002
The questions are:
1. Why we just make those constants in the code?
2. What is relevance with those constants and this API function?
3. How can I find which constants will be used in a API function?
4. I´ve heard that in the C++ head file (.h file) can be found this
relation, but I don´t know hoe to find it yet.
5. Do you have any tools to refer it? The VB API viewer can find those
Declares, but I can´t find each API will use which constants.
Waiting you answer.thank you!!
Best Regards.
Simon
Ken Halter - 21 Mar 2007 23:21 GMT
> VB installs an API Viewer.
That's really old and contains errors. Here's a "better" API Viewer here
that contains declarations for Win2k/XP, as well as the Win95 vintage
declarations found in the "stock" viewer.
http://www.activevb.de/rubriken/apiviewer/index-apiviewereng.html

Signature
Ken Halter - MS-MVP-VB - Please keep all discussions in the groups..
In Loving Memory - http://www.vbsight.com/Remembrance.htm
Hello all friends. I am a VB-API beginner. I want to know hoe to find
its constants for a API Declare. For example:
When we declare a function:
Private Declare Function RegCreateKey Lib "advapi32.dll" Alias
"RegCreateKeyA" (ByVal hKey As Long, ByVal lpSubKey As String,
phkResult As Long) As Long
Const ERROR_SUCCESS = 0&
Const ERROR_BADDB = 1009&
Const ERROR_BADKEY = 1010&
Const ERROR_CANTOPEN = 1011&
Const ERROR_CANTREAD = 1012&
Const ERROR_CANTWRITE = 1013&
Const ERROR_REGISTRY_RECOVERED = 1014&
Const ERROR_REGISTRY_CORRUPT = 1015&
Const ERROR_REGISTRY_IO_FAILED = 1016&
Const HKEY_CLASSES_ROOT = &H80000000
Const HKEY_CURRENT_USER = &H80000001
Const HKEY_LOCAL_MACHINE = &H80000002
The questions are:
1. Why we just make those constants in the code?
2. What is relevance with those constants and this API function?
3. How can I find which constants will be used in a API function?
4. I´ve heard that in the C++ head file (.h file) can be found this
relation, but I don´t know hoe to find it yet.
5. Do you have any tools to refer it? The VB API viewer can find those
Declares, but I can´t find each API will use which constants.
-------------------------
Most of your questions can be answered by consulting the Platform SDK, but I
don't understand #1. The Platform SDK is the documentation for programming
in Windows. There are actually many SDKs, each for a specific topic. For
example, there's a DirectX SDK, Windows Media SDK, Windows Installer SDK,
etc. These are all available online and all can also be downloaded for local
installation on your computer (most of them free downloads, but a few SDKs
require an MSDN subscription).
Here's a link to the online documentation for RegCreateKey:
http://msdn2.microsoft.com/en-us/library/ms724842.aspx
You frequently have to go to other "pages" for more information and
sometimes even do more than that. For example, the docs state the function
returns ERROR_SUCCESS if successful and that if if fails, it returns a
non-zero error code defined in winerror.h. So you need to have winerror.h
and open it up and then really just look through it. It's harder for VB
programmers because the Platform SDK (and most SDKs) are documented for
C/C++ programmers.
Another thing...at the bottom of the documentation, there will be
information that tells you what Windows platforms support the function, the
library which exports the function, and the header file(s).

Signature
Mike
Microsoft Visual Basic MVP
> The questions are:
> 1. Why we just make those constants in the code?
Writing
Const HKEY_CLASSES_ROOT = &H80000000
and
RegCreateKey(HKEY_CLASSES_ROOT, ...)
instead of
RegCreateKey(&H80000000, ...)
makes it much easier to read the code and understand it.
If used several times the declaration of the constant can be moved to the
common declaration part of the VB module and so will reside in the compiled
executable only once.
And last but not least: If someday you will find that &H80000000 isn't the
right value and has to be changed to e.g. &H80000001 it is much easier to
do this when HKEY_CLASSES_ROOT has been used in the code and not
&H80000000.
> 2. What is relevance with those constants and this API function?
You will learn more about the relevance when reading the MSDN documention
on RegCreateKey(). A sample citation:
"...
Parameters
hKey
Identifies a currently open key or any of the following predefined
reserved handle values:
HKEY_CLASSES_ROOT
HKEY_CURRENT_USER
...
Return Values
If the function succeeds, the return value is ERROR_SUCCESS.
If the function fails, the return value is a nonzero error code defined in
WINERROR.H", i.e. an error code for which the ERROR_* constants may be
used.
> 3. How can I find which constants will be used in a API function?
Again: Read the MSDN documentation on the function you want to use.
> 4. I´ve heard that in the C++ head file (.h file) can be found this
> relation, but I don´t know hoe to find it yet.
No, the relation between API function and constant(s) usually can't be seen
from a C/C++ header file. Only in very rare cases you will find any
comments on the usage of constants and API functions in these header files.
They are usefull for a VB programmer only in that they will provide you
with the necessary declaration of the API functions and the values of API
constants.
> 5. Do you have any tools to refer it? The VB API viewer can find those
> Declares, but I can´t find each API will use which constants.
No, I don't know any tool which will show you the relation between an API
function and a constant. You have to fetch this piece of information from
the MSDN documentation on the API function.

Signature
----------------------------------------------------------------------
THORSTEN ALBERS Universität Freiburg
albers@
uni-freiburg.de
----------------------------------------------------------------------