?
Solved

bad DLL calling convention or something like that...

Posted on 2000-02-10
16
Medium Priority
?
284 Views
Last Modified: 2008-02-01
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
0
Comment
Question by:xer_soft
  • 5
  • 3
  • 3
  • +2
16 Comments
 
LVL 12

Expert Comment

by:rwilson032697
ID: 2509994
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
 
LVL 15

Expert Comment

by:ameba
ID: 2509998
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
 
LVL 12

Expert Comment

by:rwilson032697
ID: 2510018
Or maybe not...
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
LVL 12

Expert Comment

by:rwilson032697
ID: 2510019
rwilson changed the proposed answer to a comment
0
 
LVL 15

Expert Comment

by:ameba
ID: 2510041
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
 
LVL 15

Expert Comment

by:ameba
ID: 2510046
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
 
LVL 32

Accepted Solution

by:
Erick37 earned 800 total points
ID: 2510508
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
 
LVL 15

Expert Comment

by:ameba
ID: 2511119
I didn't test it, but I trust Erick37
0
 
LVL 1

Expert Comment

by:RobMWilliams
ID: 2515826


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
 
LVL 32

Expert Comment

by:Erick37
ID: 2516474
RobMWilliams
Ameba and myself have already commented on the issues you have proposed as an answer.
0
 
LVL 1

Expert Comment

by:RobMWilliams
ID: 2516542
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
 
LVL 15

Expert Comment

by:ameba
ID: 2516575
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
 
LVL 1

Expert Comment

by:RobMWilliams
ID: 2516646
> But I think this might not be for you (helping others, exchanging knowledge).

Ouch!

This place IS tough.

0
 
LVL 32

Expert Comment

by:Erick37
ID: 2516667
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
 
LVL 1

Author Comment

by:xer_soft
ID: 2520256
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
 
LVL 1

Author Comment

by:xer_soft
ID: 2520262
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

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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…
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…
Suggested Courses

588 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