Sign in to follow this  
Vanderry

[C++] Tree View & Byte Arrays

Recommended Posts

Hello GameDevs ! I have a probably very weird problem this time. In a game engine of mine I was planning to sort the static game assets by array-like indices that correspond to a folder path. 1. Flora ---1. Trees ------1. Pine ------2. Oak ---2. Flowers ------1. Daisy 2. Structures ---1. Wall ---2. House (1, 1, 2, 0) would represent the oak asset (zeros signify end of index). The reason for all this being that I can store orientational data (within the game world) for a series of instanced game objects in a binary file that won't occupy unnecessarily much memory. Now to the actual problem, within the game world editor I'm using a Win32 Tree View to access the game assets. The way I have understood it, I can store a label string and an LPARAM (a LONG_PTR of 4 bytes) in each of its TVITEM elements. So I figured I might just as well store the index into the LPARAM in the form of a 4 char array (4 x 1 byte). My question is: can and should I push the 4 chars into the LPARAM somehow? I tried to use memcpy with no great success.
LONG_PTR lParam = 0;
UCHAR index[4] = { 1, 1, 2, 0 };
memcpy( &lParam, &index, sizeof( LONG_PTR ) );

for( int i = 0; i < sizeof( LONG_PTR ); i++ )
{
	cout << (UCHAR)(&lParam )[i] << endl; // The printout is wrong at least
}




If anyone might shed a little light on my situation I'd be ever grateful. - Dave

Share this post


Link to post
Share on other sites
I realized this was a better cast for the printout example:


LPARAM lParam = 0;
UCHAR index[4] = { 1, 1, 2, 0 };
lParam = (LPARAM)index;

for( int i = 0; i < sizeof( LPARAM ); i++ )
{
cout << (int)((UCHAR*)lParam)[i] << endl;
}




Stupid mistake, the result is correct now but I am still unsure about the actual implementation.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this