Member Avatar for Silfro

Hi I have a problem with converting a struct..

I got 2 different structs but they have the "same" data.

Struct1:

struct sStruct1
{
    BYTE  Base1;
    WORD  Base2;
    float Base3;
}

Struc2:

struct sStruct2
{
    BYTE*  Base1;
    WORD*  Base2;
    float* Base3;
}

Now I the problem: I have data inside the struct1 but I need to fill struct2 with the same data.
I have no idea how I could do this..

I tryed this but no luck

DWORD ConvertBYTE(void* pvValue, void* pvBuffer)
{
    BYTE* pbyBuffer = (BYTE*)pvBuffer;
    *pbyBuffer = *((BYTE*)pvValue);

    return sizeof(BYTE);
}

Recommended Answers

All 2 Replies

Just copy the data.

sStruct1 first;
sStruct2 second;

...

first.Base1 = *(second.Base1);
first.Base2 = *(second.Base2);
first.Base3 = *(second.Base3);

...

*(second.Base1) = first.Base1;    
*(second.Base2) = first.Base2;
*(second.Base3) = first.Base3;

you can use contructors in structs but you have to define them

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.