请高手过来看看。(100分)

  • 主题发起人 主题发起人 kenmen
  • 开始时间 开始时间
K

kenmen

Unregistered / Unconfirmed
GUEST, unregistred user!
1)我对api不大清楚,其实它是怎么回事?delphi里的api与vc++里的有啥不同?<br><br>2)这是最主要的,我想写个网络计费软件,请高手们给个建议。。。<br>&nbsp; &nbsp;应调用那个api呢?还是有其他方法?请高手说详细点。。。
 
现在还写网络计费软件?我CAO!<br>
 
我只是用来学习用的。。。。<br>
 
delphi的api和vc的没啥不同,都是调用系统函数。delphi中的函数声明在windows.pas<br>你一用到api或相关资源,就用windows.pas<br>我见过别人写的记费软件,不正常退出还记费,太差了。
 
你一用到api或相关资源,就用windows.pas<br>----WIN SHELL API 也是吗?<br>
 
1、api就是application Programming Interface 应用编程接口,就是M$对操作系统的操作<br>全部提供了接口函数给你,这样你就不用去管硬件底层是什么样了,为编程带来了方便<br>不过也很惨,程序员除了背的这些函数以外其他什么也不知道。<br>2、网络记费嘛,是看你基于时间还是基于流量;
 
其实对你来说,API和DELPHI的内部函数没有什么不同,你就直接用就行了,别管它是什么东西<br>了,等以后慢慢就懂了。<br>网络计费我没有研究
 
1)那在vc++里用的api也可在delphi里用了吗?<br><br>2)我听说可调用一个api来测出机是否联网了。。。请高手指点。。。
 
API不是VC或是DELPHI的API,而是Windows的API,不管在哪里都可以用的。<br>书上说注册表的HKEY_LOCAL_MACHINE/System/CurrentControSet/Services/RemoteAcces分支<br>下,当计算机示连接时,RemoteConnection的值为00 00 00 00,否则为01 00 00 00
 
API不是VC或是DELPHI的API,而是Windows的API,不管在哪里都可以用的。<br>书上说注册表的HKEY_LOCAL_MACHINE/System/CurrentControSet/Services/RemoteAcces分支<br>下,当计算机示连接时,RemoteConnection的值为00 00 00 00,否则为01 00 00 00
 
to 教父:<br>&nbsp; 这个办法我试过。。。在win9x下可以,<br>但在win2k下不可。。。<br>我是想用api实现的。。。有方法吗?
 
1。在vc++里用的api也可在delphi里用,当编译不行时把相应的声明单元uses一下就行了。<br>比如你要调用SHELLEXECUTE函数,delphi默认的uses如下:<br>uses<br>&nbsp; Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;<br>没有包含shellapi声明单元,所以你要加入才能使用:<br>uses<br>&nbsp; Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, shellapi;<br><br>&nbsp; 当你无法确认某函数是在哪个单元里面声明的话,可到delphi的Source目录下查找包含<br>函数名的pas单元,其名字的前部就是。同时并不是所有的api函数delphi都有声明,<br>所以有些还得自己做,可参看帮助及delphi自带的声明。<br>&nbsp; &nbsp; <br>2。可用icmp.dll中的IcmpSendEcho测试(ping)来测出机是否联网.<br>icmp.dll的函数要自己声明。delphi没提供<br><br><br>
 
有其他的函数吗?
 
多谢pqx的指教。。。<br>但我对icmp.dll的使用不熟。。。<br>能再说说吗?<br>
 
unit ping;<br><br>interface<br><br>uses<br>&nbsp; Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,<br>&nbsp; StdCtrls, winsock;<br><br>type<br>&nbsp; TForm1 = class(TForm)<br>&nbsp; &nbsp; Button1: TButton;<br>&nbsp; &nbsp; ip: TEdit;<br>&nbsp; &nbsp; procedure Button1Click(Sender: TObject);<br>&nbsp; private<br>&nbsp; &nbsp; { Private declarations }<br>&nbsp; public<br>&nbsp; &nbsp; { Public declarations }<br>&nbsp; end;<br><br>&nbsp; ip_option_information = record<br>&nbsp; &nbsp; ttl: char;<br>&nbsp; &nbsp; tos: char;<br>&nbsp; &nbsp; flags: char;<br>&nbsp; &nbsp; optionssize: char;<br>&nbsp; &nbsp; optionsdata: DWORD;<br>&nbsp; end;<br><br>&nbsp; icmp_echo_reply = record<br>&nbsp; &nbsp; address: u_long;<br>&nbsp; &nbsp; status: u_long;<br>&nbsp; &nbsp; roundtriphome: u_long;<br>&nbsp; &nbsp; datasize: integer;<br>&nbsp; &nbsp; reserved: integer;<br>&nbsp; &nbsp; datapointer: u_long;<br>&nbsp; &nbsp; options: ip_option_information;<br>&nbsp; &nbsp; data: array[0..250] of char;<br>&nbsp; end;<br><br>function IcmpCreateFile():DWORD; stdcall; external 'icmp.dll'; <br>function IcmpCloseHandle(IcmpHandle:DWORD):DWORD; stdcall; external 'icmp.dll';<br>function IcmpSendEcho(IcmpHandle, DestinationAddress: DWORD; requestData:<br>&nbsp; &nbsp; &nbsp; &nbsp; string; requestSize: integer; requestOption: DWORD; var replyBuffer:<br>&nbsp; &nbsp; &nbsp; &nbsp; icmp_echo_reply; replySize, timeout: DWORD):DWORD; stdcall; external 'icmp.dll';<br><br>var<br>&nbsp; Form1: TForm1;<br><br>implementation<br><br>{$R *.DFM}<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>var<br>&nbsp; NetAddress: u_long;<br>&nbsp; hFile,ret: dword;<br>&nbsp; msg: string;<br>&nbsp; preturn: icmp_echo_reply;<br>begin<br>&nbsp; NetAddress := inet_addr(pchar(ip.text));<br>&nbsp; hFile:=IcmpCreateFile() ;<br>&nbsp; IF hFile = 0 THEN &nbsp;exit;<br>&nbsp; msg := 'fdsfkj';<br>&nbsp; ret:=IcmpSendEcho(hFile,NetAddress,msg,Length(msg),0,preturn,282,200);<br>&nbsp; IcmpCloseHandle(hfile);<br>&nbsp; if ret &gt; 0 then<br>&nbsp; &nbsp; showmessage('ok')<br>&nbsp; else<br>&nbsp; &nbsp; showmessage('fail');<br><br>end;<br><br>end.<br>
 
等我试试.......
 
不好意思来晚了。上段时间我不能上网,耽搁了。。。<br>to:pqx<br>&nbsp;我试过你的方法,但到<br>&nbsp; ‘var<br>&nbsp; &nbsp; Form1 : TForm1;‘<br>&nbsp;这一步时,他说出错了。<br>&nbsp;‘Identifier redeclared:'Form1'‘<br>&nbsp;请问为啥?我刚学不久,不明,请多多指教。<br><br>还有,我想问问为啥要用到'winsock'?<br>&nbsp;hook是啥,有啥用?
 
to kenmen:<br>Form1 : TForm
 
不是TForm1吗?
 
1.你把人家的代码考到FORM2(当然喽,你的可能不叫这个名字)里去了吧.<br>检查一下其它单元有没有var &nbsp;Form1: TForm1;这个全局变量.<br><br>
 
后退
顶部