Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2341695
  • 博文数量: 816
  • 博客积分: 10000
  • 博客等级: 上将
  • 技术积分: 5010
  • 用 户 组: 普通用户
  • 注册时间: 2008-12-17 17:57
文章分类

全部博文(816)

文章存档

2011年(1)

2008年(815)

分类:

2008-12-17 18:05:38

今天写程序的时候出现一个奇妙的问题,一直没想到原因...
将一段内存数据复制进BUFF,然后发送:
LPVOID CIOQueue::MakeMsg(const DS_DRAWCOMMAND *pDrawCmd,int &nBufSize)
{
nBufSize = sizeof(BYTE)+sizeof(ULONG)*2;
PBYTE pBuf = NULL;
           nBufSize+=sizeof(DS_RECTAGLE);
pBuf = (PBYTE)malloc(nBufSize);
memcpy(pBuf,pDrawCmd,nBufSize);
return (LPVOID)pBuf;
}
这时这个结构体中的一段为:
Rect {nPenSize=2 nPenColor=0 nBkColor=16777215 ...} DS_RECTAGLE
nPenSize 2 unsigned long
nPenColor 0 unsigned long
nBkColor 16777215 unsigned long
nStyle 0 unsigned long
XY {x=156 y=350} tagPOINT
X1Y1 {x=337 y=516} tagPOINT

将接收到的数据再复制回来
DS_DRAWCOMMAND *CIOQueue::MakeCmd(const PBYTE dataBuf,const int nBufSize)
{
DS_DRAWCOMMAND *pCmd = new DS_DRAWCOMMAND;
memset(pCmd,0,sizeof(DS_DRAWCOMMAND));
int nHeaderSize = sizeof(BYTE)+sizeof(ULONG)*2;
memcpy(pCmd,dataBuf,nHeaderSize);
int nBodySize = sizeof(DS_RECTAGLE);
PBYTE pTmpBuf = (PBYTE)pCmd+nHeaderSize;
PBYTE srcBuf = dataBuf+nHeaderSize;
memcpy(pTmpBuf,srcBuf,nBodySize);
}

那段数据成了:
Rect {nPenSize=2 nPenColor=0 nBkColor=16777215 ...} DS_RECTAGLE
nPenSize 2 unsigned long
nPenColor 0 unsigned long
nBkColor 16777215 unsigned long
nStyle 0 unsigned long
XY {x=156 y=516} tagPOINT
X1Y1 {x=337 y=350} tagPOINT

问题是其中两个坐标点的Y值错位了,其它值都正常...传输的数据很少,没有分包,应该不是网络部分的问题

相关的成员
有结构体:
struct DS_DRAWCOMMAND
{
BYTE nCmdType;
ULONG nCmdOwner;
ULONG nCmdID;
union DS_SHAPES Shape;
static FreeDrawCmd(struct DS_DRAWCOMMAND *pDCmd)
{
switch(pDCmd->nCmdType)
{
case TOOLTYPE_PEN:
DS_PEN::FreePoints(pDCmd->Shape.Pen);
break;
case TOOLTYPE_TEXT:
delete[] pDCmd->Shape.Text.pszFontName;
delete[] pDCmd->Shape.Text.pszText;
break;
case TOOLTYPE_IMAGE:
delete[] pDCmd->Shape.Image.pImagePath;
break;
case TOOLTYPE_ERAZE:
DS_PEN::FreePoints(pDCmd->Shape.Pen);
break;
}
}
};
其中联合体:
union DS_SHAPES
{
struct DS_FILLEDRECTAGLE FillRect;
struct DS_RECTAGLE Rect;
struct DS_ELLIPSE Ellipse;
struct DS_CURVE Curve;
struct DS_LINE Line;
struct DS_PEN Pen;
struct DS_BKGND Bkgnd;
struct DS_TEXT Text;
struct DS_IMAGE Image;
};

其中DS_RECTAGLE为
struct DS_RECTAGLE
{
ULONG nPenSize;
ULONG nPenColor;
ULONG nBkColor;
ULONG nStyle;
POINT XY;
POINT X1Y1;
};


--------------------next---------------------

阅读(1060) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~