分类目录
文章索引模板
20070130 windows linux c 编程 - 七月 3, 2007 by yippee

20070130 windows linux c 编程

msys + MinGW + wxWidgets
1. Download MinGW-5.0.2.exe(129k) from sf/mingw
2. Run MinGW-5.0.2.exe, select module(mingw + gcc)
3. The setup program will download what you want automatically from Internet to the directory where the program located, then install those packages automatically to complete install. The package downloaded is below:
mingw-runtime.3.9.tar.gz
w32api-3.6.tar.gz
binutils-2.15.91-20040904-1.tar.gz
gcc-core-3.4.2-20040916-1.tar.gz
gcc-g++-3.4.2-20040916-1.tar.gz
mingw32-make-3.8.0-3.tar.gz

4. Download msys-1.0.10.exe(2742k) from sf/mingw
5. Run msys-1.0.10.exe, then select y,and specify the direcory of mingw.
6. Modify msys.bat to change some font setting.

7. Download wxWidgets-2.6 from wxWidgets.org
8. Enter msys, then execute below command to get wx inc an lib.
$ ./configure –enable-unicode –disable-shared
$ make
$ make install
9. But the sample program compiled with lib above has to be run with mingw10.dll in mingw/bin. That is because of thread module. Two approaches can be done to erase the dependency.
    First, re-configure the makefile.
        $ ./configure –enable-unicode –disable-shared –disable-threads
    Second, Modifying the makefile file manually
       remove all "-mthreads" in makefile
10. Maybe there is an error about ld for lacking of wx lib path. In makefile make LIBDIRNAME = /usr/local/lib to add lib path
11. If the above description can not make any effort, using below command to re-make wx.
    $ make clean
    $ ./configure –enable-unicode –disable-shared –disable-threads
    $ make
    $ make install

[Windows] windows上搭建linux开发环境(zz)
这里所说的开发环境主要是指在windows上使用GCC(GNU Compiler Collection)进行开发,根据需求的不同,我们有以下几种选择:

1. DevC++

这是一款基于MingW的集成开发环境(IDE),适合于C++初学者,可以利用它编写符合标准C++(98)规范的代码,体验GCC的一些特性。

DevC++非常小巧,由Bloodshed Software开发,属于Free Software。
DevC++的最新版本为:DevC++ 5.0 beta9.2(4.9.9.2) with MingW/GCC 3.4.2
DevC++的官方站点为:http://www.bloodshed.net

2. MinGW

MinGW,即Minimalist GNU for Windows,它是GNU工具集(主要是GCC)在Windows上的一个移植,通过它我们可以使用GCC来开发Win32程序。

MinGW是基于命令行的,对于初学者,使用命令行来开发有助于了解其中的细节。不过,如果你不习惯命令行的话,那么也可以选择IDE。前面提到的 DevC++便是对MinGW的一个GUI包装(界面用Delphi开发,在DevC++的安装目录下便能找到MinGW工具包),另外还有一款名为MinGW Developer Stuidio的IDE,它完全效仿了VC6的界面,对于熟悉VC6的朋友来说应该能够很快上手。

不少跨平台的开源软件在Windows上便是以MinGW为编译工具,比如大名鼎鼎的MPlayer。

MinGW的官方站点为:http://www.mingw.org

3. Cygwin

Cygwin由Cygnus公司开发,与MinGW相比,它是一个庞然大物,因为它企图在Windows上搭建整个Linux平台。Cygwin包含两个部分,首先是cygwin1.dll,它是对Linux API的一个模拟,其次是Linux工具集,包含GCC、vi以及grep等几乎所有常用工具。因此,选择Cygwin,我们不仅能使用GCC,更能学习Linux的命令工具。

Cygwin的官方站点为:http://www.cygwin.com

Cygwin的安装和使用方法为:
1) 到官方站点下载setup.exe程序;
2) 运行setup.exe,根据自己需要,可以选择从网络下载并安装或者只下载不安装。Cygwin的默认安装并不包含GCC工具,因此必须自己设置。在进行到“Select Packages”一步时,展开Devel Category,可以看到gcc package的状态为Skip,单击它,Skip将切换成最新的版本号,表示我们将安装它。如果我们要安装所有package,可以单击Category后面的Default标签,其文字将变成Install。编辑工具vi默认也不会被安装,它位于Editors Category目录下。怎样确定我们要安装的工具位于哪个Category下呢?方法是打开Cygwin下载目录(名称类似于ftp%3a%2f%2fcygwin.osuosl.org%2fpub%2fcygwin)下的setup.ini文件,查找@ tool_name(注意:@后面有一空格),比如gcc应查找@ gcc,在其中的描述信息中便包含了工具所属的Category。Cygwin很庞大,如果全部安装的话,听说需要大概4G的空间。
3) 安装完毕后,桌面上将出现一个快捷方式,运行它即可进入虚拟的linux工作环境。另外,我们也可将cygwin安装目录下的bin文件夹所在路径添加到系统PATH环境变量中,这样就可以直接在控制台中使用cygwin下的命令工具,比如运行g++等。

4) Telnet

通过telnet远程登录linux主机,这不同于前面提到的三种方法,因为它其实是在直接使用linux系统。当项目组有多个成员都需要进行linux 开发的时候,我们便可以搭建一个linux工作站,然后开发成员通过telnet到工作站上进行工作。对于大多数时候使用windows偶尔使用 linux的开发人员来说这是一个不错的选择。telnet工具可以使用STEM或者其它类似工具
 经验交流:怎样在 Windows 上建立与在 Linux 上相同的开发环境    
 

事先声明,这篇 HOWTO 只是出于个人兴趣,如果您觉得无聊,请不要浪费您的时间跟帖,谢谢。

目前,由于工作原因,我只能在 Windows 上做程序开发。离开了我所熟悉的 Linux 开发环境,以前做 Linux 程序员时的良好感觉荡然无存。比如我一见到命令行就想敲 ls / ps / find,遇到一个长文件名就想图省事敲 tab 。Windows 的命令行是如此的笨拙,经常让我感到不适。为了保持一个 Linux 的程序员的良好感觉,我在 Windows 上搭建了一个与 Linux 上几乎完全一样的开发环境。

其实做这件事不止有一种方法。最简单的方法是下载并安装 Cygwin。Cygwin 是 GNU 开发工具的 Windows 版。其中包括我们所熟悉的几乎所有 Linux 上的开发和实用工具,例如 gcc,g++,perl,tcl,autoconf,automake,cvs,awk,sed,etc. 甚至连 rpm 都可以在 Cygwin 中使用。安装好 Cygwin 后在桌面上点击其图标就可以进入 Cygwin 的开发环境 — bash。在 Cygwin 的 bash 中我甚至感觉不到自己是在 Windows 上工作。我是在 Windows 上吗?我是在某种 UNIX 上吧。呵呵。:)
Cygwin 可以从这里下载:http://www.cygwin.com

还有一种方法是自己组合出一套 Linux 开发环境,这也是我所采用的方法。
首先我需要一个 GNU 的编译器 — gcc 。目前 Windows 上有 gcc 的很多移植版本,其中限制最少的是 Mingw。Mingw 可以编译真正 native 的 Win32 代码,而且 Mingw 编译出的代码与 VC++ 也最为接近。 Mingw 可以从这里下载:http://www.mingw.org
然后我需要一个功能比较全的 bash,我使用的是另一个 GNU开发工具的 DOS / Windows版 — DJGPP 中移植的 bash。DJGPP 中的开发工具可以从这里下载:ftp://ftp.simtel.net/pub/simtelnet/gnu/djgpp/
同样,DJGPP 中也提供了我们在 Linux 上常用的几乎所有的开发和实用工具。

我还需要一个我在 Linux 上常用的编辑器,比如 vim 或者 emacs。没有问题,vim 的 Windows版 可以从这里下载:http://www.vim.org 。emacs 的 DOS/Windows 版 DJGPP 里就有。
我还需要一些常用的工具,比如 gzip,tar,bzip2,awk,sed,m4,etc. 也没有问题,这些工具 DJGPP 里也有。可是我想用真正的 32 位软件,于是我选择了这些工具的 Mingw 版,可以从这里下载:http://www.mingw.org/ported.shtml

我还想在 Windows 上使用 GTK 开发 GUI 应用程序。同样没有问题,GTK 早就被移植到了 Windows 上,使用的就是 Mingw。GTK for Win32 可以从这里下载:http://www.gimp.org/~tml/gimp/win32//downloads.html

我想有时候我可能会需要用到 Posix 系统调用,尤其是在我移植 Linux 软件到 Windows 上时。做这件事有两种方法,第一种是直接使用 Cygwin 做移植。Cygwin 中有完整的 Posix 系统调用。(使用一个模拟 Posix 调用的 dll ) 但是 Cygwin 的 License 是 GPL,使用 Cygwin 做的所有开发代码必须公开。还有一种方法是使用另外一个基于 DJGPP 的 Posix 模拟库来实现 Posix 系统调用。这个库叫做 PW32 (Posix on Win32),可以从这里下载:http://pw32.sourceforge.net/
除了 PW32 本身外,其作者还移植了很多有用的开发工具,其中包括 bash (又一个bash!),m4,perl,autoconf,automake,awk,sed,etc.。

OK,通过组合 Mingw,DJGPP 和 PW32 中的各种开发工具,我得到了与 Cygwin 差不多相同的开发环境。现在我可以很快乐地使用 GNU 开发工具随心所欲地开发我想开发的任何软件了。

希望这篇文章给大家的周末带来一些乐趣。 如果您对在 Windows 上使用 GNU 开发工具感兴趣,欢迎与我交流。我的邮箱是:
unruly_wind@sina.com

–dlee
(setq what \’Linux)
(message "% make the world better!" what)
 
cygwin/gcc和MinGW都是gcc在windows下的编译环境,但是它们有什么区别,在实际工作中如何选择这两种编译器。
 cygwin/gcc完全可以和在linux下的gcc化做等号,这个可以从boost库的划分中可以看出来端倪,cygwin下的gcc和linux下的gcc完全使用的是相同的Toolsets。
所以完全可以和linux一起同步更新gcc版本,而不用担心问题,并且在cygwin/gcc做的东西(不用win32的)可以无缝的用在linux下,没有任何问题。是在windows下开发linux程序的一个很好的选择。但是在cygwin/gcc下编译出来的程序,在windows执行必须依赖cygwin1.dll,并且速度有些慢,如果不想依赖这个东西的化,必须在gcc的编译选项中加入-mno-cygwin。加入这个选项其实gcc编译器就会自动的选择在安装cygwin/gcc时安上的mingw,这个mingw就是gcc的一个交叉编译。
 对于mingw作为gcc在windows上的一个实现,由于不像cygwin的gcc在一个模拟linux上运行,同时相当一部分linux的工具不能够使用,不过现在已经有Msys这个模拟unix的shell,可以解决很多的问题,不过没有cygwin好用,而cygwin/gcc的no-cygwin选项又依赖于mingw的支持,所以更新的更慢的,现在只是到3.3.3。在mingw下也是可以升级gcc的,不过需要使用msys。升级方法和在cygwin和linux下差不多,就不再罗嗦了。不过就我的升级经验来看好像都不太顺利。具体深入的测试,我也没有时间做了。
 也是可以让cygwin的最新安装的gcc支持no-cygwin,需要再做一遍交叉编译,但是我不会做,只好算了,呵呵,也许那一天我把这个搞定,再开一个贴吧。
 根据以上的分析,如果在windows开发linux程序,cygwin是很好的选择。如果你开发的程序不介意有一个cygwin1.dll的话,也是可以选择cygwin的。如果你是想开发windows下的程序,还要必须用gcc的化,mingw是很好的一个选择。但是在windows下有太多的编译器了,bc,vc,intel c…..。
 顺便说就题外的化,据说gcc4.0.0性能有很大的提升,如果我升级完gcc4后,再编译一把gcc4是不是以后的编译性能会提高很多呢?有机会一定要测试一下了,呵呵。
 
 一个技巧:如何知道当前版本的gcc的安装配置,用命令:gcc -v就可以了,呵呵。
