471,349 Members | 1,266 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,349 software developers and data experts.

Compiler error CS1518

Hi,

Because GDI+ doesnt support inversion of rectangles on a graphics device
(!!!) I'm attempting to call InvertRect() on the api direct from my c#
project.

In the file in questions, directly after the using directives and before
the class/namespace bit I've got (found this on the web):

[DllImport("user32.dll")]
[return:MarshalAs(UnmanagedType.Bool)]
public static bool InvertRect(IntPtr hDC, rf System.Drawing.Rectangle lprc);

The bool on the last line is generating the error. I'm using VS pro 2003.

Help!!
Jul 22 '05 #1
3 3797
>In the file in questions, directly after the using directives and before
the class/namespace bit I've got (found this on the web):

[DllImport("user32.dll")]
[return:MarshalAs(UnmanagedType.Bool)]
public static bool InvertRect(IntPtr hDC, rf System.Drawing.Rectangle lprc);

The bool on the last line is generating the error. I'm using VS pro 2003.

P/Invoke method declarations must be placed inside a type (class or
struct) just like any other method.

In addition to that, you must add the extern keyword to the
declaration, and change "rf" to "ref".

But even then it will not work as expected, because the internal
layout of a System.Drawing.Rectangle isn't the same as a GDI RECT
struct.


Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Jul 22 '05 #2
Mattias Sjögren wrote:
In the file in questions, directly after the using directives and before
the class/namespace bit I've got (found this on the web):

[DllImport("user32.dll")]
[return:MarshalAs(UnmanagedType.Bool)]
public static bool InvertRect(IntPtr hDC, rf System.Drawing.Rectangle lprc);

The bool on the last line is generating the error. I'm using VS pro 2003.
P/Invoke method declarations must be placed inside a type (class or
struct) just like any other method.

In addition to that, you must add the extern keyword to the
declaration, and change "rf" to "ref".


That's a typo.

But even then it will not work as expected, because the internal
layout of a System.Drawing.Rectangle isn't the same as a GDI RECT
struct.


Any way to convert?
Jul 22 '05 #3
redeclare your own rectangle struct using a definition from www.pinvoke.net.
"Phil Da Lick!" <ph***********@NOSPAMhotmail.com> schrieb im Newsbeitrag
news:#P**************@TK2MSFTNGP10.phx.gbl...
Mattias Sjögren wrote:
In the file in questions, directly after the using directives and before
the class/namespace bit I've got (found this on the web):

[DllImport("user32.dll")]
[return:MarshalAs(UnmanagedType.Bool)]
public static bool InvertRect(IntPtr hDC, rf System.Drawing.Rectangle lprc);
The bool on the last line is generating the error. I'm using VS pro
2003.
P/Invoke method declarations must be placed inside a type (class or
struct) just like any other method.

In addition to that, you must add the extern keyword to the
declaration, and change "rf" to "ref".


That's a typo.

But even then it will not work as expected, because the internal
layout of a System.Drawing.Rectangle isn't the same as a GDI RECT
struct.


Any way to convert?

Jul 22 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by rollasoc | last post: by
1 post views Thread by Ayende Rahien | last post: by
1 post views Thread by Franko | last post: by
3 posts views Thread by Mark Rockman | last post: by
4 posts views Thread by David Sworder | last post: by
1 post views Thread by Franko | last post: by
3 posts views Thread by Phil Da Lick! | last post: by
9 posts views Thread by blackdog | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.