P/Invoke trouble (ScrollDC)

  • Thread starter Marcos Cruz Arjona
  • Start date
M

Marcos Cruz Arjona

Hi,

In order to scroll the client area of a custom control, I call ScrollDC
unmanaged function using the P/Invoke service in the .NET Compact Framework.
I've declared it, as follows:

[DllImport("codedll.dll", EntryPoint="ScrollDC")]
public static extern bool ScrollDC(IntPtr hdc, int dx, int dy, ref RECT
lprcScroll, ref REC lprcClip, int hrgnUpdate, ref RECT lprcUpdate);

So far, it works fine. However, ¿how can I pass a null pointer on lprcScroll
& lprcClip arguments?. I have tried several ways, but I always got compiler
errors.

Best regards,

M a r c o s
 
M

Marcos Cruz Arjona

Chris,

I had already tried this, but compiler cannot convert IntPtr.Zero to ref
RECT.


Chris Tacke said:
IntPtr.Zero should work fine.

-Chris


Marcos Cruz Arjona said:
Hi,

In order to scroll the client area of a custom control, I call ScrollDC
unmanaged function using the P/Invoke service in the .NET Compact Framework.
I've declared it, as follows:

[DllImport("codedll.dll", EntryPoint="ScrollDC")]
public static extern bool ScrollDC(IntPtr hdc, int dx, int dy, ref RECT
lprcScroll, ref REC lprcClip, int hrgnUpdate, ref RECT lprcUpdate);

So far, it works fine. However, ¿how can I pass a null pointer on lprcScroll
& lprcClip arguments?. I have tried several ways, but I always got compiler
errors.

Best regards,

M a r c o s
 
C

Chris Tacke, eMVP

if you're marshalling a struct (dangerous in the CF in the first place) then
you should be able to use null.

-Chris


Marcos Cruz Arjona said:
Chris,

I had already tried this, but compiler cannot convert IntPtr.Zero to ref
RECT.


Chris Tacke said:
IntPtr.Zero should work fine.

-Chris


Marcos Cruz Arjona said:
Hi,

In order to scroll the client area of a custom control, I call ScrollDC
unmanaged function using the P/Invoke service in the .NET Compact Framework.
I've declared it, as follows:

[DllImport("codedll.dll", EntryPoint="ScrollDC")]
public static extern bool ScrollDC(IntPtr hdc, int dx, int dy, ref RECT
lprcScroll, ref REC lprcClip, int hrgnUpdate, ref RECT lprcUpdate);

So far, it works fine. However, ¿how can I pass a null pointer on lprcScroll
& lprcClip arguments?. I have tried several ways, but I always got compiler
errors.

Best regards,

M a r c o s
 
A

Alex Feinman [MVP]

What you want to do is to define an overload like this:
[DllImport("codedll.dll", EntryPoint="ScrollDC")]
public static extern bool ScrollDC(IntPtr hdc, int dx, int dy, IntPtr
lprcScroll, IntPtr lprcClip, int hrgnUpdate, ref RECT lprcUpdate);
then call it with IntPtr.Zero in place of those 2 parameters. In fact even
int and 0 would do it, but IntPtr is cleaner
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top