MoveToEx API question

adam8
adam8 used Ask the Experts™
on
Hi,
the MoveToEx APi has a lpPoint As POINTAPI parameter and it says in the api guide....

"· lpPoint
Points to a POINT structure in which the previous current position is stored. If this parameter is a NULL pointer, the previous position is not returned."

The question is that I don't need to get the last position returned so how do I send the null parameter. Using 0 doesn't work because it needs a POINTAPI variable so what do I use.

Secondly if I change a Function API to a Sub and don't get it to return a value will this affect stability of the API and will it make it quicker if a return value isn't needed.

For example

Declare Function MoveToEx Lib "gdi32" Alias "MoveToEx" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, lpPoint As POINTAPI) As Long

Change to

Declare Sub MoveToEx Lib "gdi32" Alias "MoveToEx" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, lpPoint As POINTAPI)
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Alon HirschSoftware Development Manager

Commented:
Hi,

Have you tried passing NULL as the parameter ?
Have you tried passing 0& as the parameter ?
I've seen someone pass BYVAL 0& as the LPOINT parameter for this function and it seems to work.
Give it a bash and let me know.

HTH,
Alon
Try passing the constant vbNull as a parameter. If that doesn't work try leaving the parameter empty.

If your having no luck then it's probably best that you define the POINTAPI type somewhere in your project and pass an object of this type to the relevant parameter in the API call.

Michael.

Author

Commented:
I know how to pass the POINTAPI parameter but I thought it would be faster if it didn't return the previous position.

As for the first comment I tried passing Byval 0& and it says user-defined type may not be passed ByVal. It doesn't work if I use 0& or vbNull and leaving the parameter doesn't work.

AlonHirsch, If you have seen someone pass it Byval 0& then if you can show me code that works that would be good. Maybe I am doing something wrong, but try it yourself first.

Thanks
Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Alon HirschSoftware Development Manager

Commented:
Hi,
This example uses BYVAL 0& when passing to the function.
I tried this and it worked perfectly :

Private Type POINTAPI
    x As Long
    y As Long
End Type
Private Declare Function PolylineTo Lib "gdi32" (ByVal hdc As Long, lppt As POINTAPI, ByVal cCount As Long) As Long
Private Declare Function MoveToEx Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal lpPoint As Any) As Long
Private Sub Form_Load()
    'KPD-Team 1998
    'URL: http://www.allapi.net/
    'E-Mail: KPDTeam@Allapi.net
    Me.ScaleMode = vbPixels
End Sub
Private Sub Form_Paint()
    Dim Pt(1 To 1000) As POINTAPI, Angle As Single, Radius As Single
    Dim Number As Integer, XMid As Long, YMid As Long
    XMid = Me.ScaleWidth / 2
    YMid = Me.ScaleHeight / 2
    'Fill our array with points
    For Number = 1 To 1000
        Angle = Number * 0.1
        Radius = Radius + Angle * 0.01
        Pt(Number).x = XMid + Cos(Angle) * Radius
        Pt(Number).y = YMid - Sin(Angle) * Radius
    Next Number
    'Set the coördinates of the active point
    MoveToEx Me.hdc, Me.ScaleWidth / 2, Me.ScaleHeight / 2, ByVal 0&
    'Draw several lines
    PolylineTo Me.hdc, Pt(1), 1000
End Sub
Private Sub Form_Resize()
    Me.Cls
    Form_Paint
End Sub

HTH,
Alon

Author

Commented:
This is the function I found....

Private Declare Function MoveToEx Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, lpPoint As POINTAPI) As Long

Try passing this as Byval 0&

I don't get why there are different versions of the same API?
Software Development Manager
Commented:
Hi,

The API has been declared differently in order to cater for the situation you require.
Using your declaration - you need to pass a parameter of type POINTAPI.
Using the declaration in the example I sent you - the parameter can be any type of value including NULL.

You will find that several API's will allow multiple declarations (depending on where you see it) in order to cater for different scenarios.
One such example is the SendMessage API :
VB Declaration

Declare Function SendMessage& Lib "user32" Alias "SendMessageA" (ByVal hwnd As _
Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any)
Declare Function SendMessageBynum& Lib "user32" Alias "SendMessageA" (ByVal _
hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long)
Declare Function SendMessageByString& Lib "user32" Alias "SendMessageA" (ByVal _
hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String)

Description    

Sends a message to a window by calling the window function for that window. This function does not return until the message is processed. SendMessageBystring and SendMessageBynum are type-safe declarations of SendMessage.

HTH,
Alon

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial