Results 1 to 2 of 2

Thread: As Any

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2000
    Location
    Logan, Utah
    Posts
    15

    As Any

    Accessing the Win32 API there are several functions which declare a parameter type 'As Any'. This in C++ is just a 'void *'.

    I'm learning to write some dll's in C++ using the ATL COM AppWizard. I know we cannot set a 'void *' for a parameter type. What type do we need to use to have it come across in VB 'As Any'

    Thanks

  2. #2
    jim mcnamara
    Guest
    As Any is really a fiber filler to allow VB to use the Win32API.

    It allows for passing both ByRef and ByVal. Good coding practice in VB is to change the declaration of the api to make it type-safe, unless you really love the blue screen o' death.
    Code:
    'generic declaration - avoid this 
    
    Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    
    ' instead explicitly declare lParam as whatever, changing the name
    ' for string
    Public Declare Function SendMessageString Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String) As Long
    
    ' for long
    Public Declare Function SendMessageLong Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Long) As Long
    So, what I'm saying is: don't try to create a single entry point into your code. It will cause problems later on. Good programmers will code around it anyway.

    Create several entrypoints, each with completely defined parameters. Let the entrypoints each call the same code. Avoid 'as any'. Like the plague. I know this doesn't directly answer your question.

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