?
Solved

Passing a User-defined type ByRef

Posted on 2005-03-30
4
Medium Priority
?
810 Views
Last Modified: 2007-12-19
I am using the following code


Private Type POINTAPI
        X As Long
        Y As Long
End Type

Private Type tMSG
    hWnd        As Long
    nMsg        As Long
    wParam      As Long
    lParam      As Long
    time        As Long
    pt          As POINTAPI
End Type
Private MSG As tMSG
Private MouseCoords As POINTAPI
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Declare Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As Long
Private Declare Function GetMessage Lib "user32" Alias "GetMessageA" (lpMsg As tMSG, ByVal hWnd As Long, ByVal wMsgFilterMin As Long, ByVal wMsgFilterMax As Long) As Long
Private Declare Function TranslateMessage Lib "user32" (lpMsg As tMSG) As Long
Private Declare Function DispatchMessage Lib "user32" Alias "DispatchMessageA" (lpMsg As tMSG) As Long
Private Declare Function WindowFromPoint Lib "user32" (ByVal X As Long, ByVal Y As Long) As Long
Private Declare Function ChildWindowFromPoint Lib "user32" (ByVal hWndParent As Long, ByVal pt As POINTAPI) As Long


Private Sub Form_Load()
    hWndConnected = Command1.hWnd
    GetMessage MSG, Parent.hWnd, 0, 0
    TranslateMessage MSG
    DispatchMessage MSG
    GetCursorPos MouseCoords 'get current mouse location
    Debug.Print ChildWindowFromPoint(hWndConnected, MSG.pt)
End Sub



I receive this error when calling the ChildWindowFromPoint Function

Compile error:

User-defined type may not be passed ByVal

What can I do to fix this?
I have to send a POINTAPI datatype but cant use a POINTAPI datatype?
Is there a way to change the value from a Reference to a Value?

Thank You
0
Comment
Question by:cdthurman
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 32

Expert Comment

by:Erick37
ID: 13668465
Change the declare to this:

Private Declare Function ChildWindowFromPoint Lib "user32" (ByVal hWndParent As Long, pt As POINTAPI) As Long
0
 
LVL 32

Accepted Solution

by:
Erick37 earned 2000 total points
ID: 13668552
Nope, that won't work... another VB6 quirk...

The Declare should be:

Private Declare Function ChildWindowFromPoint Lib "user32" (ByVal hWndParent As
 Long, ByVal X As Long, ByVal Y As Long) As Long


and call it from your program like this:

Debug.Print ChildWindowFromPoint(hWndConnected, MSG.pt.X, MSG.pt.Y)
0
 

Author Comment

by:cdthurman
ID: 13670294
that had the same error
0
 

Author Comment

by:cdthurman
ID: 13670480
I did not read the post fully, that worked thank you
0

Featured Post

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Suggested Courses
Course of the Month14 days, 22 hours left to enroll

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question