Results 1 to 3 of 3

Thread: a question about win API functions signatures

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2002
    Location
    india
    Posts
    1

    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?

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    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.

  3. #3
    Frenzied Member MerrionComputin's Avatar
    Join Date
    Apr 2001
    Location
    Dublin, Ireland
    Posts
    1,616
    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
    ----8<---------------------------------------
    NEW - The .NET printer queue monitor component
    ----8<---------------------------------------
    Now with Examples of use

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width