试试将dwBytesWritten定义成cardinal,
file_attribute_normal or file_flag_overlapped-> 0还有,写入COM口时,不用这么一个字节一个字节的来的
给段例子Function Send232Data(const SendStr:array of char;const SendLen:integer):integer;
var
  iSendNums: Cardinal;
begin
  //gComID是COM的HANDLE
  PurgeComm(gComID, PURGE_TXCLEAR or PURGE_RXCLEAR);  if not WriteFile(gComId,SendStr,SendLen,iSendNums,nil) then begin
    Result := -1;
    exit;
  end;
  if (int(iSendNums) <> SendLen) then begin
    Result := -2;
    exit;
  end;
  Result := iSendNums;
end;

解决方案 »

  1.   

    你在win2000下试验过,好像在win2000下不好用啊
      

  2.   

    唉,现在csdn关注技术的人太少了。
      

  3.   

    我怀疑是delphi3.0有问题,可惜delphi5.0编译的东西大了很多。
      

  4.   

    将1:    HandleID     :=createfile('COM1',generic_read or
                           generic_write,0,nil,open_existing,
                           file_attribute_normal or
                           file_flag_overlapped,0);
    2:    HandleID :=CreateFile('COM2', GENERIC_READ or GENERIC_WRITE,
                             0, Nil,
                             CREATE_ALWAYS,
                             FILE_ATTRIBUTE_NORMAL or FILE_FLAG_OVERLAPPED,
                             0);
    改成
    1:    HandleID     :=createfile('COM1',generic_read or
                           generic_write,0,nil,open_existing,
                           file_attribute_normal ,0);
    2:    HandleID :=CreateFile('COM2', GENERIC_READ or           GENERIC_WRITE,
                             0, Nil,
                             CREATE_ALWAYS,
                             FILE_ATTRIBUTE_NORMAL 0);即可