win32下GNU 编译环境搭建
2005年08月09日 00:00:28

eclipse和dev-cpp这些都是调用MinGW或者Cygin来编译调试C/C++程序的. 建议使用MinGW,它全称是Minimal GNU for Win,是GNU开发工具在win32平台上的一个移植,不同于Cygin,MinGW是原生的win32移植,不需要另外的POSIX模拟中间层的支持.另外MinGW项目也发布了一个最小的posix实现接口–msys,移植了很多linux下很方便的小工具,比如ls,vi,rvxt等等. MinGW项目的主页是
    http://www.mingw.org
我们可以在上面下载最新的  MinGW-3.2.0-rc-3.exe 和 MSYS-1.0.10.exe 这两个文件,安装的时候先安装Mingw,然后安装msys.安装完msys之后会跳出一个问题,选y (yes), 然后它问你是不是已经安装了 MinGW, 选y,然后按它的例子输入MinGW的安装路径(比如c:/MinGW),这样msys就把这个路径mount到了安装路径的msys目录下,可以直接使用Mingw的那些工具了.

   好了.装好这两个以后我们就要eclipse编译c文件需要的gcc,gdb,make工具了.为了eclipse能找到它们,要把c:\\MinGW\\ bin目录加到windows的环境变量PATH中. 需要说明的是,c:\\MinGW\\bin目录下的make不是GNU的make,而是mingw32-make.exe,这个是make在windows 下的版本,由于没有posix完整接口,这个make缺少一些标准make的功能,同时也有一些linux下make所不具备的功能. 因为我们后面要用到pkg-config来自动配置GTK+库的路径,这是mingw32-make.exe所不支持的. msys中提供的GNU make是可以的,为了使用它,我们还得把msys安装目录下的bin目录加到环境变量PATH中.
Eclipse+CDT MSYS/MinGW开发GTK+2/Glade跨平台GUI开发环境构建
先声明,不管使用什么高级货IDE,统统都是对make、gcc/g++、GBD的包装,所以,无论用什么IDE,只要在cmd下面跑通了就肯定都没有问题!我习惯eclipse,就用这个做例子了。

一、准备工作:

  就是下载必备软件:
  #Eclipse&CDT:
   http://www.eclipse.org
  #MinGW环境:
   http://www.mingw.org/
   1、MinGW-3.2.0-rc-3.exe
   2、MSYS-1.0.10.exe
   3、msysDTK-1.0.1.exe
   4、msys-libtool-1.5.tar.bz2
  #GTK+ and GTKMM win32 port库:
   1、GTK+/Glade: http://gladewin32.sourceforge.net/
   2、GTKMM: http://www.pcpm.ucl.ac.be/~gustin/win32_ports/gtkmm.html
  
  解释一下上面都是什么东西:
  Eclipse是很好的集成开发环境,广泛应用在j2ee开发上,CDT是一套基于Eclipse平台的C/C++开发插件,功能强大,包括了代码辅助和调试,都很方便。
  MinGW-3.2.0-rc-3.exe和MSYS-1.0.10.exe再啰嗦一下,就是M$ Windows下开发跨平台C/C++的环境,什么cross compiler(gcc/g++之类)、debug(gdb)之类的还有一些标准库,其实在cmd下面一样用,只要装了msys就行,记得运行脚本文件要这样:sh configure;msysDTK-1.0.1.exe和msys-libtool-1.5.tar.bz2都是configure和make时需要的东西,一定要装;GTK+/Glade里面有已经port好了的安装文件,安装后里面除了有GTK的东西外还有glade;GTK是用纯c写的,安装GTKMM的C++封装后,就可以用C++做GTK了,同时,glade–.exe这个win32 port的用来生成glade c++文件的代码生成器也会一同安装。好了,需要详细了解的请看相关软件的linux版的官网,同时,如果不满意或不放心别人port的东西,完全可以在安装了mingw msys后自己来痛苦的port一把,反正我懒得要命。

  接下来要安装这些软件,别怕都是双击安装和解压缩,没啥技术含量。

  1、MinGW-3.2.0-rc-3.exe

  2、MSYS-1.0.10.exe

下面的窗口中全部按回车跳过msys和mingw的自动整合:

  3、msysDTK-1.0.1.exe & msys-libtool-1.5.tar.bz2

msysDTK-1.0.1.exe:

msys-libtool-1.5.tar.bz2解压缩后,copy其中全部的目录到c:\\msys\\1.0\\下面。

  4、GTK+/Glade和GTKMM

不要自动msys整合:

GTK和GTKMM必需都要安装到mingw的路径下:

  5、环境变量设置

添加PATH环境变量:

  在系统环境变量中设置/添加path变量为:c:\\MinGW\\bin;c:\\msys\\1.0\\bin

  6、复制C:\\MinGW\\share\\下全部目录到C:\\msys\\1.0\\share\\下面,这步很关键!不要遗漏!

  7、在cmd下输入 pkg-config –cflags gtkmm-2.4 和 pkg-config –libs gtkmm-2.4 ,如果出现了类似下面的内容就说明你的基本环境应该没什么问题了。

  完成了,你可以玩玩glade了,glade的图标就在你的桌子上面等着呢。

标签:, , ,
1228 SOCKET 编程 资料 - 五月 31, 2007 by yippee

1228 SOCKET 编程 资料

Beej网络socket编程指南    qiujianben(转贴)
http://www.csdn.net/develop/article/18/18237.shtm

