|
-
Feb 16th, 2002, 02:30 AM
#1
Thread Starter
New Member
a question about win API functions signatures
some of the win API functions contain parameters which are clearly marked as "by val".
But whatever modifications we do to these parameters can be seen in calling function(for example getusername function)
what is this peculiarity?
-
Feb 16th, 2002, 09:15 AM
#2
By Val and By Ref are used by APIs. You seldom see a By Ref (By Reference) because that is the default. If you do not explicitly pass something By Val (By Value) it will automatically be passed By Ref.
The difference is that a value passed By Val can not be changed. A value passed By Ref can be changed.
-
Feb 19th, 2002, 12:33 PM
#3
Frenzied Member
In the context of string data types in the API the keywords ByVal and ByRef have a special meaning.
This is because most API calls expect a C style null terminated string data type but internally VB string variables are stored as BSTR format.
If you see ByVal in a string parameter it means that VB will take a copy of the BSTR as a C string, copy the data in to it, call the API and then copy the result back.
Therefore if the API call definition wants a data type of LPSTR, LPCSTR or the like, use ByVal, if the data type is LPBSTR don't.
See also "The Visual Basic Programmer's Guide to the Win32 API" by Daniel Appleman - he explains this much more lucidly...
HTH,
Duncan
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|