By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,728 Members | 1,169 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,728 IT Pros & Developers. It's quick & easy.

P/Invoke Interop Assistant uint type cast question

P: n/a
The P/Invoke Interop Assistant (http://www.codeplex.com/clrinterop)
generates a signature for GetDefaultPrinter using an uint type for
pcchBuffer:

public static extern bool GetDefaultPrinter([OutAttribute()]
[MarshalAsAttribute(UnmanagedType.LPStr)] StringBuilder pszBuffer, ref
uint pcchBuffer);

However, StringBuilder only accepts type int. Is it safe to cast uint to
int?

The GetDefaultPrinter signature on pinvoke.net uses an int type for
pcchBuffer, so a cast is not necessary.

Thanks,

Tim Sprout
Sep 20 '08 #1
Share this Question
Share on Google+
2 Replies


P: n/a
"Tim Sprout" <tm**@ptialaska.netwrote in message
news:ut**************@TK2MSFTNGP04.phx.gbl...
The P/Invoke Interop Assistant (http://www.codeplex.com/clrinterop)
generates a signature for GetDefaultPrinter using an uint type for
pcchBuffer:

public static extern bool GetDefaultPrinter([OutAttribute()]
[MarshalAsAttribute(UnmanagedType.LPStr)] StringBuilder pszBuffer, ref
uint pcchBuffer);

However, StringBuilder only accepts type int. Is it safe to cast uint to
int?

The GetDefaultPrinter signature on pinvoke.net uses an int type for
pcchBuffer, so a cast is not necessary.

It doesn't make a difference since an int and a uint are the same size.

Technically, ref uint is the correct type for the GetDefaultPrinter() call,
but if it's easier to use an int then go for it :)

I personally prefer to use the type that will need the least amount of
casting.

Mark

--
Mark Salsbery
Microsoft MVP - Visual C++
>
Thanks,

Tim Sprout
Sep 20 '08 #2

P: n/a
Mark Salsbery [MVP] wrote:
"Tim Sprout" <tm**@ptialaska.netwrote in message
news:ut**************@TK2MSFTNGP04.phx.gbl...
>The P/Invoke Interop Assistant (http://www.codeplex.com/clrinterop)
generates a signature for GetDefaultPrinter using an uint type for
pcchBuffer:

public static extern bool GetDefaultPrinter([OutAttribute()]
[MarshalAsAttribute(UnmanagedType.LPStr)] StringBuilder pszBuffer, ref
uint pcchBuffer);

However, StringBuilder only accepts type int. Is it safe to cast uint
to int?

The GetDefaultPrinter signature on pinvoke.net uses an int type for
pcchBuffer, so a cast is not necessary.


It doesn't make a difference since an int and a uint are the same size.

Technically, ref uint is the correct type for the GetDefaultPrinter()
call, but if it's easier to use an int then go for it :)

I personally prefer to use the type that will need the least amount of
casting.

Mark
Thanks, Mark!

Tim Sprout
Sep 21 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.