首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

CopyMemory无法复制常量指针?解决方案

2012-04-11 
CopyMemory无法复制常量指针?constCONST_NAME TESTCopyMemory(@SendBuf, @CONST_NAME, strLen(CONST_

CopyMemory无法复制常量指针?

const
  CONST_NAME = 'TEST';

CopyMemory(@SendBuf, @CONST_NAME, strLen(CONST_NAME));

//出错求解释

[解决办法]
CONST_NAME应该是一个字符串
应该这样
@CONST_NAME[1]
[解决办法]
可以复制的,请看下面的示例,@CONST_NAME[1]下标从1开始

Delphi(Pascal) code
const  CONST_NAME = 'TEST';var  SendBuf: array of Byte;  i: Integer;begin  SetLength(SendBuf,4);  CopyMemory(@SendBuf[0], @CONST_NAME[1], strLen(CONST_NAME));  for i := Low(SendBuf) to High(SendBuf) do    ShowMessage(Char(SendBuf[i]));end;
[解决办法]
const
CONST_NAME = 'TEST';

CopyMemory(@SendBuf, PChar(CONST_NAME), SizeOf(char)*strLen(CONST_NAME));

热点排行