tags:

views:

36

answers:

1

I am trying to cast data to a struct from a parameter passed into my method, I need the data to be passed to a global variable as it is needed elsewhere in my application.

I have tried the following but I get errors saying that diceResult is an undeclared identifier

Here is the code itself:

//Structure to hold dice data
typedef struct diceData
{
    int dice1;
    int dice2;
};

struct diceResult;

DWORD WINAPI UnpackDiceData(LPVOID sentData)
{
    //Unpack data
    struct diceData unpackedData = *((struct diceData*)sentData);

    diceResult.dice1 = unpackedData.dice1;
    diceResult.dice2 = unpackedData.dice2;
}

I don't understand why it won't recognise it being there when it's clearly global.

+1  A: 
typedef struct diceData
{
    int dice1;
    int dice2;
};

Your typedef isn't doing anything. Normally you'd use it something like:

typedef struct { 
    int dice1;
    int dice2;
} diceData;

Then you can define an instance of that type:

diceData diceResult;

... and then your other code should be able to use that instance.

When you have that working, my advice would to rewrite it so it does not use global data.

Jerry Coffin
Thank you for the answer, I'll be sure to try and remove the need for a global variable.
Jamie Keeling