#include "stdio.h" #include "string.h" typedef struct { int nData; char chData; }Tstruct1; typedef struct { int nData; char chData; short wData; }Tstruct2; Tstruct1 tTestt1 = {100, '1'}; Tstruct2 tTestt2 = {200, '2', 20}; const char *Stable[]= { (const char *)(&tTestt1), (const char *)(&tTestt2), }; void GetStructT(int type, void *pvOutBuf, int dwLen) { char *lpstrBuf = NULL; lpstrBuf = (char *)(Stable[type]); memcpy(pvOutBuf, (char *)lpstrBuf, dwLen); } void SetStructT(int type, void *pvOutBuf, int dwLen) { char *lpstrBuf = NULL; lpstrBuf = (char *)(Stable[type]); memcpy(lpstrBuf, pvOutBuf, dwLen); } int main(void) { Tstruct1 at1 = {0}; Tstruct2 at2 = {0}; GetStructT(0, &at1, sizeof(Tstruct1)); printf("struct1: nData:%d, chData:%c/n", at1.nData, at1.chData); GetStructT(1, &at2, sizeof(Tstruct2)); printf("struct2: nData:%d, chData:%c, wData:%d/n", at2.nData, at2.chData, at2.wData); at2.nData = 700; at2.chData = '8'; at2.wData = 66; SetStructT(0, &at2, sizeof(at2)); printf("struct2: nData:%d, chData:%c, wData:%d/n", at2.nData, at2.chData, at2.wData); return 0; }