Beej\’s 网络编程指南
Internet Sockets
Version 1.5.5 (13-Jan-1999)
[http://www.ecst.csuchico.edu/~beej/guide/net]

WinSock之基础API(二)
http://hi.baidu.com/hnxyy/blog/item/6e96eec467c816a98326ac7a.html

void CSimpleTcpClientDlg::DownloadFile()
&leftsign;
 char buff[512];
 CString s;
 WSADATA wsaData;
 struct hostent *hp;
 unsigned int addr;
 struct sockaddr_in server;
 CString servername;
 CString filepath;
 CString filename; 
 ParseURL(m_url,servername,filepath,filename);
 int wsaret=WSAStartup(0×101,&wsaData);
 if(wsaret) 
  return;
 s.Format("Initialized WinSock");
 m_list.AddString(s);
 SOCKET conn;
 conn=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
 if(conn==INVALID_SOCKET)
  return;
 s.Format("SOCKET created");
 m_list.AddString(s);
 if(inet_addr(servername)==INADDR_NONE)
 &leftsign;
  hp=gethostbyname(servername);
 &rightsign;
 else
 &leftsign;
  addr=inet_addr(servername);
  hp=gethostbyaddr((char*)&addr,sizeof(addr),AF_INET);
 &rightsign;
 if(hp==NULL)
 &leftsign;
  closesocket(conn);
  return;
 &rightsign;
 s.Format("hostname/ipaddress resolved");
 m_list.AddString(s);
 server.sin_addr.s_addr=*((unsigned long*)hp->h_addr);
 server.sin_family=AF_INET;
 server.sin_port=htons(80);
 if(connect(conn,(struct sockaddr*)&server,sizeof(server)))
 &leftsign;
  closesocket(conn);
  return; 
 &rightsign;
 s.Format("Connected to server :- %s",servername);
 m_list.AddString(s);
 sprintf(buff,"GET %s\\r\\n\\r\\n",filepath);
 send(conn,buff,strlen(buff),0);
 s.Format("sending command :- GET %s to server",filepath);
 m_list.AddString(s);
 CFile f;
 int y;
 CString fname="c:\\\\";
 fname+=filename;
 f.Open(fname,CFile::modeCreate &line; CFile::modeWrite);
 s.Format("starting to receive file");
 m_list.AddString(s);
 while(y=recv(conn,buff,512,0))
 &leftsign;
  f.Write(buff,y);
 &rightsign;
 f.Close();
 s.Format("File downloaded and saved :- %s",fname);
 m_list.AddString(s);
 closesocket(conn);
 s.Format("SOCKET closed");
 m_list.AddString(s);
 WSACleanup();
 s.Format("De-Initialized WinSock");
 m_list.AddString(s); 

&rightsign;

server端  
  void   main()  
  &leftsign;  
  SOCKET   socket1;  
   
  InitWinsock();   //初始化,你自己写一个吧  
  struct   sockaddr_in   local;  
  struct   sockaddr_in   from;  
  int   fromlen   =sizeof(from);  
  local.sin_family=AF_INET;  
  local.sin_port=htons(1000);                           ///监听端口  
  local.sin_addr.s_addr=INADDR_ANY;               ///本机  
   
  socket1=socket(AF_INET,SOCK_DGRAM,0);  
   
  bind(socket1,(struct   sockaddr*)&local,sizeof   local);  
   
  while   (1)  
  &leftsign;  
  char   buffer[1024]="\\0";  
  printf("waiting   for   message   from   others————-\\n");  
  if   (recvfrom(socket1,buffer,sizeof   buffer,0,(struct   sockaddr*)&from,&fromlen)!=SOCKET_ERROR)  
  &leftsign;  
  printf("Received   datagram   from   %s–%s\\n",inet_ntoa(from.sin_addr),buffer);  
  ////给cilent发信息  
  sendto(socket1,buffer,sizeof   buffer,0,(struct   sockaddr*)&from,fromlen);  
   
  &rightsign;  
  Sleep(500);  
  &rightsign;  
   
  closesocket(socket1);  
   
   
  &rightsign;  
  Client端  
  void   main()  
  &leftsign;  
  SOCKET   socket1;  
   
  InitWinsock();  
  struct   sockaddr_in   server;  
  int   len   =sizeof(server);  
  server.sin_family=AF_INET;  
  server.sin_port=htons(1000);                                             ///server的监听端口  
  server.sin_addr.s_addr=inet_addr("192.168.1.101");   ///server的地址    
   
  socket1=socket(AF_INET,SOCK_DGRAM,0);  
  while   (1)  
  &leftsign;  
   
  char   buffer[1024]="\\0";  
  printf("input   message\\n");  
  scanf("%s",buffer);  
  if   (strcmp(buffer,"bye")==0)  
  break;  
  if   (sendto(socket1,buffer,sizeof   buffer,0,(struct   sockaddr*)&server,len)!=SOCKET_ERROR)  
  &leftsign;  
  if   (recvfrom(socket1,buffer,sizeof   buffer,0,(struct   sockaddr*)&server,&len)!=SOCKET_ERROR)  
  printf("rece   from   server:%s\\n",buffer);  
  &rightsign;  
  &rightsign;  
  closesocket(socket1);  
  &rightsign;  
 

标签:, ,
1216 FTP 编程 资料 - 五月 19, 2007 by yippee

1216 FTP 编程 资料

ftp下载文件一般步骤如下:
echo open xxx.xxx.xxx.xxx >ftp.txt
echo user >>ftp.txt
echo password >>ftp.txt
echo binary >>ftp.txt [可选]
echo get srv.exe >>ftp.txt
echo bye >>ftp.txt
ftp -s:ftp.txt(这一步是关键哟)
del ftp.txt
存为*.bat
这种方法就是在pb程序中运行Windows中自带的ftp命令。具体做法是在程序中生成一个.bat文件,将要运行的ftp命令写到此文件中,再运行这个批处理文件。假设ftp服务器ip为   202.114.67.2,用户名为user,口令12345,现在要将本地c:\\temp\\下的t00001.txt文件上传到服务器的\\txtdata\\目录下去。则pb代码如下:    
   
  integer   li_bat     //文件名指针  
  li_bat   =   FileOpen(path_ftp+\’get_file.bat\’,    
  lineMode!,   Write!,   LockWrite!,   Replace!)  
   
  FileWrite(li_bat,   \’cd   c:\\temp\\\’)  
  FileWrite(li_bat,   \’ftp   202.114.67.2\’)  
  FileWrite(li_bat,   \’user)  
  FileWrite(li_bat,   \’12345\’)  
  FileWrite(li_bat,   \’put   t00001.txt  
  \\txtdata\\t00001.txt\’)  
  FileWrite(li_bat,   \’bye\’)  
  FileWrite(li_bat,   \’exit\’)  
  FileClose(li_bat)  
  Run(path_ftp+\’get_file.BAT\’,Minimized!)  
  messagebox("提示信息","数据上报完毕")  
   
  —-   此方法的优点是简单易行,既不要调用API函数,也不需加入OLE。缺点一是要运行外部命令,将会打开dos窗口,显得不够和谐;二是数据传输成功与否无法判断,在编程时不好控制。

  2.   使用Internet   Transfer控件    
   
  —-   Internet   Transfer控件是网络编程中非常常用的控件。它支持目前Internet上使用最为广泛的两种协议,即Http和Ftp。在windows98中它是由系统自带。有关此控件的详细资料请查看相关书籍。这里我们只使用它的Ftp功能。在PB中加入一个与此控件的OLE,取名ole_1,并按以下数据设置此控件的属性(注意不是ole_1的属性),表中没有列出的属性请用缺省值:    
   
  属性                         值                     说明  
  Protocol               2                     指定用Ftp协议  
  Remotehost             202.114.67.2  
  Username                 User1  
  Password                 12345  
   
  —-   Internet   Transfer控件支持两种数据传输方式,即同步传输方式和异步传输方式。同步传输方式在数据传输时会阻塞程序,此功能是通过调用该控件的OpenUrl方法来实现的;而异步方式则不会阻塞程序,它通过调用控件的Execute方法来实现。同步方式虽然易于控制,但它只能下载文件,不能上传文件,这使得它在实际的应用受到限制。要实现数据的上传下载,只能使用此控件的异步传输方式。要完成上例中的功能,在PB程序中加入以下语句即可:    
  Ole_1.object.execute("","put   c:  
  \\temp\\t00001.txt       \\txtdata\\t00001.txt")  
   
  —-   同理,如果要将服务器上的文件下载到本地,在程序中加入即下语句:    
  Ole_1.   object.execute("","get   \\txtdata  
  \\t00001.txt     c:\\temp\\t00001.txt")  
   
  —-   Internet   Transfer控件的功能很强大,利用它足以制作一个功能比较完善的FTP工具,而且它是操作系统自带的,在编程时不需要注册新的控件。但根据笔者的使用经验,此控件也有两个不能忽视的缺点,其一、它的数据上传下载是异步传输的,在每次只运行一个ftp命令时尚可,如果一次运行多个ftp命令就会出错。比如说,我们想先进入服务器的\\file目录,再上传数据,这样程序应如下:    
  Ole_1.object.execute("","cd   \\file\\")  
  Ole_1.object.execute("","put    
  c:\\temp\\t00001.txt       \\txtdata\\t00001.txt")  
   
  —-   由于execute方法是异步执行的,它不等第一个语句完成就开始执行第二条语句,这样可能服务器还来不及将当前目录转到\\file下数据已经开始上传,造成错误。    
  —-   其二、笔者还发现一个莫名其妙的问题,那就是利用此控件进行上传时它会将上传到服务器上的文件的文件名改为大写,如上例中,本地的t00001.txt上传到服务器上后,它的名字会变成T00001.TXT,这在NT上自然无妨,但在Unix机器上就可能带来错误。  

  msinet.ocx   也就是实现了ftp和http,直接用mfc好了  
  下面是我写的一个在ftp服务器上写文件的例子  
   
  以下代码经测试通过,我去掉了服务器名和帐号  
  有些防火墙不允许外部ftp   server流入数据,所以我用了Passive模式,即ftpconn=isession.GetFtpConnection("xxx.xxx.xxx.xxx","","",21,true);里的true  
  完整代码如下:  
   
  #include   <afxinet.h>  
  void   CFtptestDlg::OnBtnftp()    
  &leftsign;  
  //   TODO:   Add   your   control   notification   handler   code   here  
  CInternetSession   isession;  
  CFtpConnection*   ftpconn;  
  CInternetFile*   ifile;  
                  //建立ftp连接  
  ftpconn=isession.GetFtpConnection("xxx.xxx.xxx.xxx","","",21,true);  
  if(!ftpconn)  
  &leftsign;  
  TRACE("GetFtpConnection   FAILED!\\n");  
  return;  
  &rightsign;  
                  //在当前目录(根目录)建立一个文件叫   ftptest.txt  
  ifile=ftpconn->OpenFile("ftptest.txt",GENERIC_WRITE);  
  if(!ifile)  
  &leftsign;  
  TRACE("OpenFile   FAILED!\\n");  
  return;  
  &rightsign;  
                  //写数据  
  ifile->Write("test",4);  
  ifile->Close();  
  isession.Close();  
MicrosoftInternetTransferControl使用简介(功能:HTTP及FTP请求,GET及POST方法) Microsoft Internet Transfer Control 使用简介
Example:
Dim objInet
Set objInet = Server.CreateObject("InetCtls.Inet.1")
在VB里面先把它加到部件里,然后直接放到form上面就可以了

1.Get HTTP Page
strHTML = objInet.OpenURL(strURL)
或者
objInet.URL = strURL
strHTML = objInet.OpenURL

2.Get HTTP File
\’我还不知道在ASP里面怎么用,有知道的请指点。
Dim b() As Byte
b() = objInet.OpenURL(strURL, icByteArray)
If UBound(b) < 1 Then
    strErrorMsg = "无法打开该URL地址!"
Else
    Open FileName For Binary Access Write As #1
    Put #1, , b()
    Close #1
End If

3.Get FTP File
\’如果不是匿名的话
objInet.Username = "yourname"
objInet.Password = "yourpass"
objInet.URL = "ftp://ftp.pku.edu.cn"
objInet.Execute , "CD dir1"
objInet.Execute , "GET xx.exe c:\\download\\xx.exe"
objInet.Execute , "QUIT"

4.List FTP Files
objInet.URL = "ftp://ftp.pku.edu.cn"
objInet.Execute , "DIR /dir1"
Private Sub objInet_StateChanged(ByVal State As Integer)
       \’因为Execute方法执行后并不是马上返回结果的,所以必须在StateChanged事件中处理
Dim vtData As Variant \’数据变量。
Dim strData As String: strData = ""
Dim bDone As Boolean: bDone = False
    If State = 12 Then
        vtData = objInet.GetChunk(1024, icString)
              DoEvents
              Do While Not bDone
                 strData = strData & vtData
                 DoEvents
                 vtData = objInet.GetChunk(1024, icString)
                 If Len(vtData) = 0 Then
                        bDone = True
                 End If
              Loop
    End If
    MsgBox(strData)
End Sub  

5.Use Proxy Server
objInet.Proxy = "proxy.io.com:3128"
objInet.AccessType = icNamedProxy

6.Use HTTP Get & Post
objInet.Execute "http://www.c hinaasp. com/sqlbbs/wwwboard.asp", "GET", "id=1"
要用Post只需要把GET那几个字符换一下就可以了,取得返回值的方法同4

Visual Basic專業版和企業版包含了三種ActiveX控制項,這三種控制項提供了不同層次的Internet通訊功能。

WinSock控制項(MSWINSCK.OCX)提供了低階的Transfer Control Protocol (TCP)和User Datagram Protocol (UDP)兩種在Internet上面應用的網路通訊協定。使用WinSock控制項的交談型應用程式,可以在多部電腦之間直接進行資料交換。
 
InternetTransfer控制項(MSINET.OCX)讓你能從HTTP(Hypertext Transfer Protocol)或FTP (File Transfer Protocol)伺服器上複製檔案到自己的機器上,而且也可以讓你瀏覽檔案的目錄,以及以同步或非同步的模式來讀取資料。這個控制項可以用來發展具有FTP瀏覽功能和檔案傳輸功能的應用程式。
 
WebBrowser控制項(SHDOCVW.DLL)把所有Microsoft Internet Explorer (IE)的功能全部包裝在一個控制項裡,你可以用這個控制項在某個應用程式裡加入一個Internet瀏覽器,或者可以在某個應用程式裡透過WebBrowser控制項來控制Internet Explorer。
 
http://webmail.vh.com.tw/Microsoft/Microsoft%20Visual%20Basic%206.0%20程式設計實務手冊/7.htm
7. Internet元件的應用

Open "c:\\ftp.dat" For Output As #1
Print #1, "o xxx.xxx.xxx.xxx"
Print #1, "user anonymous"
Print #1, "pass itsme@"
Print #1, "put " & sFile
Print #1, "quit"
Close #1

Shell "command.com /c ftp.exe -n -s:c:\\ftp.dat", vbHide
Private Declare Function InternetOpen Lib "wininet.dll" Alias "InternetOpenA" _  
3     (ByVal sAgent As String, ByVal lAccessType As Long, _  
4     ByVal sProxyName As String, ByVal sProxyBypass As String, ByVal lFlags As Long) As Long 
5  
6 Private Declare Function InternetCloseHandle Lib "wininet" (ByRef hInet As Long) As Long 
7  
8 Private Declare Function InternetReadFile Lib "wininet.dll" _  
9     (ByVal lngHFile As Long, ByVal strBuffer As String, _  
10     ByVal lNumBytesToRead As Long, lNumberOfBytesRead As Long) As Integer 
11  
12 Private Declare Function InternetConnect Lib "wininet.dll" Alias "InternetConnectA" _  
13     (ByVal hInternetSession As Long, ByVal sServerName As String, _  
14     ByVal nServerPort As Integer, ByVal sUsername As String, _  
15     ByVal sPassword As String, ByVal lService As Long, _  
16     ByVal lFlags As Long, ByVal lContext As Long) As Long 
17  
18 Private Declare Function FtpSetCurrentDirectory Lib "wininet.dll" Alias "FtpSetCurrentDirectoryA" _  
19     (ByVal hFtpSession As Long, ByVal lpszDirectory As String) As Boolean 
20  
21 Private Declare Function FtpOpenFile Lib "wininet.dll" Alias "FtpOpenFileA" _  
22     (ByVal hFtpSession As Long, ByVal sBuff As String, ByVal Access As Long, _  
23     ByVal Flags As Long, ByVal Context As Long) As Long 
24  
25 Private Declare Function FtpFindFirstFile Lib "wininet.dll" Alias "FtpFindFirstFileA" _  
26     (ByVal hFtpSession As Long, ByVal lpszSearchFile As String, lpFindFileData As WIN32_FIND_DATA, _  
27     ByVal dwFlags As Long, ByVal dwContent As Long) As Long 
28  
29 Private Declare Function InternetFindNextFile Lib "wininet.dll" Alias "InternetFindNextFileA" _  
30     (ByVal hFind As Long, lpvFindData As WIN32_FIND_DATA) As Boolean 
31  
32 Private Declare Function FtpGetFile Lib "wininet.dll" Alias "FtpGetFileA" _  
33     (ByVal hConnect As Long, ByVal lpszRemoteFile As String, ByVal lpszNewFile As String, _  
34     ByVal fFailIfExists As Long, ByVal dwFlagsAndAttributes As Long, _  
35     ByVal dwFlags As Long, ByRef dwContext As Long) As Boolean 
36  
37 Private Type FILETIME  
38         dwLowDateTime As Long 
39         dwHighDateTime As Long 
40 End Type  
41  
42 Private Type WIN32_FIND_DATA  
43         dwFileAttributes As Long 
44         ftCreationTime As FILETIME  
45         ftLastAccessTime As FILETIME  
46         ftLastWriteTime As FILETIME  
47         nFileSizeHigh As Long 
48         nFileSizeLow As Long 
49         dwReserved0 As Long 
50         dwReserved1 As Long 
51         cFileName As String * 260  
52         cAlternate As String * 14  
53 End Type  
54  
55 Private Sub Download()  
56     Dim cltFile As New Collection  
57     Dim lngLoop As Long 
58     Set cltFile = GoGoGo("220.111.222.22", "hammer", "haha", "/工具區", "C:\\")  
59     For lngLoop = 1 To cltFile.Count  
60         MsgBox cltFile.Item(lngLoop) \’ 在這裡接上您的程式  
61     Next 
62 End Sub 
63  
64 Private Function GoGoGo(strFTP As String, _  
65                                         strUser As String, _  
66                                         strPswd As String, _  
67                                         strFtpDir As String, _  
68                                         strDownDir As String, _  
69                                         Optional strFileType As String = "*.TXT") As Collection  
70       
71     Dim lngHOpen As Long, lngHFile As Long, lngHConn As Long, lngRet As Long 
72     Dim strFile As String, strBuffer As String, strContent As String 
73     Dim lngLoop As Integer 
74       
75     lngHOpen = InternetOpen("Power Hammer", 1, vbNullString, vbNullString, 0)  
76     lngHConn = InternetConnect(lngHOpen, strFTP, 0, strUser, strPswd, 1, &H8000000, 0)  
77       
78     If FtpSetCurrentDirectory(lngHConn, strFtpDir) Then \’ 切到您要的 FTP 資料夾  
79         Set GoGoGo = GetFileList(lngHConn, strFileType) \’ 取得檔案 List  
80         With GoGoGo  
81             For lngLoop = 1 To .Count  
82                 \’ 進行檔案下載  
83                 FtpGetFile lngHConn, .Item(lngLoop), strDownDir & .Item(lngLoop), False, 0, &H0, 0  
84                 DoEvents  
85             Next 
86         End With 
87     End If 
88       
89     InternetCloseHandle lngHConn  
90     InternetCloseHandle lngHFile  
91     InternetCloseHandle lngHOpen  
92       
93 End Function 
94  
95 \’ 取得某 FTP 資料夾內所有 .TXT 檔案  
96 Private Function GetFileList(lngHConn As Long, strFileType As String) As Collection  
97     Dim cltFile As New Collection  
98     Dim lngHFind As Long 
99     Dim varFile As WIN32_FIND_DATA  
100     varFile.cFileName = String(256, 0)  
101     lngHFind = FtpFindFirstFile(lngHConn, strFileType, varFile, 0, 0)  
102     cltFile.Add Left(varFile.cFileName, InStr(1, varFile.cFileName, Chr(0), 0) – 1)  
103     Do While InternetFindNextFile(lngHFind, varFile)  
104         cltFile.Add Left(varFile.cFileName, InStr(1, varFile.cFileName, Chr(0), 0) – 1)  
105     Loop 
106     Set GetFileList = cltFile  
107 End Function 

标签:, ,
0426 DNS 编程 注册表取值 - 十月 6, 2006 by yippee

0426 DNS 编程 注册表取值

注册表取值:
读取注册表
LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Services\\tcpip\\parameters下的nameserver,多个dns以逗号分开.
读注册表
在 LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Services\\tcpip\\parameters
\\Interfaces\\&leftsign;17CE8728-AA4E-44BE-9F76-52C5F3B99842&rightsign;\\NameServer

&leftsign;17CE8728-AA4E-44BE-9F76-52C5F3B99842&rightsign;字符串根据网卡的不同而不同,通过下列代码获得
function GateWay:string;
var
Reg :TRegistry;
MyStr : TStrings;
buffer : array[0..1024] of byte;
i:integer;
info:TRegKeyInfo ;
str:string;
begin
Result:=\’\';
Reg :=TRegistry.Create;
Mystr:=Tstringlist.Create;
Reg.RootKey :=HKEY_LOCAL_MACHINE;
if Reg.OpenKey(\’SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\NetworkCards\’,false) then
begin
if reg.GetKeyInfo(info) then
begin
reg.GetKeyNames(mystr);
str:=\’SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\NetworkCards\\\’+Mystr.Strings[0];
end;
end;
Reg.CloseKey;
Mystr.Free;
Reg.RootKey :=HKEY_LOCAL_MACHINE;
if reg.OpenKey(str,false) then
str:=reg.ReadString(\’ServiceName\’);
Reg.CloseKey;
Reg.free;
Result:=Str;
end;

はじめまして松本と申します。
いつも参考にさせて頂いております。

さて、早速ですが質問させていただきます。

現在DNSの各レコードの検索を実装するクラスを作成しております。
(nslookupとほぼ同程度)
DNSサーバに回答請求を送るのですが、
送り先のDNSサーバのIPアドレスの取得方法について質問です。

NTの場合は、Platform SDK の RegQueryValueEx()を使って、
レジストリの
"HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters"
から"NameServer"を検索し、その値を取得できることはわかっております。

2000の場合、上記のレジストリが存在しません。
どのように取得すれば良いでしょうか?

因みに開発環境は、
VC++ 6.0 sp2
Platform SDK February 2001 Edition

标签:, ,
0426 DNS 编程 API - 十月 5, 2006 by yippee

0426 DNS 编程 API 编程

api
DnsQueryConfig
DnsQueryConfig
The DnsQueryConfig function enables application programmers to query for the configuration of the local computer or a specific adapter.

DNS_STATUS WINAPI DnsQueryConfig(DNS_CONFIG_TYPE Config,DWORD Flag,PWSTR pwsAdapterName,PVOID pReserved,
PVOID pBuffer,PDWORD pBufferLength);
Parameters Config
[in] Structure specifying query requests. The following parameters can be queried:
DnsConfigPrimaryDomainName_W, DnsConfigPrimaryDomainName_A, DnsConfigPrimaryDomainName_UTF8, DnsConfigAdapterDomainName_W,
DnsConfigAdapterDomainName_A, DnsConfigAdapterDomainName_UTF8, DnsConfigDnsServerList, DnsConfigSearchList, DnsConfigAdapterInfo,
DnsConfigPrimaryHostNameRegistrationEnabled, DnsConfigAdapterHostNameRegistrationEnabled, DnsConfigAddressRegistrationMaxCount
Flag
[in] Specifies whether the configuration should be associated with a LocalAlloc function call. Set Flag to TRUE to associate the query.
pwsAdapterName
[in] Specifies the adapter name against which the query is run. pReserved Reserved for future use. pBuffer
[out] Pointer to the buffer storing the query response.
pBufferLength
[in, out] Length of the buffer, in bytes. If the buffer provided is not sufficient, an error is returned and pBufferLength contains the minimum necessary buffer size. Ignored on input if Flag is set to TRUE.
Return Values Returns success confirmation upon successful completion. Otherwise, returns the appropriate DNS-specific error code as defined in Winerror.h.

Requirements Windows NT/2000: Requires Windows 2000. Header: Declared in Windns.h.Library: Use Dnsapi.lib.
DNS Functions
The following functions are defined for DNS:

DnsAcquireContextHandle
DnsExtractRecordsFromMessage
DnsModifyRecordsInSet
DnsNameCompare
DnsQuery
DnsQueryConfig
DnsRecordCompare
DnsRecordCopyEx
DnsRecordListFree
DnsRecordSetCompare
DnsRecordSetCopyEx
DnsRecordSetDetach
DnsReleaseContextHandle
DnsReplaceRecordSet
DnsValidateName
DnsWriteQuestionToBuffer

Domain Name System Purpose
Domain Name System (DNS), a locator service in Microsoft Windows, is an industry-standard protocol that locates computers on an IP-based network. IP networks, such as the Internet and Windows networks, rely on number-based addresses to process data. Users however, can more easily remember name addresses, so it is necessary to translate user-friendly names (www.microsoft.com) into addresses that the network can recognize (207.46.131.137).
Where Applicable
Windows and Active Directory use DNS. DNS is the primary locator service for the Internet and Active Directory, and therefore, DNS is considered a base service for Windows and Active Directory.
Developer Audience
Windows provides functions that enable application programmers to use DNS, such as programmatic DNS query, record compare, and name lookup.
Programmable DNS components are designed for use by C/C++ programmers. Familiarity with networking and DNS is required. Programmers should be familiar with the IP-protocol suite, as well as the DNS protocol and DNS operations.
Run-Time Requirements
DNS is used on all IP networks that require an Internet-compatible locator service. However, the DNS API requires Windows 2000 or later.

About Domain Name System
Domain Name System (DNS) is an industry-standard protocol used to locate computers on an IP-based network. Users can remember display names, such as www.microsoft.com or msdn.microsoft.com, easier than number-based addresses, such as 207.46.131.137.
IP networks, such as the Internet and Windows 2000 networks, rely on number-based addresses to transmit data throughout the network; therefore, it is necessary to translate display names ( www.microsoft.com) into numeric addresses that the network can recognize (207.46.131.137). DNS is the service of choice in Windows 2000 to locate such resources and translate them into IP addresses.
DNS is the primary locator service for Active Directory, and therefore, DNS can be considered a base service for both Windows 2000 and Active Directory. Windows 2000 provides functions that enable application programmers to use DNS functions such as programmatically making DNS queries, comparing records, and looking up names.
Many DNS functions are actually function types, in that there is a base name for the function, but its use depends on character encoding. For example, the DnsQuery function is listed in the function reference of the DNS Application Programming Interface (API) as DnsQuery, but its use in applications depends on whether the character encoding is ANSI (designated by appending _A to the function type name), Unicode (designated by appending _W to the function type name), or UTF-8 (designated by appending _UTF to the function type name). Therefore, the function call for the DnsQuery function would actually be one of the following:
DnsQuery_A (_A for ANSI encoding)
DnsQuery_W (_W for Unicode encoding)
DnsQuery_UTF8 (_UTF8 for UTF-8 encoding)
All functions that require this convention clearly state this requirement within the first few sentences of their function definition. Use the proper function name; for example, you cannot simply call DnsQuery instead of DnsQuery_A.

标签:, ,
0423  wince vs2003 编程 mainmenu - 九月 25, 2006 by yippee

0423  wince vs2003 编程 mainmenu

装了一大堆模拟器

您当前已安装了下列面向此平台运行应用程序的设备。
WWE SP 2003 SE QVGA (Virtual Radio) – SDK Emulator
WWE SP 2003 SE (Virtual Radio) – SDK Emulator
CHS Smartphone 2003 (Virtual Radio) – SDK Emulator (默认)
CHS Smartphone 2003 (Radio Required) – SDK Emulator
Smartphone Device
Smartphone 2003 Emulator (Virtual Radio)
Smartphone 2003 Emulator (Radio Required)
 
2006-04-19  22:17             2,245 Device Emulator Manager.lnk
2006-04-19  22:04             2,242 Emulate Pocket PC-WM 2003 SE Square(Cold Bot).lnk
2006-04-19  22:04             2,000 Emulate Pocket PC-WM 2003 SE Square(Restore.lnk
2006-04-19  22:04             2,206 Emulate Pocket PC-WM 2003 SE(Cold Boot).lnk
2006-04-19  22:17             2,269 Emulate Pocket PC-WM 2003 SE(Restore).lnk
2006-04-19  22:17             2,495 Emulate Smartphone-WM 2003 SE(Cold Boot).ln
2006-04-19  22:17             2,285 Emulate Smartphone-WM 2003 SE(Restore).lnk
2006-04-19  22:05             2,235 Register Device Emulator.lnk

准备制作第一个程序,倒腾半天,原来MAINMENU的第一个菜单不能有子菜单
否则
未处理的“System.NotSupportedException”类型的异常出现在 System.Windows.Forms.dll 中。

其他信息: NotSupportedException
未处理的“System.NotSupportedException”类型的异常出现在 System.Windows.Forms.dll 中。

其他信息: NotSupportedException

线程 \’<无名称>\’ (0×41314) 已退出,返回值为 0 (0×0)。
线程 \’<无名称>\’ (0×56694) 已退出,返回值为 0 (0×0)。
程序“[2528] rundll32.exe: kuandai.exe”已退出,返回值为 0 (0×0)。

System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(frmmain));
   this.mainMenu = new System.Windows.Forms.MainMenu();
   this.menuItem5 = new System.Windows.Forms.MenuItem();
   this.menuItem6 = new System.Windows.Forms.MenuItem();
   this.menuItem7 = new System.Windows.Forms.MenuItem();
   this.menuItem8 = new System.Windows.Forms.MenuItem();
   //
   // mainMenu
   //
   this.mainMenu.MenuItems.Add(this.menuItem5);
   this.mainMenu.MenuItems.Add(this.menuItem6);
   //
   // menuItem5
   //
   this.menuItem5.MenuItems.Add(this.menuItem8);
   this.menuItem5.Text = "计算";
   //
   // menuItem6
   //
   this.menuItem6.MenuItems.Add(this.menuItem7);
   this.menuItem6.Text = "系统";
   //
   // menuItem7
   //
   this.menuItem7.Text = "退出";
   //
   // menuItem8
   //
   this.menuItem8.Text = "测试";
   //
   // frmmain
   //
   this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
   this.Menu = this.mainMenu;
   this.Text = "test";
   this.Load += new System.EventHandler(this.frmmain_Load);

标签:, , , ,
perl7 编程 embperl安装1 - 九月 14, 2005 by yippee

安装Embperl ppd,根据 http://perl.apache.org/embperl/pod/INSTALL.htm
As last step you can install the Embperl ppd:
+ If you have Perl 5.8.x:
    ppm install http://theoryx5.uwinnipeg.ca/ppms/Embperl-1.ppd
  This is an Embperl 2 ppd, the "-1" at the end of the package name  denotes that this ppd is for mod_perl 1.x. There is no Embperl 1 ppd  for Perl 5.8.x (yet).
+ If you have Perl 5.6.x:
  – Embperl 1: www.yippeesoft.com
    ppm install http://theoryx5.uwinnipeg.ca/ppmpackages/HTML-Embperl.ppd
  – Embperl 2:
    ppm install http://theoryx5.uwinnipeg.ca/ppmpackages/Embperl.ppd
 

ppm> install http://theoryx5.uwinnipeg.ca/ppms/Embperl-1.ppd
====================
Install \’Embperl-1\’ version 2.0b9 in ActivePerl 5.8.7.813.
====================
Downloaded 675673 bytes.
Extracting 112/112: blib www.yippeesoft.com
Files found in blib\\arch: installing files in blib\\lib into architecture depende
nt library tree

The library libxml2.dll is needed to complete the installation,
and should be placed in a directory somewhere in your PATH
environment variable. I can fetch and install this for you,
if you don\’t already have it.

Fetch libxml2.dll? [yes]

如果此时按下 CTRL+C,结果会提示中断进程,但是最后问题是DOS窗口无法退出,输入EXIT也都是出现,是否中断BAT?!

修改 HTTPD.CONF www.yippeesoft.com
LoadModule embperl_module "O:/php/perl/site/lib/auto/Embperl/Embperl.dll"

结果 www.yippeesoft.com
Syntax error on line 177 of O:/php/Apache Group/Apache2/conf/httpd.conf:
Cannot load O:/php/perl/site/lib/auto/Embperl/Embperl.dll into server: \\xd5\\xd2\\
xb2\\xbb\\xb5\\xbd\\xd6\\xb8\\xb6\\xa8\\xb5\\xc4\\xc4\\xa3\\xbf\\xe9\\xa1\\xa3
Note the errors or messages above, and press the <ESC> key to exit.  6….

搞了半天也没有办法解决~~~~~

http://203.64.183.130/~yst/ruby/PART1/web-db-4.htm
第四課 Embperl: 將Perl嵌入HTML
Perl/ASP和Embperl ?
前面在 Perl/ASP中己學過如何將 Perl敘述嵌入HTML之中,那Embperl又有什麼特別的地方?
Embperl 可在CGI和ASP mode執行﹐也可在命令提示字元下執行﹐方便除錯?
Embperl能自動辨識像Table等標籤﹐對顯示資料庫查詢結果非常方便﹐省去for/while迴圈
Embperl 的安裝
【準備工作】確認先前所安裝的Perl的執行檔之路徑已加入環境變數PATH之中。
打開命令提示字元視窗﹐輸入 ppm 命令﹐輸入 search Embperl﹐查看所搜尋到的Ebperl之版本全名﹐然後輸入 install ?所搜尋到Ebperl版本全名?﹐(例如﹐Embperl-1)﹐等安裝完成後輸入exit 結束ppm﹐再輸入exit關閉令提示字元視窗。
在Apache的設定檔httpd.conf最後面(只要在載入mod_perl之後即可)輸入下列指令:
LoadModule embperl_module Perl的安裝路徑/site/lib/auto/Embperl/Embperl.dll
另外在與httpd.conf同目錄的 perl.conf檔案後面附加下列的指令
PerlModule Embperl
AddType text/html .epl
<Files *.epl>
SetHandler perl-script
PerlHandler Embperl
Options ExecCGI
</files>  www.yippeesoft.com
存檔後﹐重新啟動Apache即可。以後Embperl的檔案就以 .epl為副檔名。
Embperl 的標籤
Embperl和 Perl/ASP基本上很像﹐就是在HTML檔案中嵌入Perl的敘述﹐只是標籤不太相同﹐Embperl的功能較多樣化。
Embperl的 [- ... -] 和Perl/ASP的 <% … %> 一樣﹐標籤裡面的敘述會被執行。
Embperl的 [+ ... +] 和Perl/ASP的 <%= … %> 一樣﹐標籤裡面的運算式會被顯示出來。
Embperl的 [! ... !] 內的敘只會執行一遍﹐常用在定義函數方面。
Embperl還有些所謂的 Meta Command是放在 [$ . . . $] 之間﹐用來做流程控制﹐如 if-else, for, while, sub(函數) 等等﹐方便HTML的產生。當然我也可以不用Meta Command﹐直接在 [- ... -] 之中利用Perl的流程控制敘述來達成類似效果。
Embperl最有趣的地方之一就是它會辨認HTML標籤﹐像有重複性的HTML標籤如 <OL>, <UL>, Table中的<tr> <td>, 和表單中的Select的OPTION選項等等﹐Embperl會自產生一個counter (也像c++的Iterator)﹐我們可省去for或while迴圈。這種功能你在PHP或Perl/ASP內看不的﹐(IIS的JScript, PerlScript和 VB也沒有)﹐你只能在像ColdFusion這類要錢的網頁開發工具上看到這功能。
既生瑜,何生亮? Embperl和Perl/ASP都是以Perl語言為底的工具﹐而Perl/ASP功能好像少很多﹐那Perl/ASP的存在有何意義? 其實不然﹐Perl/ASP的程式不只在Apache上可以用﹐它也可在IIS的PerlScript使用。但Apache可在Windows和Linux等各種平台上架站﹐速度快﹐功能又多﹐誰又會去想IIS呢。若是你這樣想的話﹐Embperl的確是較吸引人!
Embperl還有一大堆功能﹐我們想快速上手﹐先學一些基礎的技術即可﹐暫且不管其它複雜的功能。對有意深入的人﹐可到Embperl總站取得多資訊。
和Embperl角色類似的免費的網頁開發工具還有 Mason, AxKit等等﹐有興趣的人可參觀 Apache的Perl網頁參觀﹐感受一下這些在開放原始碼(Open Source)的政策下所產生出來的智慧結晶。技術透明化﹐開放交流﹐只要肯用心學習的人﹐都可以學到專業級的技術。這絶非是少數自私和壟斷的軟體企業所能提供的。

表單參數的處理
Embperl表單參數基本上用下列兩個物件
$fdat&leftsign;\’表單參數名稱\’&rightsign;: 其中 %fdat是一個Hash table
@ffld : 是一個含有所有表單參數名稱的陣列
範例 1
輸入下列含有表單的網頁檔(htm)存入 C:/Apache/Apache/htdocs/Teach/embperl/ 目錄下﹐檔名取做 ex501.htm
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=big5" />
</head>
<body>
<form method=post action=ex501.epl>
輸入姓名: <input type=text name=user> <p>
<input type=submit value="繼續">
</form>
</body>
</html>
 
輸入下列Embperl檔存入 C:/Apache/Apache/htdocs/Teach/embperl/ 目錄下﹐檔名取做 ex501.epl
<CENTER>
<H1> 歡迎 <U> [+ $fdat&leftsign;user&rightsign; +] </U> 進入Embperl的世界! </H1>
<CENTER>
自己瀏覽一下吧!

标签:, ,
perl6 编程 embperl 1 - 九月 14, 2005 by yippee

一直不习惯PERL直接PRINT输出HTML,想如果象PHP一样就方便了,看看

把程式語言嵌在 HTML 裡, 一直是許多網頁計者的夢想… 最近紅透半邊天的 PHP (讓 M$ 的 ASP 靠邊站), 成為廣大網站設計者的最愛(超過100萬個站台), 身為 Perl 的愛好者, 不禁要問: Perl 也可以嵌在 HTML 中嗎? 答案是: 可以的! www.yippeesoft.com

以下為您介紹三種不錯的 Embed Perl:

Mason – http://www.masonhq.com/

Embperl – http://perl.apache.org/embperl/index.html

ePerl – http://www.engelschall.com/sw/eperl/

首先, 您必須安裝好 Apache + mod_perl

Mason安裝法:

perl Makefile.PL
make
make install
修改 httpd.conf, 加入:

PerlRequire /usr/local/mason/handler.pl

Alias /mason /usr/local/www/htdocs

<location /mason> www.yippeesoft.com
 SetHandler perl-script
 PerlHandler HTML::Mason
</location>

重新啟動 Apache.
範例: www.yippeesoft.com
http://www.tnc.edu.tw/ml/TestMason.htm
http://www.tnc.edu.tw/ep/ePerl_test.htm
http://www.tnc.edu.tw/emp/embperl_test.htm

Embperl 及 ePerl 的安裝法類似,請自行參考程式包中的安裝說明.

可是我实在WINDOWS下面,实在没有办法直接安装。 www.yippeesoft.com

进行搜索也不行 www.yippeesoft.com
ppm> search Embperl
Searching in Active Repositories
No matches for \’Embperl\’; see \’help search\’.
ppm> install http://apache.osuosl.org/perl/win32-bin/ppmpackages/Embperl.ppd
Error: no suitable installation target found for package Embperl.
ppm> install http://apache.osuosl.org/perl/win32-bin/ppmpackages/Embperl.ppd
Error: no suitable installation target found for package Embperl.
ppm> install http://www.eu.apache.org/dist/perl/win32-bin/ppmpackages/HTML-Embpe
rl.ppd
Error: no suitable installation target found for package HTML-Embperl.

又搜索了半天,看到这个 www.yippeesoft.com

OSSP eperl interprets a text file bristled with Perl program statements by evaluating the Perl code while passing through the plain text data. It can operate in various ways: As a stand-alone Unix filter or integrated Perl module for general file generation tasks and as a powerful webserver scripting language for dynamic HTML page programming.
http://www.ossp.org/pkg/tool/eperl/

最后发现这个Embperl-1: version 2.0b9 www.yippeesoft.com
abstract: Embed Perl code in HTML documents (using mod_perl 1)
author: Gerald Richter <richter@dev.ecos.de>

ppm> install http://theoryx5.uwinnipeg.ca/ppms/Embperl-1.ppd
====================
Install \’Embperl-1\’ version 2.0b9 in ActivePerl 5.8.7.813.
==================== www.yippeesoft.com
Transferring data: 228794/675673 bytes.

Fetching http://theoryx5.uwinnipeg.ca/ppms/scripts/libxml2.dll …  done!
Where should libxml2.dll be placed? [O:\\php\\perl\\bin]
libxml2.dll has been successfully installed to O:/php/perl/bin
Successfully installed Embperl-1 version 2.0b9 in ActivePerl 5.8.7.813.

标签:,
perl 5 编程 mod_perl - 九月 14, 2005 by yippee

mod_perl 是个庞大而复杂的工具,它内建了许多模块帮助你方便地构建动态网站。这篇指南的目的是帮助你构建一个良好的 mod_perl 模块,并从中理解 mod_perl 的实现技术。我并不推荐使用这里介绍的技术来建立一个大型站点,尤其对于一个刚刚涉足 mod_perl 的人来说。但我推荐大家可以深入看一下它的一些内建的方案,比如 Mason, AxKit, EmbPerl, Apache::ASP 和 PageKit 等等。

运行PPM www.yippeesoft.com
运行ppm> install http://theoryx5.uwinnipeg.ca/ppms/mod_perl.ppd

中间提示下载 mod_perl.so,指示路径到
O:\\php\\Apache Group\\Apache2\\modules

最后报告: www.yippeesoft.com
Fetching http://theoryx5.uwinnipeg.ca/ppms/x86/mod_perl.so …  done!
Where should mod_perl.so be placed? [D:/Apache2/modules] O:/php/Apache Group/Apa
che2/manual
mod_perl.so has been successfully installed to O:/php/APACHE~1/Apache2/manual.
To enable mod_perl, put in the directives
   LoadFile "C:/Path/to/Perl/bin/perl58.dll"
   LoadModule perl_module modules/mod_perl.so
in httpd.conf. For more information, visit
   http://perl.apache.org/
and especially see
   http://perl.apache.org/docs/2.0/rename.html

Successfully installed mod_perl version 2.0.1 in ActivePerl 5.8.7.813.

按照它的说明,以及结合 www.yippeesoft.com
Win32平台Apache 2.0.52配置mod_perl
http://blog.csdn.net/fzjw/archive/2004/11/03/165856.aspx

修改HTTD.CONF
#
# AddHandler allows you to map certain file extensions to "handlers":
# actions unrelated to filetype. These can be either built into the server
# or added with the Action directive (see below)
#
# To use CGI scripts outside of ScriptAliased directories:
# (You will also need to add "ExecCGI" to the "Options" directive.)
#
#AddHandler cgi-script .cgi www.yippeesoft.com
AddHandler cgi-script .cgi .pl
AddHandler perl-script .pl .cgi

LoadFile "O:/php/perl/bin/perl58.dll" www.yippeesoft.com
LoadModule perl_module modules/mod_perl.so

Alias /perl/ "O:/php/Apache Group/Apache2/perl/"
<Location /perl>
     SetHandler perl-script
     PerlResponseHandler ModPerl::Registry
     Options +ExecCGI
     PerlOptions +ParseHeaders
</Location>

重新运行APACHE,在O:\\php\\Apache Group\\Apache2\\perl写一个PL文件
print "Content-type: text/plain; charset=iso-8859-1\\n\\n";
foreach $var (sort(keys(%ENV))) &leftsign;
    $val = $ENV&leftsign;$var&rightsign;;
    $val =~ s&line;\\n&line;\\\\n&line;g;
    $val =~ s&line;"&line;\\\\"&line;g;
    print "$&leftsign;var&rightsign;=\\"$&leftsign;val&rightsign;\\"\\n";
&rightsign; www.yippeesoft.com

原来的第一行 #!O:/php/perl/bin/Perl.exe 就可以不用了 www.yippeesoft.com

Mod_perl的简介  Mod_perl是为在Apache上提高perl执行效率而开发的一个模块,有了他就可以直接把  perl程序编译到Apache去,就象把php编译到apache里一样,能大幅度提高执行效率。   Mod_perl的原理  先让我们来看看一个CGI请求请求过程:  web服务器首先启动一个新的进程,并请求perl解析器对脚本进行解析,然后执行,并  返回输出结果。   也就是说,对于每个新的用户对CGI进行请求时服务器都要使用perl解析器对脚本进行重新  的解析,这样很大程度影响了脚本的执行效率。另外由于CGI请求与普通http请求一样都是  进程管理,当脚本执行完成后马上退出内存,但是当服务器响应率很高的时候,同一个时  间有上千个请求的时候,进程队列就会非常拥挤,而且每个单独的进程都会消耗一定的内  存。这就是所谓的‘运行CGI程序的瓶颈’。   而mod_perl正是针对这一点而设计的,当服务器第一次请求mod_perl程序的时候,web服务  器会在内存中编译并加载该程序,当程序完成后并不退出内存,当有新的对该程序的请求  的时候,就无需启动perl进行解析,同时由于线程的响应,因此同一时间内不会耗费更多  的内存,从而达到提高perl-cgi的执行效率,及降低系统资源。  但是盲目的使用mod_perl也有副作用,因为当服务器每次加载一个perl线程时都要占用  内存,而且不象进程那样,执行完成以后退出内存,因此会导致服务器内存耗光。  因此采用Mod_per比较适合下载如下的脚本: 常用的Perl模块DBI GD CGI.pm 等,以及  请求比较繁忙的CGI脚本。

标签:,
perl4编程出错信息 - 九月 13, 2005 by yippee

perl 出错信息
刚开始接触PERL,不怎么熟悉语法,经常出错,不过出错信息实在太不友好了

#!O:/php/perl/bin/Perl.exe
print "Content-type:text/html\\n\\n";
print "<center><h2>Hello World</h2></center>;
#这里少了一个“ 号
exit; www.yippeesoft.com

Internal Server Error www.yippeesoft.com
The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator, www.yippeesoft.com and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.

——————————————————————————–

Apache/2.0.54 (Win32) PHP/4.3.10 Server at 127.0.0.1 Port 80

这根本都看不出什么东西 www.yippeesoft.com
找了一些资料,原来这样就可以了

加入: www.yippeesoft.com
use CGI::Carp qw(fatalsToBrowser);

Software error:
syntax error at O:/php/Apache Group/Apache2/cgi-bin/sf.pl line 8, near "print "Content"
syntax error at O:/php/Apache Group/Apache2/cgi-bin/sf.pl line 8, near "gb2312\\"
Can\’t find string terminator \’"\’ anywhere before EOF at O:/php/Apache Group/Apache2/cgi-bin/sf.pl line 26.

For help, please send mail to the webmaster (www.yippeesoft.com), giving this error message and the time and date of the error.

B<CGI::Carp> – CGI routines for writing to the HTTPD error log
CGI::Carp – CGI routines for writing to the HTTPD (or other) error log

——————————————————————————–

SYNOPSIS
    use CGI::Carp;
    croak "We\’re outta here!";
    confess "It was my fault: $!";
    carp "It was your fault!";  
    warn "I\’m confused";
    die  "I\’m dying.\\n";
    use CGI::Carp qw(cluck);
    cluck "I wouldn\’t do that if I were you";
    use CGI::Carp qw(fatalsToBrowser);
    die "Fatal error messages are now sent to browser";

——————————————————————————–

DESCRIPTION
CGI scripts have a nasty habit of leaving warning messages in the error logs that are neither time stamped nor fully identified. Tracking down the script that caused the error is a pain. This fixes that. Replace the usual

    use Carp;
with

    use CGI::Carp
And the standard warn(), die (), croak(), confess() and carp() calls will automagically be replaced with functions that write out nicely time-stamped messages to the HTTP server error log.

For example:

   [Fri Nov 17 21:40:43 1995] test.pl: I\’m confused at test.pl line 3.
   [Fri Nov 17 21:40:43 1995] test.pl: Got an error message: Permission denied.
   [Fri Nov 17 21:40:43 1995] test.pl: I\’m dying.
AUTHORS
Copyright 1995-2002, Lincoln D. Stein. All rights reserved.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

Address bug reports and comments to: lstein@cshl.org

标签:, ,
perl3编程模板技术 - 九月 13, 2005 by yippee

本来以为PHP的模板技 www.yippeesoft.com 术说明很多,PERL的应该也不少,结果是寥寥无几。
看到一些说明总结 www.yippeesoft.com
Perl中的模板系统很多,而且在perl中设计简单的Template也不是什么难事,我 bloves 等等都设计国自己的template。  www.yippeesoft.com
要是想用简单的,我推荐用我们的吧,我的那个还支持CGI文件缓存呢(打广告)。

不过话说回来了,不论是Perl的Template技术还是常用的这些P结尾的技术,还都无法于Mason相提并论。

如果需要参考,那么请到www.ilcatperl.org中下载EasyTemplate   www.yippeesoft.com
如果你仅需要使用模板技术而不是想去了解它,那么推荐你可以使用Perl语言的众多模块HTML::Template,TemplateToolkit等. 

Dtamplate由GPL获得许可并由BalázsSzabó维护,它由C扩展的Perl语言来编写,可以从CPAN主页中下载。
dTemplate is licensed under the GPL and is maintained by Bal醶s Szab? It is written in Perl with a C extension and can be downloaded from CPAN. http://search.cpan.org/~dlux/dTemplate-2.4/

下载了:CGI-FastTemplate Text-FastTemplate
demo: www.yippeesoft.com
  <!– NAME: row.tpl –>
  <tr>
  <td>$NUMBER</td>
  <td>$BIG_NUMBER</td>
  </tr>
  <!– END: row.tpl –>

  <!– NAME: main.tpl –>
  <html> www.yippeesoft.com
  <head><title>$TITLE</title>
  </head>
  <body>
  $MAIN www.yippeesoft.com
  </body>
  </html>
  <!– END: main.tpl –>

  <!– NAME: table.tpl –>
  <table>
  $ROWS www.yippeesoft.com
  </table>
  <!– END: table.tpl –>

  #!O:/php/perl/bin/Perl.exe
print "Content-type: text/plain; charset=gb2312\\n\\n";
use CGI::FastTemplate;
my $tpl = new CGI::FastTemplate("./tpl");
$tpl->define(     main    => "main.tpl",
                    table   => "table.tpl",
                    row     => "row.tpl",
                    );
  $tpl->assign(TITLE => "FastTemplate Test");
  for $n (1..3)
  &leftsign; www.yippeesoft.com
        $tpl->assign(   NUMBER      => $n,
        BIG_NUMBER   => $n*10);
        $tpl->parse(ROWS   => ".row");
  &rightsign;
  $tpl->parse(MAIN => ["table", "main"]);
  $tpl->print();
  $tpl->clear_all();
  ## END ##

  1 10
2 20
3 30  www.yippeesoft.com

[quote]cyril Why Do We Need Templates? http://web.cyril.idv.tw/aps/ApsApsshowArticle.php?SystemId=1&CategoryId=1&Order=1
當我們使用Perl或是Python這類的語言來作Web Application時,有什麼更好的方式嗎?答案是有的,也就是所謂的Template.簡單的說,Template就是一個網頁的範本,上面有想要呈現的網頁風格.但是對於實際要呈現的資料,則由程式語言來動態決定,決定好之後將網頁範本與資料結合,就成了最後輸出的網頁.在Perl的世界中,有一個很流行的Module,就是CGI-FastTemplate.以此一Module來實現一開始的例子,我們需要兩個檔案,一個是網頁的Template檔案(helloworld2.tpl),另一個則是執行的程式(helloworld2.pl).

檔案:helloworld2.tpl
<html>
<head>
<title>Perl Demo2</title>
</head>
<body>
<h1>Perl Hello World Demo2</h1>
$STRING<br>
</body>
</html>
 
檔案:helloworld2.pl
#!/usr/bin/perl -T -w

use CGI::FastTemplate;
my $tpl = new CGI::FastTemplate;
$tpl->define(message=>\’helloworld2.tpl\’);
$tpl->assign(STRING=>\’hello world!\’);
$tpl->parse(MAIN=>\’message\’);
print "Content-type:text/html \\n\\n";
$tpl->print();
 
我將這種產生頁面的方式,稱之為On-line Template parsing,也就是每次讀取網頁就重新執行Template的置換動作,並將結果直接送給客戶端的程式(通常就是瀏覽器).除此之外,還有另外一種就是Off-line Template parsing.此一方式會先將Template的置換結果儲存下來,這樣後續的網頁讀取就可以直接利用先前已經儲存的結果,以增加網站的反應速度.雖說Template的設計方式,在執行速度上可能會比不用Template來的慢些,不過這種設計方式所獲得的好處,絕對遠大於這些速度的犧牲.而對於真正要求執行速度的系統,應該盡量以Off-line的方式來產生頁面.在這種情況下,使用Template所造成的速度減緩就不再是問題了.

當然了,Template不只是對非內嵌式的語言才有好處,對於像是PHP這類的內嵌式語言也有相當的好處.在程式設計中,一個很重要的觀念就是,要將data management,business logic,以及presentation分開.而Template的做法,正是將presentation跟business logic分離.這樣子的設計,可以讓一個複雜的系統變得更加容易實作,也更加容易維護以及修改.除此之外,這種設計還可以增加開發系統的速度.因為當你將business logic跟presentation分開之後,程式設計師就可以跟網頁設計師同時進行開發與修改的動作,而不至於互相影響而耽誤了對方的進度.當然了,從原始的HTML檔案變成Template檔案之間,還是會有雙方交集而影響的存在,不過這樣的方式已經將原先相互影響的時間減到最低了.所以即使是以PHP這種內嵌式的語言,還是建議使用Template的方式來架構網站.在這個簡單的例子裡,很難看出Template的好處,但是當你的網站規模越來越大,功能越來越多的時候,你會感謝有Template技術的存在.

可惜的是,這只是理想中的情況.在現實中,business logic跟presentation卻不是可以完全分離的.舉例來說,如果要動態產生一個不固定行數的表格,通常需要利用迴圈來達成這樣的效果.一種做法就是將表格的標籤經由程式裡的迴圈來產生,另一種做法就是在Template檔案裡利用特殊的標籤來達到迴圈的效果.而在後者中,Template的功能已經不只是單純的變數取代,而是包含了簡單的控制標籤.也因此又有了所謂的Template Language的出現.不管是哪一種做法,都說明了想要將business logic跟presentation完全分離,至少在Web Application上,目前還是沒有完美的解決方式.
 [/quote]

标签:,
perl2编程mysql中文 - 九月 13, 2005 by yippee

使用connect方法建立一个到数据源的连接。$data_source应该以DBI:driver_name:开始,例如:

$dbh = DBI->connect("DBI:mysql:$database", $user, $password); www.yippeesoft.com

$dbh = DBI->connect("DBI:mysql:$database:$hostname",$user, $password);

$dbh = DBI->connect("DBI:mysql:$database:$hostname:$port",$user, $password);

Can\’t locate DBI.pm in @INC (@INC contains: O:/php/perl/lib O:/php/perl/site/lib .) at O:\\php\\OptiPerl\\webroot\\cgi-bin\\newscript1.cgi line 3.
BEGIN failed–compilation aborted at O:\\php\\OptiPerl\\webroot\\cgi-bin\\newscript1.cgi line 3.

#!O:/php/perl/bin/Perl.exe www.yippeesoft.com
print "Content-type: text/plain; charset=gb2312\\n\\n";
print "rrow[1]\\n";
use DBI; www.yippeesoft.com
my $dbh = DBI->connect(\’dbi:mysql:astbill:localhost\’,\’root\’,\’123\’);

$dbh->do("set names gbk");

my $sql = "insert into admin(namee,pwd) values(\’对数函数\’,\’闪电划过的\’)";
my $sth = $dbh->prepare($sql);
$sth->execute(); www.yippeesoft.com

my $sql = "select * from admin";
my $sth = $dbh->prepare($sql);

$sth->execute(); www.yippeesoft.com
my @row;
while(@row=$sth->fetchrow_array())
&leftsign; www.yippeesoft.com
 print "$row[2]\\n"; www.yippeesoft.com
&rightsign;

rrow[1]
21232f297a57a5a743894a0e4a801fc3
?????
rrow[1] www.yippeesoft.com
21232f297a57a5a743894a0e4a801fc3
闪电划过的 www.yippeesoft.com

[client]
port=3306
default-character-set=gbk www.yippeesoft.com

# The default character set that will be used when a new schema or table is
# created and no character set is defined
default-character-set=gbk www.yippeesoft.com

[quote]   cnchun  
    perl mysql中文乱码
   摘自 中国Perl协会 用户推广组   cnchun  2005-06-29 16:57
http://perlchina.sun126.com/cgi-bin/ccb/index.cgi
搞了一天总算搞好了。
perl5.8+mysql4.1,用perl DBI mysql往数据库插入数据,总是乱码,而用phpmyadmin能插入中文;而用perl插入的中文在phpmyadmin里面也是乱码。数据库的创建,我用了。
create database cnews default character set gbk;
CREATE TABLE `news` (
 `id` int(10) unsigned NOT NULL auto_increment,
 `title` varchar(50) default NULL,
 `context` text,
 `date` date default NULL,
 `site` varchar(20) default NULL,
 PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=gbk

如果在my.cnf里面设置了
[client]
default-character-set = gbk
[mysqld]
default-character-set = gbk

mysql -uroot -p;
mysql>use cnews;
mysql> status
————–
Server characterset:  gbk
Db   characterset:  gbk
Client characterset:  gbk
Conn. characterset:  gbk
则perl能够正常插入中文无须其它设置。

如果不在my.cnf里设置default-character-set,例如:
mysql -uroot -p;
msyql>use cnews
mysql> status
Server characterset:  latin1
Db   characterset:  gbk
Client characterset:  latin1
Conn. characterset:  latin1

在调用perl 的时候,需要下面设置:
$db->do("SET character_set_client = \’gbk\’");
$db->do("SET character_set_connection = \’gbk\’");
如果需要显示结果,加上
$db->do("SET character_set_results= \’gbk\’ ");

其实可以把database 设置为gbk,然后用character_set_*来设置相关编码,mysql其实还是很灵活的。perl运行跟linux的locale没有关系,对于数据库操作。
刚学perl,希望对跟我一样的新手有所帮助。
 
 hoowa  
    在Perl里简单的执行这个也.
   摘自 中国Perl协会 用户推广组   hoowa  2005-06-29 19:00
http://perlchina.sun126.com/cgi-bin/ccb/index.cgi
在Perl里简单的执行这个也可以实现与服务器端一样是gbk编码
set names gbk  [/quote]

这个中文真是麻烦,找了半天资料,可是KOMODO不管怎么样就是不能输入中文?!

标签:, , , ,
perl1编程mysql安装 - 九月 13, 2005 by yippee

访问: www.yippeesoft.com
http://ppm.activestate.com/PPMPackages/zips/
ActivePerl 5xx (e.g. ActivePerl 5_005.522)
http://ppm.activestate.com/PPMPackages/zips/5xx-builds-only/
DBD-Mysql.zip 、 DBI.zip

看看里面的说明: www.yippeesoft.com
To install this ActiveState PPM package, run the following command
in the current directory:

    ppm install DBI.ppd

结果:www.yippeesoft.com
Error: no suitable installation target found for package DBI.

以为是路径的问题,直接修改 DBI.ppd
<SOFTPKG NAME="DBI" VERSION="1,14,0,0">
 <TITLE>DBI</TITLE>
 <ABSTRACT>Database independent interface for Perl</ABSTRACT>
 <AUTHOR>Tim Bunce (dbi-users@fugue.com)</AUTHOR>
 <IMPLEMENTATION>
  <OS NAME="MSWin32" />
  <ARCHITECTURE NAME="MSWin32-x86-object" />
  <CODEBASE HREF="x86/DBI.tar.gz" />
 </IMPLEMENTATION>
</SOFTPKG>
还是不行

最后干脆这样,先运行PPM
C:\\DBI>ppm www.yippeesoft.com
PPM – Programmer\’s Package Manager version 3.2.
Copyright (c) 2001 ActiveState Corp. All Rights Reserved.
ActiveState is a division of Sophos.

Entering interactive shell. Using Term::ReadLine::Perl as readline library.

Type \’help\’ to get started.

再install DBI www.yippeesoft.com
ppm> install dbi www.yippeesoft.com
====================
Install \’dbi\’ version 1.48 in ActivePerl 5.8.7.813.
====================
Downloaded 548475 bytes.
Extracting 73/73: blib/arch/auto/DBI/Driver_xst.h
Installing O:\\php\\perl\\site\\lib\\auto\\DBI\\dbd_xsh.h
Installing O:\\php\\perl\\site\\lib\\auto\\DBI\\DBI.bs
Installing O:\\php\\perl\\site\\lib\\auto\\DBI\\DBI.dll

DBD-Mysql.ppd 同样 www.yippeesoft.com
To install this ActiveState PPM package, run the following command
in the current directory:

    ppm install DBD-Mysql.ppd
Error: no suitable installation tar www.yippeesoft.com get found for package DBD-Mysql.

Successfully installed dbd-mysql version 3.0002 in ActivePerl 5.8.7.813.
ppm> exit www.yippeesoft.com

C:\\DBD-Mysql>ppm install DBD-Mysql.ppd
Note: Package \’DBD-mysql\’ is already installed.

这是人家的办法:
SOLUTION

——————————————————————————–

I have successfully installed DBI and DBD-mysql onto my Windows XP machine (which does not have a \’net connection).

Here are the steps I took to do it:

Go to http://ppm.activestate.com/PPMPackages/zips/, choose your version of ActivePerl, and choose your platform
Scroll down to find the package(s) you\’re looking for (in my case, I found DBI.zip and DBD-mysql.zip at http://ppm.activestate.com/PPMPacka…s-only/Windows/).
Download the package(s) into a directory you\’ll be able to find later on.
Unzip the package(s) into your local repository directory (mine is C:\\Perl\\repo on the XP machine).
If you haven\’t done so already, denote this directory as a repository directory within ppm. I labeled my repository "local" (minus double quotes). Here is the command I used to add my repository: ppm repository add local C:\\Perl\\repo
Once the directory is added, search your repositories for all packages: ppm search * I got a list of the two packages in my "local" repository (DBI and DBD-mysql).
Once I had the names, I installed each one. I did NOT edit the .ppd file that came bundled in the .zip file.
First, I installed DBI: ppm install DBI www.yippeesoft.com
Then I installed DBD-mysql: ppm install DBD-mysql

All done! Start using the packages. It\’s that easy.

Note: If you are already running from within ppm (you\’ll be able to tell because your command prompt will start with ppm>), then leave off the ppm in the command you type to carry out any actions. (Example: ppm> repository add local C:\\Perl\\repo instead of ppm> ppm repository add local C:\\Perl\\repo.) www.yippeesoft.com

Please let me know if this has been a help to you. If you have any problems with these instructions, please reply to this post.

标签:, , , ,
php+MYSQL数据库访问编程入门 - 八月 12, 2005 by yippee

<html>
<body> www.yippeesoft.com
<?php www.yippeesoft.com
$db = mysql_connect("localhost","root","123");
mysql_query("SET NAMES \’utf8\’",$db);
mysql_query("SET CHARACTER SET utf8",$db);
mysql_select_db("testsf",$db);
$result = mysql_query("SELECT * FROM sf",$db);
while($myrow=mysql_fetch_array($result)) &leftsign;
    echo $myrow[\'sf\'];
    echo "\\n";
&rightsign;

注意:这时候 RESULT已经到了最后,不能再用来循环,再循环也读取不到数值
?>
</body>
</html>

1、mysql_fetch_array()
格式:array mysql_fetch_array(int query);

执行成功,返回1个数组,该数组保存有下一条记录的值,如执行失败,则返回False值。
返回的数组既可以用下标来表示,也可以用字段名来表示。

例子:  www.yippeesoft.com
$query = mysql_query($sql , $connect);
while($arrary = mysql_fetch_array($query))
&leftsign;

echo $array[column1]." &line; ".$array[column2];
//echo $array[0]." &line; ".$array[1];

&rightsign;
?>
Note : 数组的下标是从0开始的!  www.yippeesoft.com

2、mysql_fetch_row()
格式:array = mysql_fetch_row(int query);

与1的mysql_fetch_array()函数功能基本相同。区别在于mysql_fetch_row()只能以数组下标来表示。
成功返回1个数组,失败返回False值。

例子:  www.yippeesoft.com
$query = mysql_query($sql , $connect);
while($row = mysql_fetch_row($query))
&leftsign;
echo $row[0] . " &line; " . $row[1] . "
";
&rightsign;
?>
Note : mysql_fetch_row()函数只能用数组下标来表示,并从0开始。
另:mysql_fetch_row()比mysql_fetch_array()执行速度快,并且都是对下一行数据进行读取。

3、mysql_result()  www.yippeesoft.com
格式:int mysql_result(int query , int row , string filedname);

在mysql_result()中,参数row必须从0开始,参数filedname必须是真实的字段名,不能用下标来表示。
执行成功,返回由数据库中取出的字段的数值,失败则返回False值。

例子:
$query = mysql_query($sql , $connect);
echo mysql_result($query , 0 , "column1")."
";
echo mysql_result($query , 1, "column1")."
";
echo mysql_result($query , 2, "column1")."
";
?>  www.yippeesoft.com

Note : 此函数功能少,但使用方便。

昨天狂搞笑,一个老外接到一个电话,然后找我要台电话机拨打,那个手机奇大无比,还是智能手机,结果字显示暗暗的,小小的,并且手机号码显示怪怪的,1381显示为 1(381),结果我看错了,以为是0381,结果拨打失败,我以为是由于我的长途功能被关闭了,找同事,结果他看成了 1 表示 国际长途?! 381表示国际国家代号,于是又找到经理去打国际长途,结果还是失败!

最后我满问了一个,WHERE is this phone FROM? 一下子懵懵的,居然他也听懂了,MOBILE PHONE,SHANGHAI! 晕倒!!!

标签:, , , , ,
华工达梦国产数据库尝试3 VB编程2 - 七月 15, 2005 by yippee

今天下午继续测试了一下:www.yippeesoft.com

1、控制台-达梦服务器组--LOCALHOST--安全--登陆--SYSDBA
一般访问:密码:我试着输入150个1,点击应用,没有出错提示,但是重新连接仍然是旧密码

2、jisql--选项--设置最大行数,没有输入限制,可以输入字母,输入50个1,可以确定,但是不生效

3、在JMANAGER中修改SFF表,增加一字段,切换到 约束,点击 + 号,勾选 选择 SF 字段,点击应用,出现 JAVA.SQL.SQLEXCEPTION:RUN_TIME ERROR NUMBER=-3061 www.yippeesoft.com

4、去掉 勾选,左边 树 点击SFF 表下面的 索引,提示要保存修改结果吗?选择 确定。提示 UNIQUE约束中没有选中任何列,此时只能点击确定,之后,字段修改结果丢失。www.yippeesoft.com

5、任务栏状态区上面的DM4 SERVER小图标,点击右键,关联菜单总是在最右下角弹出,例如图标已经在任务区的左边,右边还有一些杀毒软件、GB、EMAIL之类的图标,但是菜单显示在最右下。

6、VB写了几行代码:非常简单的,使用msado15.dll#Microsoft ActiveX Data Objects 2.8 Library

Option Explicit
Dim dm As New ADODB.Connection
Dim dmcmd As New ADODB.Command
Dim ac As New ADODB.Connection
Dim accmd As New ADODB.Command
Dim sq As New ADODB.Connection
Dim sqcmd As New ADODB.Command
Private Sub Command1_Click()
Debug.Print "dm begin:", Timer
Dim i As Integer
For i = 0 To 10000
    dmcmd.CommandText = "insert into ""SYSTEM"".""INFO_SCHEM"".""SFF""(SF) values(\’" + Format(i) + "\’)"
    dmcmd.Execute
Next
Debug.Print "dm end :", Timer
End Sub
Private Sub Command2_Click()
Debug.Print "ac begin:", Timer
Dim i As Integer
For i = 0 To 10000
    accmd.CommandText = "insert into sff values(\’" + Format(i) + "\’)"
    accmd.Execute
Next
Debug.Print "ac end :", Timer
End Sub
Private Sub Command3_Click()
Debug.Print "sq begin:", Timer
Dim i As Integer
For i = 0 To 10000
    sqcmd.CommandText = "insert into sff values(\’" + Format(i) + "\’)"
    sqcmd.Execute
Next
Debug.Print "sq end :", Timer
End Sub

Private Sub Form_Load()
dm.CursorLocation = adUseClient
dm.Open "PROVIDER=MSDASQL;dsn=sf;uid=SYSDBA;pwd=123123;database=system;"
Set dmcmd.ActiveConnection = dm
ac.CursorLocation = adUseClient
ac.Open "PROVIDER=MSDASQL;dsn=sfff;uid=;pwd=;"
Set accmd.ActiveConnection = ac
sq.CursorLocation = adUseClient
sq.Open "PROVIDER=MSDASQL;dsn=sq;uid=sa;pwd=sffs;database=phs;"
Set sqcmd.ActiveConnection = sq
End Sub

结果如下:其中DM代表达梦、AC代表ACCESS、SQ代表MSDE 2000,所有表名都是SFF,下面有一个字段SF,全部采用默认值,例如DM是char(10),AC是文本(50),msde是CHAR(10)

dm begin: 55832.08  dm begin:  55869.71  dm begin: 56378.77
dm end :  55836.39  dm end :   55873.96   dm end :  56383.09
ac begin: 55948.19  ac begin:  55966.22   ac begin: 56384.93
ac end :  55951.09  ac end :    55969.29   ac end : 56387.96
sq begin: 56316.5   sq begin:   56333.96   sq begin: 56389.17
sq end :  56319.34  sq end :    56336.56   sq end :  56391.74

以上是1000条插入,下面是10000条插入

dm begin:  56585.92 ac begin: 56768.63 sq begin:      56835.28
dm end :   56635.68 ac end :  56800.46 sq end :       56863.34

ac begin:      58630.98  sq begin:      58908.63 dm begin:      59138.11
ac end :       58797.15  sq end :       59062.89  dm end :       59356.91 五万条

本来想测试一下数据库大小的,但是时间不够了,明天再看看

Timer 函数
返回一个 Single,代表从午夜开始到现在经过的秒数。
Microsoft Windows中,Timer函数返回一秒的小数部分。

华工达梦国产数据库尝试2 VB编程1  华工达梦国产数据库尝试

标签:, , ,