Jump to content

Convert 2 WORD's into a single DWORD in C++

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
1 reply to this topic

#1
dinklebaga

dinklebaga

    Newbie

  • Members
  • PipPip
  • 23 posts
Hi All,
I need a function that can convert 2 WORDs into a single DWORD. I've tried using the HIWORD and LOWORD funtions but they wont let me add them in like this:

else

{

	HIWORD(clusterno) = _RE.high_first_clus;

	LOWORD(clusterno) = _RE.low_first_clus;

}

Any ideas?
Dinklebaga

#2
julmuri

julmuri

    Programmer

  • Members
  • PipPipPipPip
  • 139 posts
You could use MAKELONG macro from windef.h.
Heres function how you could also do it. (:


template < typename R, typename T >

R join( T lo, T hi )

{

	// make sure that return can hold both

	assert( sizeof( R ) == sizeof( T ) * 2 );


	R result;


	result = 0;

	result = (( lo & 0xFF ) | ( hi & 0xFF ) << sizeof( T ) * 8 );


	return result;

}

Just made that though, so cant guarantee that there isnt any probs with it.