Passing a User-defined type ByRef

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
cdthurmanAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Erick37Commented:
Change the declare to this:

Private Declare Function ChildWindowFromPoint Lib "user32" (ByVal hWndParent As Long, pt As POINTAPI) As Long
0
Erick37Commented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
cdthurmanAuthor Commented:
that had the same error
0
cdthurmanAuthor Commented:
I did not read the post fully, that worked thank you
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.