0

I am trying to import some winapi functions into my wpf project(written in c#) but I do not know how to "convert" some of their paramaters, for example the function

BOOL WINAPI GetClientRect(
  _In_  HWND   hWnd,
  _Out_ LPRECT lpRect
);

takes a pointer to a RECT struct and modifies its contents. If I were to import this function using the DllImport attribute it would look like:

[DllImport("user32.dll"]
public static extern bool GetClientRect(IntPtr hwnd, ???);

How do I handle the pointer to RECT object?

gorilla bull
  • 150
  • 9
  • 2
    There is a site full of pinvoke: http://www.pinvoke.net/default.aspx/user32.getclientrect . Have you tried them? There is a definition for a RECT. – xanatos Mar 02 '17 at 07:15
  • (note that sometimes that site is wrong :-) They have some problems with 32-to-64 bits) – xanatos Mar 02 '17 at 07:16
  • Also http://stackoverflow.com/questions/13086927/call-getclientrect-winapi – mpiatek Mar 02 '17 at 07:17
  • well looks like pinvoke.net should do it.. i should have asked here first before searching myself for hours lol ... – gorilla bull Mar 02 '17 at 07:32
  • Then you should better your google-fu... If you search for *GetClientRect pinvoke* then the first link is for pinvoke.net, the third is for the stackoverflow answer linked by mpiatek – xanatos Mar 02 '17 at 07:50
  • There is a Pinvoke.Net plugiun for Visual Studio – Paul Baxter Mar 08 '17 at 20:05

1 Answers1

0
[StructLayout(LayoutKind.Sequential)]
public struct RECT
{
    public int Left, Top, Right, Bottom;
}

[DllImport("user32.dll")]
static extern bool GetClientRect(IntPtr hWnd, out RECT lpRect);
Paul Baxter
  • 1,054
  • 12
  • 22