您的位置:首页 > 运维架构 > Shell

pb7下使用几个Win32 API 的例子

2007-06-21 19:20 381 查看
  pb7下会用到API来处理很多底层的操作。因为PB7在数据库方面强,在别的方面就显得很弱。pb7中使用win32 API 也是很简单的。首先对要使用的win32 API 进行声明,然后就是调用,声明和调用的时候需要注意数据类型。

  声明一般在 Declare  --> Global External Functions 中。

  1,几个文件系统操作的API

声明:

//  用关联的应用程序打开一个文件

    
FUNCTION   long   ShellExecuteA(   ulong   hWnd,   string   Operation,   string   lpFile,string   lpParameters,   string   lpDirectory,   int   nShowCmd   )   LIBRARY   "shell32.dll"     


 
//

  创建一个目录
 Function   boolean   CreateDirectoryA(string   lpPathName,string   lpSecurityAttributes)   Library   "kernel32.dll"


    
//      删除一个空目录


 FUNCTION   ulong   RemoveDirectory(ref   string   lpPathName)   LIBRARY   "kernel32.dll"   ALIAS   FOR   "RemoveDirectoryA"   



调用:


//  打开文件


ShellExecuteA(0,"open","c:Northsnow.doc","","",1) 




//  创建目录


string ls_SecurityAttributes,As_PathName


SetNull(ls_SecurityAttributes)


As_PathName = "c:Northsnow"


CreateDirectoryA(as_PathName,ls_SecurityAttributes)




//  删除空目录


string filePath


filePath="c:Northsnow"


RemoveDirectory(filePath)

文件系统操作的API功能非常强。这里只是列出了刚刚用过的几个而已。比如创建,打开,修改,删除文件和目录,文件系统的拷贝,剪切和粘贴。文件系统的遍历,文件系统属性的操作。

  2,几个FTP连接的API

声明:

 


FUNCTION ulong InternetConnect (ULONG HINTERNET,REF STRING lpszservername ,long nserverport ,ref string lpszusername,ref string lpszpassword,ulong dwsevice,ulong dwflags,ref ulong dwcontext  ) library "WININET.DLL" alias for "InternetConnectA"




FUNCTION boolean FtpGetFile(ulong hconnect ,ref string lpszremotefile,ref string lpsznewfile,boolean ffailifexists,ulong dwflagsandattributes,ulong dwfalgs,ref ulong dwcontext) library "WININET.DLL" alias for "FtpGetFileA"




FUNCTION BOOLEAN FtpPutFile(ulong hconnect ,ref string lpszLocalfile,ref string lpszNewRemoteFile,ulong dwfalgs,ref ulong dwcontext) library "WININET.DLL" alias for "FtpPutFileA"






FUNCTION BOOLEAN FtpDeleteFile (ULONG HCONNECT,REF STRING LPSZLOCALFILE,REF STRING LPSZNWEREMOTEFILE ,ULONG DWFLAGS,REF ULONG DWCONTEXT) LIBRARY "WININET.DLL" ALIAS FOR "FtpPutFileA"




FUNCTION BOOLEAN FtpDeleteFile (ULONG HCONNECT ,REF STRING LPSZFILENAME) LIBRARY "WININET.DLL" ALIAS FOR "FtpDeleteFileA"




FUNCTION BOOLEAN FtpRenameFile (ULONG HCONNECT,REF STRING LPSZEXISTING ,REF STRING LPSZNEW) LIBRARY "WININET.DLL" ALIAS FOR "FtpRenameFileA"




FUNCTION ULONG FtpOpen(ULONG HCONNECT ,REF STRING LPSZFILENAME,ULONG DWACCESS,ULONG DWFLAGS,REF ULONG DWCONTEXT ) LIBRARY "WININET.DLL" ALIAS FOR "FtpOpenFileA" 




FUNCTION BOOLEAN FtpSetCurrentDirectory (ULONG HCONNECT,REF STRING LPSZDIRECTORY) LIBRARY "WININET.DLL" ALIAS FOR "FtpSetCurrentDirectoryA"




FUNCTION BOOLEAN FtpGetCurrentDirectory (ULONG HCONNECT ,REF STRING LPSZCURRENTDIRECTORY,REF ULONG LPDWCURRENTDIRECTORY) LIBRARY "WININET.DLL" ALIAS FOR "FtpGetCurrentDirectoryA" 




FUNCTION ULONG InternetOpen(REF STRING LPSZAGENT,ULONG DWACCESSTYPE,REF STRING LPSZPROXY ,REF STRING LPSZPROXYBYPASS,ULONG DWFLAGS) LIBRARY "WININET.DLL" ALIAS FOR "InternetOpenA"




FUNCTION   long   ShellExecuteA(   ulong   hWnd,   string   Operation,   string   lpFile,string   lpParameters,   string   lpDirectory,   int   nShowCmd   )   LIBRARY   "shell32.dll"     


Function   boolean   CreateDirectoryA(string   lpPathName,string   lpSecurityAttributes)   Library   "kernel32.dll"

 

调用:

 

 


ulong    lnginetconn //被赋予 wininet.dll internetconnect 函数


boolean  ftpgetf     //被赋予 wininet.dll ftpgetfile 函数   


ulong    ulngIetOpen //被赋予 wininet.dll internetopen 函数




string sAgent="liuyang"


string sProxy


string sProxyByPass


ulngIetOpen=InternetOpen(sAgent,0,sProxy,sProxyByPass,0)


lnginetconn=InternetConnect(ulngIetOpen,ftpserver ,ftpport,ftpu,ftpp,1,0,d)








string f


string g 


   //从服务器上取文件


ftpgetf=FtpGetFile(lnginetconn,f,g,false,0,1,d)






string str


boolean bPutFile


string g


ulong e =0


bPutFile= FtpPutFile(lnginetconn,g,str,0,e)  






string  ds


//在ftp服务器上删除文件


ftpdeletef= FtpdeleteFile(lnginetconn,ds) 

 

 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息