Hiya,
I have converted the RECT and POINT structures as well as the PtInRect API
to the following C# code
[StructLayout(LayoutKind.Sequential)]
public struct Point
{
public int x;
public int y;
}
[StructLayout(LayoutKind.Sequential)]
public struct Rect
{
public int Left;
public int Top;
public int Right;
public int Bottom;
}
[DllImport("User32.dll")]
public static extern bool PtInRect
(
ref Rect Rectangle,
ref Point Position
);
The problem is that I can't get the PtInRect API to ever return a true
value, i.e. that
my point exist in the given rectangle not even with basic test code (note
all interop
stuff has been places in a class called Win32 for simplicity)
Win32.Rect r = new GraphicsLibrary.Win32.Rect();
r.Left = 0;
r.Top = 0;
r.Right = 100;
r.Bottom = 100;
Win32.Point p = new GraphicsLibrary.Win32.Point();
p.x = 50;
p.x = 50;
if( Win32.PtInRect(ref r, ref p) )
MessageBox.Show("Point is inside the rect");
I am sure that the code is executed, but the messagebox never shows =/
Any ideas ?

Signature
ANDREAS H?KANSSON
andreas (at) selfinflicted.org
Andreas Håkansson - 07 Sep 2003 13:07 GMT
Ok I think I found the problem.. The declaration of PtInRect should be
[DllImport("User32.dll")]
public static extern bool PtInRect
(
ref Rect Rectangle,
Point Position
);
instead of
[DllImport("User32.dll")]
public static extern bool PtInRect
(
ref Rect Rectangle,
ref Point Position
);
Is "ref" only needed with the Win32 API is a pointer to a struct ?

Signature
ANDREAS HÅKANSSON
andreas (at) selfinflicted.org
"Andreas Håkansson" <andreas@selfinflicted.org> wrote in message news:ukdXzdTdDHA.880@TK2MSFTNGP09.phx.gbl...
Hiya,
I have converted the RECT and POINT structures as well as the PtInRect API
to the following C# code
[StructLayout(LayoutKind.Sequential)]
public struct Point
{
public int x;
public int y;
}
[StructLayout(LayoutKind.Sequential)]
public struct Rect
{
public int Left;
public int Top;
public int Right;
public int Bottom;
}
[DllImport("User32.dll")]
public static extern bool PtInRect
(
ref Rect Rectangle,
ref Point Position
);
The problem is that I can't get the PtInRect API to ever return a true
value, i.e. that
my point exist in the given rectangle not even with basic test code (note
all interop
stuff has been places in a class called Win32 for simplicity)
Win32.Rect r = new GraphicsLibrary.Win32.Rect();
r.Left = 0;
r.Top = 0;
r.Right = 100;
r.Bottom = 100;
Win32.Point p = new GraphicsLibrary.Win32.Point();
p.x = 50;
p.x = 50;
if( Win32.PtInRect(ref r, ref p) )
MessageBox.Show("Point is inside the rect");
I am sure that the code is executed, but the messagebox never shows =/
Any ideas ?
--
ANDREAS HÅKANSSON
andreas (at) selfinflicted.org
Mattias Sj?gren - 07 Sep 2003 13:14 GMT
Hej Andreas,
>[DllImport("User32.dll")]
>public static extern bool PtInRect
>(
> ref Rect Rectangle,
> ref Point Position
>);
The Point parameter should be passed by value, so remove the ref
modifier.
Mattias

Signature
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/
Please reply only to the newsgroup.
Andreas Håkansson - 08 Sep 2003 17:45 GMT
Btw, thank you for your're reply.. 7seconds appart ;)

Signature
ANDREAS HÅKANSSON
STUDENT OF SOFTWARE ENGINEERING
andreas (at) selfinflicted.org
"Mattias Sjögren" <mattias.dont.want.spam@mvps.org> wrote in message news:#nY1LlTdDHA.1656@TK2MSFTNGP10.phx.gbl...
Hej Andreas,
>[DllImport("User32.dll")]
>public static extern bool PtInRect
>(
> ref Rect Rectangle,
> ref Point Position
>);
The Point parameter should be passed by value, so remove the ref
modifier.
Mattias
--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/
Please reply only to the newsgroup