From: Hugo gleaves on
Does anyone know if there are any routines in the C runtime that allows
comversion from one type to another?

We have a need to potentially convert data from one type to another at
runtime, we dont know until runtime and the 'type' of both source and target
are a simple code.

We need to support from/to char, wchar, short, long, long long, float and
double including the signed/unsigned too.

We can code these ourselves and perhaps make it a 2D array of function
pointers (initialized to point at the functions during startup).

Thus we can then code:

ConvertData[SourceType][TargetType](addr1, addr2);

However, before we do this we want to be sure we dont reinvent the wheel.

Any info appreciated.

This is for all platforms, XP, Vista, Server etc and 32-bit & 64-bit.




From: Gary G. Little on
I'm more C than C++, but we use the following ...

static_cast<type> (target)
dynamic_cast<type> (target)

--
The personal opinion of
Gary G. Little

"Hugo gleaves(a)hotmail.com>" <hugh<underbar> wrote in message
news:C97A6187-024A-48B3-AAEB-7335811463FD(a)microsoft.com...
> Does anyone know if there are any routines in the C runtime that allows
> comversion from one type to another?
>
> We have a need to potentially convert data from one type to another at
> runtime, we dont know until runtime and the 'type' of both source and
> target
> are a simple code.
>
> We need to support from/to char, wchar, short, long, long long, float and
> double including the signed/unsigned too.
>
> We can code these ourselves and perhaps make it a 2D array of function
> pointers (initialized to point at the functions during startup).
>
> Thus we can then code:
>
> ConvertData[SourceType][TargetType](addr1, addr2);
>
> However, before we do this we want to be sure we dont reinvent the wheel.
>
> Any info appreciated.
>
> This is for all platforms, XP, Vista, Server etc and 32-bit & 64-bit.
>
>
>
>


From: Christian Kaiser on
VariantChangeType()?

VarXxxFromYyyy() -> VARTYPE coercion API in OLEAUTO.H!

Christian

"Hugo gleaves(a)hotmail.com>" <hugh<underbar> wrote in message
news:C97A6187-024A-48B3-AAEB-7335811463FD(a)microsoft.com...
> Does anyone know if there are any routines in the C runtime that
> allows
> comversion from one type to another?
>
> We have a need to potentially convert data from one type to another
> at
> runtime, we dont know until runtime and the 'type' of both source
> and target
> are a simple code.
>
> We need to support from/to char, wchar, short, long, long long,
> float and
> double including the signed/unsigned too.
>
> We can code these ourselves and perhaps make it a 2D array of
> function
> pointers (initialized to point at the functions during startup).
>
> Thus we can then code:
>
> ConvertData[SourceType][TargetType](addr1, addr2);
>
> However, before we do this we want to be sure we dont reinvent the
> wheel.
>
> Any info appreciated.
>
> This is for all platforms, XP, Vista, Server etc and 32-bit &
> 64-bit.
>
>
>
>


From: Jochen Kalmbach [MVP] on
Hi Hugo!

> Does anyone know if there are any routines in the C runtime that allows
> comversion from one type to another?
>
> We need to support from/to char, wchar, short, long, long long, float and
> double including the signed/unsigned too.

In general you would use "VARIANT" for this scenario.

See also:
VARIANT and VARIANTARG
http://msdn.microsoft.com/en-us/library/ms221627

VariantChangeType
http://msdn.microsoft.com/en-us/library/ms221258

Variant Manipulation Functions
http://msdn.microsoft.com/en-us/library/ms221673

--
Greetings
Jochen

My blog about Win32 and .NET
http://blog.kalmbachnet.de/
From: Hugo gleaves on
Thanks to each of you, this is most interesting.

Rgds
Hugh


"Hugo" wrote:

> Does anyone know if there are any routines in the C runtime that allows
> comversion from one type to another?
>
> We have a need to potentially convert data from one type to another at
> runtime, we dont know until runtime and the 'type' of both source and target
> are a simple code.
>
> We need to support from/to char, wchar, short, long, long long, float and
> double including the signed/unsigned too.
>
> We can code these ourselves and perhaps make it a 2D array of function
> pointers (initialized to point at the functions during startup).
>
> Thus we can then code:
>
> ConvertData[SourceType][TargetType](addr1, addr2);
>
> However, before we do this we want to be sure we dont reinvent the wheel.
>
> Any info appreciated.
>
> This is for all platforms, XP, Vista, Server etc and 32-bit & 64-bit.
>
>
>
>