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

Convert System::UInt64 to unsigned long

P: n/a
What is the best way to convert a managed unsigned int64 to an
unsigned long? Basically I need to do the following:

System::UInt64 managedInt = 10;
unsigned long unmanagedInt;
unmanagedInt = managedInt;

Also it would be nice to know how to do this:

System::UInt64 managedInt;
unsigned long unmanagedInt = 10;
managedInt = unmanagedInt;

Thanks for your help.
Mike
Nov 16 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
You do realize that a 64 bit unsigned integer like a System::UInt64 does
_not_ fir in to a 32 bit unsigned integer such as a long?

If you are sure it won't overflow, just cast:

unsigned long unmanagedInt = static_cast<unsigned long>(managedInt);

If you want to use the same 64 bit type, just use:

unsigned long long unmangedInt = managedInt;

In physical reality there is no different between the System:: integer types
and the normal integer types in C++. Only when you take the address of them,
the type of pointer you get is different (in the 7.0 and 7.1 versions of
Visual C++, in the Whidbey version they will be identical in all respects).

Ronald Laeremans
Visual C++ team

"Mike Miller" <mm*****@bluecypress.net> wrote in message
news:f2**************************@posting.google.c om...
What is the best way to convert a managed unsigned int64 to an
unsigned long? Basically I need to do the following:

System::UInt64 managedInt = 10;
unsigned long unmanagedInt;
unmanagedInt = managedInt;

Also it would be nice to know how to do this:

System::UInt64 managedInt;
unsigned long unmanagedInt = 10;
managedInt = unmanagedInt;

Thanks for your help.
Mike

Nov 16 '05 #2

P: n/a
Ronald,
Thanks for taking the time to answer my question. I tried the
following:

System::UInt32 managedInt = 10;
unsigned long unmanagedInt = static_cast<unsigned long>(managedInt);

When I get following compiler error:
error C2440: 'static_cast' : cannot convert from 'unsigned int __gc *'
to 'unsigned long'

I can't seem to convert between managed integer types and unmanaged
integer types.

Any help would be appreciated.
Thanks,
Mike


"Ronald Laeremans [MSFT]" <ro*****@online.microsoft.com> wrote in message news:<uI**************@TK2MSFTNGP12.phx.gbl>...
You do realize that a 64 bit unsigned integer like a System::UInt64 does
_not_ fir in to a 32 bit unsigned integer such as a long?

If you are sure it won't overflow, just cast:

unsigned long unmanagedInt = static_cast<unsigned long>(managedInt);

If you want to use the same 64 bit type, just use:

unsigned long long unmangedInt = managedInt;

In physical reality there is no different between the System:: integer types
and the normal integer types in C++. Only when you take the address of them,
the type of pointer you get is different (in the 7.0 and 7.1 versions of
Visual C++, in the Whidbey version they will be identical in all respects).

Ronald Laeremans
Visual C++ team

"Mike Miller" <mm*****@bluecypress.net> wrote in message
news:f2**************************@posting.google.c om...
What is the best way to convert a managed unsigned int64 to an
unsigned long? Basically I need to do the following:

System::UInt64 managedInt = 10;
unsigned long unmanagedInt;
unmanagedInt = managedInt;

Also it would be nice to know how to do this:

System::UInt64 managedInt;
unsigned long unmanagedInt = 10;
managedInt = unmanagedInt;

Thanks for your help.
Mike

Nov 16 '05 #3

P: n/a
Figured it out - just being stupid on a Monday morning.
Mike
-----Original Message-----
Ronald,
Thanks for taking the time to answer my question. I tried thefollowing:

System::UInt32 managedInt = 10;
unsigned long unmanagedInt = static_cast<unsigned long> (managedInt);
When I get following compiler error:
error C2440: 'static_cast' : cannot convert from 'unsigned int __gc *'to 'unsigned long'

I can't seem to convert between managed integer types and unmanagedinteger types.

Any help would be appreciated.
Thanks,
Mike


"Ronald Laeremans [MSFT]" <ro*****@online.microsoft.com>

wrote in message news:<uIhO9
$8*********@TK2MSFTNGP12.phx.gbl>...
You do realize that a 64 bit unsigned integer like a System::UInt64 does _not_ fir in to a 32 bit unsigned integer such as a long?
If you are sure it won't overflow, just cast:

unsigned long unmanagedInt = static_cast<unsigned long> (managedInt);
If you want to use the same 64 bit type, just use:

unsigned long long unmangedInt = managedInt;

In physical reality there is no different between the System:: integer types and the normal integer types in C++. Only when you take the address of them, the type of pointer you get is different (in the 7.0 and 7.1 versions of Visual C++, in the Whidbey version they will be identical in all respects).
Ronald Laeremans
Visual C++ team

"Mike Miller" <mm*****@bluecypress.net> wrote in message
news:f2**************************@posting.google.c om...
> What is the best way to convert a managed unsigned int64 to an > unsigned long? Basically I need to do the following:
>
> System::UInt64 managedInt = 10;
> unsigned long unmanagedInt;
> unmanagedInt = managedInt;
>
> Also it would be nice to know how to do this:
>
> System::UInt64 managedInt;
> unsigned long unmanagedInt = 10;
> managedInt = unmanagedInt;
>
> Thanks for your help.
> Mike

.

Nov 16 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.