主题:请高手指点代码
[code=c]
typedef struct
{
public:
char Port[4];
short BaudRate;
}SerialParam;
int test()
{
SerialParam* a = (SerialParam*)malloc(sizeof(SerialParam));
memcpy(a->Port,"COM1",4);
a->BaudRate = 9600;
CString b;
b.Format("%s",a);
SerialParam *c =NULL;
c = (SerialParam*)(LPCSTR)b;
TRACE("%s",c->Port);
TRACE("%d",c->BaudRate);
return 0;
}
[/code]
C->PORT 的值出现了问题,是否一定要将两个值分开传呢?请指点我的思想哪里有问题。
typedef struct
{
public:
char Port[4];
short BaudRate;
}SerialParam;
int test()
{
SerialParam* a = (SerialParam*)malloc(sizeof(SerialParam));
memcpy(a->Port,"COM1",4);
a->BaudRate = 9600;
CString b;
b.Format("%s",a);
SerialParam *c =NULL;
c = (SerialParam*)(LPCSTR)b;
TRACE("%s",c->Port);
TRACE("%d",c->BaudRate);
return 0;
}
[/code]
C->PORT 的值出现了问题,是否一定要将两个值分开传呢?请指点我的思想哪里有问题。