Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Interop / September 2003

Tip: Looking for answers? Try searching our database.

Problems with PrInRect API

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Andreas H?kansson - 07 Sep 2003 12:59 GMT
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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.