bad DLL calling convention or something like that...

I do this
If PtInRect(InterData(i).Inter_HotBox, thepoint) > 0 Then

InterData(i).Inter_HotBox is a RECT and thepoint is a pointapi

and I get a bad dll calling convention.. Why
Heres my declares

Type POINTAPI
        x As Long
        y As Long
End Type


Type RECT
        Left As Long
        Top As Long
        Right As Long
        Bottom As Long
End Type
Public Declare Function PtInRect Lib "user32" (lpRect As RECT, pt As POINTAPI) As Long
LVL 1
xer_softAsked:
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.

rwilson032697Commented:
You must declare the function as using standard caling convention.

Public Declare Function PtInRect Lib "user32" stdcall (lpRect As RECT, pt As POINTAPI) As Long

(I think) Look in the help for exact syntax for calling convention on functions if this doesn't quite fly!

Cheers,

Raymond.


0
amebaCommented:
First, replace "> 0" with "<> 0"

"The return value is nonzero if the point lies within the given rectangle. Otherwise, it is zero."

Then, post code to get rectangle and thepoint.
0
rwilson032697Commented:
Or maybe not...
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

rwilson032697Commented:
rwilson changed the proposed answer to a comment
0
amebaCommented:
Just noticed, I use myPtInRect

Public Function myPtInRect(lpRect As RECT, pt As POINTAPI) As Long
' replacement for PtInRect api, which gives Bad DLL convention. Wrong declaration?
    Dim tmp As Long
    tmp = 0
    If pt.X >= lpRect.Left Then
        If pt.X <= lpRect.Right Then
            If pt.Y >= lpRect.Top Then
                If pt.Y <= lpRect.Bottom Then
                    tmp = 1
                End If
            End If
        End If
    End If
    myPtInRect = tmp
End Function
0
amebaCommented:
That was old version, this is new

Public Function myPtInRect(lpRect As RECT, pt As POINTAPI) As Long
' replacement for PtInRect api, which gives Bad DLL convention.
    If pt.X >= lpRect.Left Then
        If pt.X <= lpRect.Right Then
            If pt.Y >= lpRect.Top Then
                If pt.Y <= lpRect.Bottom Then
                   myPtInRect = 1
                End If
            End If
        End If
    End If
End Function
0
Erick37Commented:
Option Explicit

Private Type POINTAPI
        x As Long
        y As Long
End Type
Private Type RECT
        Left As Long
        Top As Long
        Right As Long
        Bottom As Long
End Type

Private Declare Function PtInRect Lib "user32" (lpRect As RECT, _
  ByVal ptx As Long, ByVal pty As Long) As Long

Private Sub Command1_Click()
    Dim pt As POINTAPI
    Dim rc As RECT
    rc.Right = 100
    rc.Bottom = 100
    pt.x = 50
    pt.y = 50
    Debug.Print PtInRect(rc, pt.x, pt.y)
End Sub
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
amebaCommented:
I didn't test it, but I trust Erick37
0
RobMWilliamsCommented:


Part one of the problem is passing the variables to Windows.  Windows is expecting the two longs in the POINTAPI structure to be Longs passed by value.  User Defined Types are always passed by reference.  Declare the function like this:

Declare Function PtInRect Lib "user32.dll" (lpRect As RECT, ByVal x As Long, ByVal y As Long) As Long


Also, I think I have a problem with the following
If PtInRect(interdata(i).Inter_HotBox, thepoint) > 0 Then …

Perhaps you left something out but the array looks like a user defined type where one element of the User defined type is a user defined type of RECT.

Clear?
Is that right?

If it’s just an array of UDT’s then

Dim interdata(1 To 10) As RECT

Then assign values to each RECT in the array:

interdata(1).Bottom = 100
interdata(1).Left = 1
interdata(1).Right = 200
interdata(1).Top = 1
etc.

Dim y as long, z as long

Then call the function:
If PtInRect(interdata(1), y, z) > 0 Then …

If Inter_HotBox is a RECT within a user definded type like:

Type interdataX
    Something as long
    Otherthing as string
    Inter_HotBox as RECT
End Type

Dim interdata(1 to 10) as interdataX

That’s fine.  That should work.  Okay dokay.

0
Erick37Commented:
RobMWilliams
Ameba and myself have already commented on the issues you have proposed as an answer.
0
RobMWilliamsCommented:
Okay, thanks, sorry about that.
I’m new to this forum and I didn’t realize this point system.
I see that “comments” is information, and “answers” is some contest thing for points.
I don’t want to seem cynical but what’s the point with the points?  Is there a car or something at the end?  
I’ve already had a perfectly fine answer “rejected” quite soundly.  I don’t see how someone who doesn’t understand what they’re talking about (that’s why they’re asking) can reject the answer to their problem (because they don’t understand what they’re talking about)

If there IS as car at the end, I’m interested, otherwise, why should anyone bother?

0
amebaCommented:
No, there is no car.

To understand, maybe you can read JimMorgan's profile, he is number 67 on http://www.experts-exchange.com/bin/Top100

But I think this might not be for you (helping others, exchanging knowledge).
0
RobMWilliamsCommented:
> But I think this might not be for you (helping others, exchanging knowledge).

Ouch!

This place IS tough.

0
Erick37Commented:
This is how I see it.  I usually post a comment if others have already commented on a question, especially if the questioner has not replied yet.

If I am certain I have a solution to a particular question (and no other comments have addressed the point) I will post as answer.

Also, if you get a certain number of points, there is a free tee shirt waiting for you.
0
xer_softAuthor Commented:
This seems to not be a hard problem... I see that the API text viewer gives the wrong declare! At least mine does... The lower one is the one my viewer gives me it uses a pointapi. The one every one sujested i use does not use this type. Thanks to every one who helped. I'll give the points to the first person who used the right code. But for now on I am only giveing my points to the first correct Answer not comment. I always feel bad when making theese decisions but no more. Only the correct Answer not a comment. -For any one who cares.

Futher: does any one else have the problem with the API viewer?

Private Declare Function PtInRect Lib "user32" (lpRect As RECT, ByVal ptx As Long, ByVal pty As Long) As Long

Private Declare Function PtInRect Lib "user32" (lpRect As RECT, pt As POINTAPI) As Long
0
xer_softAuthor Commented:
Looks like this is the first post that uses the correct API declare. (Why did EE every make it so comments could be used as answers...) Sorry if I made any one mad...
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.