Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Passing a User-defined type ByRef

Posted on 2005-03-30
4
Medium Priority
?
867 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
  • 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month14 days, 13 hours left to enroll

577 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