469,267 Members | 1,070 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,267 developers. It's quick & easy.

Convert System::UInt64 to unsigned long

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
3 8195
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
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
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.

Similar topics

1 post views Thread by Fred | last post: by
3 posts views Thread by seema | last post: by
1 post views Thread by John Smith | last post: by
8 posts views Thread by AGRAJA | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.