windows的api为什么这么难用?writefile???(30分)

  • 主题发起人 suntofly
  • 开始时间
S

suntofly

Unregistered / Unconfirmed
GUEST, unregistred user!
[?]creatfile都没有问题了,但是writefile的时候就说拒绝访问 那位大侠能帮我找一个<br>writefile &nbsp;的例子研究一下 &nbsp; 谢谢!!<br>&nbsp; &nbsp; &nbsp;hdevice:=CreateFile('//./Passthru',GENERIC_READ and GENERIC_WRITE,<br> 0,//share mode<br> nil,//no security<br> OPEN_EXISTING,<br> FILE_ATTRIBUTE_NORMAL,<br> 0);//no template<br><br>&nbsp; &nbsp; &nbsp; &nbsp; str:='&amp;'+edit1.Text;<br>&nbsp; &nbsp; &nbsp; &nbsp; num:=length(str);<br>&nbsp; &nbsp; &nbsp; &nbsp; //ifwrite:=WriteFileex(hDevice,pchar(str),num+2,ln,nil);<br>&nbsp; &nbsp; &nbsp; &nbsp; ifwrite:=WriteFile(hDevice,pchar(str),num+2,pwnum,ln);<br>&nbsp; &nbsp; &nbsp; &nbsp; num:=getlasterror();<br>&nbsp; &nbsp; &nbsp; &nbsp; ShowMessage(SysErrorMessage(GetLastError));<br>&nbsp; &nbsp; &nbsp; &nbsp; showmessage(inttostr(num));<br>&nbsp; &nbsp; &nbsp; &nbsp; showmessage(str);<br>&nbsp; &nbsp; &nbsp; &nbsp; if num=0 then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; showmessage('writefile succeded!!');<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; showmessage('writefile failed!!');
 
CreateFile这些函数是在写串口通讯时候用的。你看看这方面的说明!
 
createfile时GENERIC_READ and GENERIC_WRITE, 错了<br>应该是 GENERIC_READ or GENERIC_WRITE<br>
 
hehe &nbsp;搞定了 &nbsp; 谢谢![:)]<br>不过能否详细解释一下或者给我些可以参考的api文章 :)
 

Similar threads

I
回复
0
查看
602
import
I
I
回复
0
查看
730
import
I
I
回复
0
查看
825
import
I
I
回复
0
查看
688
import
I
顶部