| 订阅 | 在线投稿
分享
 
 
当前位置: 王朝网络 >> c/c++ >> Windows xia C yu yan wang luo bian cheng kuai su ru men

Windows xia C yu yan wang luo bian cheng kuai su ru men

2008-06-01 02:11:41 编辑來源:互联网 评论
 
 
 
本文为【Windows下C语言网络编程快速入门】的拼音翻译版
  C yu yan de xue xi , yi ban de fang shi shi , xian xue C, ran hou shi C++, zui hao huan yao you hui bian yu yan he wei ji yuan li ji chu , ran hou cai shi Visual C++。 zhe yang de fang shi , dui xue xi zhe lai shuo , yao hua fei hen duo shi jian he nai li 。 er zai xue xiao jiao xue zhong , ye mei you shi jian shen ru xue xi Windows bian cheng de shi yong ji shu le 。
  qi shi , ju you le C yu yan ji chu hou , zai you yi xie ji ben de C++ lei de gai nian , jiu ke yi zhi jie xue xi Windows C bian cheng le 。
  yi 、 zou jin Windows C yu yan
  hen duo yu yan dou ba xian shi yi ge “Hello,World!” zuo wei di yi ge ru men cheng xu , C yu yan de di yi ge cheng xu shi zhe yang de :
  #include<stdio.h>
  main()
  {
  PRintf(“Hello,World!”);
  }
  jia ru ba main han shu xie cheng dai shen shu de main han shu , ying gai shi :
  #include<stdio.h>
  main(int arge,char *argv[])
  {
  printf(“Hello,World!”);
  }
  Windows C de di yi ge cheng xu he zhe ge cheng xu zai xing shi he yuan li shang dou shi yi zhi de , zhi shi you liang dian bu tong :
  1. zhu han shu jie shou de xing shen bu zhi shi ming ling xing zhong de zi fu chuan de ge shu he zi fu chuan de shou di zhi 。
  2. C yu yan de hen duo han shu zai Windows C zhong dou ke yi ji xu shi yong , dan xiang printf() ping mu xian shi deng han shu jiu bu neng ji xu shi yong le 。 yin wei Windows shi duo ren wu cao zuo xi tong , ping mu yi bu zai wei mou yi ge ying yong cheng xu suo du you ,Windows C ying yong cheng xu yao xian shi zi fu chuan , xu yao shi yong Windows ti gong de API han shu , kai zi ji de chuang kou
  xia mian shi yi ge zui jian dan de , xian shi “Hello,World!” de Windows C cheng xu :
  #include<windows.h>
  APIENTRY WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,
  LPSTR lpCmdLine,int nCmdShow)
  {
  MessageBox(NULL,"Hello,World!"," di yi ge Windows C cheng xu ",MB_OKMB_ICONASTERISK);
  }
  zhu han shu de xing shen you si ge :
  1) Hinstance: jie shou cheng xu yun xing shi dang qian shi li de ju bing ;
  2) HprivInstance: qian yi ge shi li de ju bing ;
  3) LpCmdLine: cheng xu ming ling xing zhi zhen ;
  4) NcmdShow: yi ge yong lai zhi ding chuang kou xian shi fang shi de zheng shu 。
  zhe ji ge shen shu de shi yong wo men hui zai shen ru de xue xi zhong jie shao de 。
  xian shi Hello,Word! zi fu chuan , wo men shi yong le yi ge MessageBox han shu , zhe ge han shu hui zai ping mu shang xian shi yi ge dui hua kuang , ta de yuan xing shi :
  int MessageBox(HWND hWnd,LPCTSTR lpText,LPCTSTR lpCaption,UNIT uType)
  si ge shen shu fen bie shi :
  1) HWnd: fu chuang kou de ju bing ;
  2) LpText: yao xian shi zi fu chuan de zhi zhen ;
  3) LpCaption: dui hua kuang biao ti zi fu chuan de zhi zhen ;
  4) UType: xian shi zai dui hua kuang shang de xiao tu biao de lei xing 。
  shi yong zhe ge han shu yao bao han windows.h tou wen jian 。
  tiao shi yi xia , zen me yang ? chuang kou shang tan chu le yi ge “ di yi ge Windows C cheng xu ” dui hua kuang , shang mian you yi xing zi :“Hello,World!”。
  shi jie zhen de hen mei hao a !!
  shen ru bian cheng :
  zai C yu yan zhong , han shu de sheng ming , jia ru mei you zhi ming fan hui zhi lei xing , que sheng zhi wei void, zhe ge cheng xu de zhu han shu jiu mei you fan hui zhi 。 bu guo , zai Windows bian cheng shi , wo men zui hao yang cheng ge hao xi guan , zhi ming han shu de fan hui zhi lei xing , yin wei zai C++ zhong , han shu fan hui zhi lei xing shi bu ke yi que sheng de 。 er wo men zai Windows C bian cheng shi , huan shi hui yong dao C++ de yi xie gai nian , zhe yang zuo , you li yu yi hou shen ru di xue xi 。
  gui fan yi dian de cheng xu ying gai shi zhe yang de :
  #include<windows.h>
  int APIENTRY WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,
  LPSTR lpCmdLine,int nCmdShow)
  {
  MessageBox(NULL,"Hello,World!"," di yi ge Windows C cheng xu ",MB_OKMB_ICONASTERISK);
  return 0;
  }
  zhe li , wo men sheng ming de lei xing wei int xing , bing qie fan hui yi ge zhi 0, zhe yang de han shu jiu ke yi shi yong zai fu duo yi dian de han shu tiao yong zhong le 。
  zai zhe yi jie zhong , wo men you ji chu dou ti dao le ju bing de gai nian , ju bing he zhi zhen de gai nian bu tong , ta shi zuo wei cao zuo xi tong nei bu suo yin biao zhong de yi ge zhi lai shi yong de , zhe yang ke yi fang zhi ying yong cheng xu zhi jie fang wen ming dui xiang de nei bu jie gou , ti xian le Windows zi yuan zhi li de you yue xing 。 pi ru shuo , yi ge chuang kou zhao kai zhi hou , hao dui ying nei cun zhong de yi ge nei cun kuai , zhe ge chuang kou suo zai de nei cun kuai di zhi wang wang hui you cao zuo xi tong zuo dong tai de tiao zheng , dan qi que bu hui sui zhi bian hua 。 bu guo , tong guo ta ke yi fang wen zhe ge chuang kou , suo yi zai shi yong de shi hou , ke yi ba ta dang zuo zhi zhen yi yang kan dai 。
  er 、 huo qu ben di ji suan ji de zhu ji ming he ip di zhi
  he C yu yan yi yang , han shu shi Windows C bian cheng de zui ji ben de dan wei 。 bu guo ,Windows C zhu yao shi yong API han shu , er wang luo bian cheng ze zhu yao shi yong Winsock ti gong de API han shu 。
  Winsock shi 90 nian dai chu , wei le fang bian wang luo bian cheng , you Microsoft lian he le qi ta ji jia gong si gong tong zhi ding de yi tao WINDOWS xia de wang luo bian cheng jie kou , ta shi tong guo C yu yan de dong tai lian jie ku fang shi ti gong gei yong hu ji ruan jian kai fa zhe de , zhu yao you winsock.h tou wen jian he dong tai lian jie ku winsock.dll zu cheng , mu qian you liang ge ban ben :Winsock1.1 he Winsock2.0。
  
  
  
  zai Win32 ping tai shang , fang wen zhong duo de ji ceng wang luo xie yi ,Winsock shi shou xuan jie kou 。
  yong Visual C++6.0 bian yi Windows C cheng xu , shi yong Winsock API han shu shi , shou xian yao ba wsock32.lib tian jia dao ta de ku mo kuai zhong , fou gang zai lian jie de shi hou , hui chu xian “error LNK2001” cuo wu 。 tian jia wsock32.lib de ju ti bu zhou shi : da kai gong cheng cai dan , xuan ze she zhi , zai tan chu de Project settings dui hua kuang zhong , dian ji link xuan xiang ka , ran hou zai dui xiang / ku mo kuai wen ben kuang zhong tian jia wsock32.lib。
  zui jian dan de wang luo bian cheng shi huo qu ben ji de zhu ji ming he IP di zhi , zhe ge cheng xu shi yong le WSAStart()、WSAClenaup()、gethostname()、gethostbyname() si ge winsock API han shu , zhe si ge han shu de gong neng he shi yong fang fa jie shao ru xia :
  1. WSAStartup():
  【 han shu yuan xing 】
  int PASCAL FAR WSAStartup(WORD wVersionRequired, LPWSADATA lpWSAData);
  【 shi yong shuo ming 】
  mei yi ge shi yong winsock de ying yong cheng xu , dou bi xu jin xing WSAStart han shu tiao yong , bing qie zhi you zai tiao yong cheng gong zhi hou cai neng shi yong qi ta de winsock wang luo cao zuo han shu 。
  WVersionRequired:< shu ru > biao shi yu shi yong de Winsock ban ben , zhe shi yi ge WORD lei xing de zheng shu , ta de gao wei zi jie ding yi de shi ci ban ben hao , di wei zi jie ding yi de shi zhu ban ben hao 。
  LpWSAData:< shu chu > shi yi ge zhi xiang WSADATA zi liao de zhi zhen 。 zhe ge zi liao wo men yi ban bu shi yong 。
  fan hui zhi : tiao yong cheng gong fan hui 0; fou ze , fan hui chu cuo xin xi 。
  2. WSAClenaup():
  【 han shu yuan xing 】
  int PASCAL FAR WSACleanup(void);
  【 shi yong shuo ming 】
  winsock shi yong hou , yao tiao yong WSACleanup han shu guan bi wang luo she bei , yi bian shi fang qi zhan yong de zi yuan 。
  3.gethostname()
  【 han shu yuan xing 】
  int PASCAL FAR gethostname (char FAR * name, int namelen);
  【 shi yong shuo ming 】
  gai han shu ke yi huo qu ben di zhu ji de zhu ji ming , qi zhong :
  name:< shu chu > yong yu zhi xiang suo huo qu de zhu ji ming de huan chong qu de zhi zhen 。
  Namelen:< shu ru > huan chong qu de da xiao , yi zi jie wei dan wei 。
  fan hui zhi : ruo wu cuo wu , fan hui 0; fou ze , fan hui cuo wu dai ma 。
  4.gethostbyname()
  【 han shu yuan xing 】
  strUCt hostent FAR * PASCAL FAR gethostbyname(const char FAR * name);
  【 shi yong shuo ming 】
  gai han shu ke yi cong zhu ji ming shu ju ku zhong de dao dui ying de “ zhu ji ”。
  gai han shu wei yi de shen shu name jiu shi qian mian tiao yong han shu gethostname() de dao de zhu ji ming 。 ruo wu cuo wu , gang fan hui yi ge zhi xiang hostent jie gou de pi zhen , ta ke yi biao shi yi ge “ zhu ji ” lie biao 。
  Hostent jie gou ding yi ru xia :
  Struct hostent
  {
  char FAR * h_name;
  char FAR FAR ** h_aliases;
  short h_addrtype;
  char FAR FAR ** h_addr_list;
  }
  qi zhong :
  h_name:< shu ru > zhu ji ming di zhi (PC)。
  h_aliases: yi ge you zhu ji bei yong ming zu cheng de kong zhong zhi shu zu 。
  H_addrtype: fan hui di zhi de lei xing , dui yu Winsock, zhe ge yu zong shi PF_INET。
  H_lenth: mei ge di zhi de chang du ( zi jie shu ), dui ying yu PF_INET yu ying gai wei 4。
  H_addr_list: ying gai yi kong zhi zhen jie yi de zhu ji di zhi de lie biao , fan hui de di zhi shi yi wang luo shun xu pai lie de 。
  qi zhong ,h_addr_list[0] cun fang de jiu shi ben di zhu ji de 4 ge zi jie de IP di zhi , ji :
  h_addr_list[0][0].h_addr_list[0][1].h_addr_list[0][2].h_addr_list[0][3]
  yi ge jian dan de yong xiao xi kuang xian shi zhu ji ming he IP di zhi de yuan cheng xu ru xia :
  #include<winsock.h>
  int WSA_return;
  WSADATA WSAData;
  HOSTENT *host_entry;
  char host_name[256];
  char host_address[256];
  int APIENTRY WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,
  LPSTR lpCmdLine,int nCmdShow)
  {
  WSA_return=WSAStartup(0x0101,&WSAData);
  if(WSA_return==0)
  {
  gethostname(host_name,256);
  host_entry=gethostbyname(host_name);
  if(host_entry!=0)
  {
  wsprintf(host_address,"%d.%d.%d.%d",
  (host_entry->h_addr_list[0][0]&0x00ff),
  (host_entry->h_addr_list[0][1]&0x00ff),
  (host_entry->h_addr_list[0][2]&0x00ff),
  (host_entry->h_addr_list[0][3]&0x00ff));
  MessageBox(NULL,host_address,host_name,MB_OK);
  
  
   }
  }
  WSACleanup();
  return 0;
  }
  shen ru bian cheng :
  qian mian xian shi IP di zhi de shi hou , wo men shi yong de shi xiao xi kuang , gui fan yi dian de bian cheng ying gai shi yong dui hua kuang , ru he bian ji yi ge dui hua kuang , hen duo shu zhong dou you jie shao , bian ji de dui hua kuang ke shen kao tu 5 de yun xing jie mian 。
  tou wen jian Get_IP.h ru xia :
  BOOL APIENTRY Hostname_ipDlgPro(HWND hDlg,UINT message,WPARAM wParam,LPARAM lParam);
  zhe ge cheng xu zhi shi yong le yi ge dui hua kuang guo cheng , yi ban ba zhe ge guo cheng de sheng ming fang zai tou wen jian zhong 。
  yuan cheng xu Get_IP.c:
  #include<winsock2.h>
  #include"Get_IP.h"
  #include"resource.h" // zhe ge tou wen jian zai chuang jian zi yuan de shi hou hui zi dong sheng cheng ,
  // bing hui zai cha ru zi yuan shi zi dong sheng cheng kong jian biao shi hao .
  int WSA_return;
  WSADATA WSAData;
  HOSTENT *host_entry;
  char host_name[256];
  char host_address[256];
  int APIENTRY WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,
  LPSTR lpCmdLine,int nCmdShow)
  {
  WSA_return=WSAStartup(0x0101,&WSAData);
  if(WSA_return==0)
  {
  gethostname(host_name,256);
  host_entry=gethostbyname(host_name);
  if(host_entry!=0)
  {
  wsprintf(host_address,"%d.%d.%d.%d",
  (host_entry->h_addr_list[0][0]&0x00ff),
  (host_entry->h_addr_list[0][1]&0x00ff),
  (host_entry->h_addr_list[0][2]&0x00ff),
  (host_entry->h_addr_list[0][3]&0x00ff));
  }
  }
  WSACleanup();
  DialogBox(hInstance,"DIALOG1",NULL,(DLGPROC)Hostname_ipDlgPro);
  return 0;
  }
  BOOL APIENTRY Hostname_ipDlgPro(HWND hDlg,UINT message,
  WPARAM wParam,LPARAM lParam)
  {
  switch(message)
  {
  case WM_INITDIALOG:
  return(TRUE);
  case WM_COMMAND:
  if(LOWORD(wParam)==IDOK)
  {
  SetDlgItemText(hDlg,IDC_EDIT1,host_name);
  SetDlgItemText(hDlg,IDC_EDIT2,host_address);
  SetDlgItemText(hDlg,IDCANCEL," que ding ");
  }
  if(LOWORD(wParam)==IDCANCEL)
  EndDialog(hDlg,TRUE);
  return(TRUE);
  break;
  }
  return(FALSE);
  }
  san 、 li yong VisualC++6.0 bian yi Windows C cheng xu
  li yong Visual C++6.0 bian yi Windows C cheng xu yi ban yao jing guo yi xia si ge bu zhou : xin jian xiang mu 、 tian jia dai ma 、 tian jia zi yuan he bian yi lian jie 。 xia mian wo men jian dan di jie shao yi xia cheng xu shang mian jie shao de gui fan de huo qu ben ji de zhu ji ming he IP di zhi cheng xu de bian yi guo cheng :
  ( yi ) xin jian xiang mu
  1. qi dong MicrosoftVisualC++, ran hou zai 【 wen jian 】 cai dan zhong xian ze 【 xin jian 】 ming ling , tan chu ru tu 1 suo shi de 【 xin jian 】 dui hua kuang :
Windows下C语言网络编程快速入门

  dian ji cha kan da tu
  tu 1
  2. zai 【 xin jian 】 dui hua kuang zhong , xi tong da kai de shi mo ren de 【 gong cheng 】 xuan xiang ka ,【 gong cheng 】 xuan xiang ka zuo ce de lie biao kuang zhong you duo zhong jian li gong cheng de fang shi , wo men xuan zhong “Win32 application” xuan xiang 。
  3. zai 【 wei zhi 】 wen ben kuang zhong shu ru xin jian gong cheng de lu jing ( li ru :F:\), zai 【 gong cheng 】 wen ben kuang zhong shu ru gong cheng ming cheng ( li ru :Get_IP)。
  4. xuan zhong 【 ping tai 】 lie biao kuang zhong de Win32 fu xuan kuang , ran hou dan ji 【 que ding 】 an niu 。
  5. zai sui hou de dui hua kuang zhong , dou xuan ze mo ren she zhi , wan cheng hou , jin ru tu 2 shi jie mian :
Windows下C语言网络编程快速入门

  dian ji cha kan da tu
  tu 2
  ( er ) tian jia dai ma
  zai VisualC++6.0 zhong , yuan dai ma yi ban cun fang zai yuan dai ma wen jian he tou wen jian zhong , wang xiang mu zhong tian jia yuan dai ma shi fei chang fang bian de , wei xiang mu xin jian yi ge yuan dai ma wen jian yi ban yao an xia shu fang fa cao zuo :
  1. xuan ze 【 gong cheng 】【 tian jia gong cheng 】【 xin jian 】 xuan xiang , tan chu tu 3 suo shi 【 xin jian 】 dui hua kuang :
Windows下C语言网络编程快速入门

  dian ji cha kan da tu
  tu 3
  2. zai dui hua kuang de 【 wen jian 】 xuan xiang ka zhong , zuo ce de lie biao kuang xuan zhong “C++ Source File” xuan xiang , you ce xuan zhong 【 tian jia gong cheng 】 fu xuan kuang , bing zai 【 wen jian 】 wen ben kuang zhong shu ru yuan wen jian ming ( li ru :Get_IP.c)。
  
  
  
  3. dan ji 【 que ding 】 an niu ,【 xin jian 】 dui hua kuang jiang bei bi , yong hu jiu ke yi zai xin jian de Get_IP.c zhong shu ru cheng xu de yuan dai ma le 。
  4. tian jia tou wen jian Get_IP.h de fang fa he shang mian suo shu guo cheng yi yang , zhi shi zai 【 wen jian 】 xuan xiang ka zhong , zuo ce de lie biao kuang yao xian zhong “C/C++ Header File” xuan xiang 。 zai 【 wen jian 】 wen ben kuang zhong shu ru tou wen jian ming ( li ru :Get_IP.h)。
  ( san ) tian jia zi yuan
  zai tian jia zi yuan qian , bi xu zai xiang mu zhong xian tian jia yi ge zi yuan wen jian , ran hou ke li yong Visual C++6.0 ti gong de zi yuan bian ji qi wei xiang mu xin jian yi ge zi yuan , ju ti bu zhou ru xia :
  1. xuan ze 【 gong cheng 】【 tian jia gong cheng 】【 xin jian 】 xuan xiang , tan chu tu 3 suo shi 【 xin jian 】 dui hua kuang 。
  2. zai dui hua kuang de 【 wen jian 】 xuan xiang ka zhong , zuo ce de lie biao kuang xuan zhong “Rsource Script” xuan xiang , you ce xuan zhong 【 tian jia gong cheng 】 fu xuan kuang , bing zai 【 wen jian 】 wen ben kuang zhong shu ru zi yuan wen jian ming ( li ru :Get_IP.rc)。
  3. dan ji que ding , hui dao zhu chuang kou hou , xuan ze 【 cha ru 】【 zi yuan 】 xuan xiang , da kai 【 cha ru zi yuan 】 dui hua kuang , ru tu 4 suo shi , zai 【 zi yuan lei xing 】 lie biao kuang zhong xuan zhong “Dialog” xuan xiang , dan ji 【 xin jian 】 an niu , fan hui zhu chuang kou hou , ji ke li yong dui hua kuang bian ji qi jin xing bian ji le 。 bian ji hou de dui hua kuang ru tu
Windows下C语言网络编程快速入门

  tu 4
Windows下C语言网络编程快速入门

  tu 5
  ( si ) bian yi lian jie
  zai tian jia le yuan dai ma yu zi yuan wen jian hou , jiu ke yi dui cheng xu bian yi lian jie le , ke an Ctrl+F7 jian bian yi , an F7 jian lian jie , an Ctrl+F5 jian yun xing cheng xu 。 zai lian jie qian shi yao zhu chong , zi yuan wen jian Get_IP.rc ye yao jin xing bian yi 。
  you yu zhe ge cheng xu yin yong le Winsock API han shu , zai bian yi lian jie qian , huan yao tian jia wsock32.dll, ju ti fang fa qian mian yi jing jie shao guo , zhe li jiu bu zai zhui shu le 。
  yi dian kan fa :
  li yong C yu yan bian xie Windows ying yong cheng xu you liang zhong fang shi : yi zhong shi Windows C bian cheng fang shi , ling yi zhong shi Visual C++ bian cheng fang shi 。 zai yi ban qing kuang xia ,Visual C++ bian cheng fang shi bian xie de cheng xu yuan dai ma liang xiao 、 kai fa shi de gong zuo liang xiao 、 gong zuo nan du ye jiao xiao , dan bian yi hou de dai ma liang jiao da , yun xing su du lue di ; er Windows C bian cheng fang shi bian xie de cheng xu yuan dai ma liang sui ran jiao da , dan ke zhi xing dai ma xiao lv gao 。 sui zhe ji shu de jin bu ,Visual C++ bian cheng fang shi yi bei guang fan cai yong , dan xiang wang luo bian cheng deng yi xie dui su du yao qiu gao 、 dui ying jian cao zuo jiao duo de cheng xu , da duo shu huan shi yong Windows C bian cheng fang shi kai fa de 。 ling wai , xue xi Windows C cheng xu she ji , huan you zhu yu geng shen ru di le jie Windows de nei mu he Windows API。
  cong jiao xue jiao du jiang , zai xue sheng ju bei le C yu yan he qi ta yi xie qian dao ke cheng ji chu hou , zhi jie jin ru Windows C wang luo bian cheng deng shi yong bian cheng ji shu ke cheng , bu jin ke yi rang xue sheng jin zao di jie chu dao qian yan de shi yong bian cheng ji shu , er qie huan ke yi ji da di tiao dong xue sheng de xue xi ji ji xing , zai you xian de shi jian li , xue dao geng duo de zhi shi he ji shu 。【原文】【汉音对照
 
 
 
 
 
 
 
 94.*.*.* 发表于2012-07-21 10:40:00
  That's going to make thnigs a lot easier from here on out.
  回复
  
  
 
 
 
日版宠物情人插曲《Winding Road》歌词

日版宠物情人2017的插曲,很带节奏感,日语的,女生唱的。 最后听见是在第8集的时候女主手割伤了,然后男主用嘴帮她吸了一下,插曲就出来了。 歌手:Def...

兄弟共妻,我成了他们夜里的美食

老钟家的两个儿子很特别,就是跟其他的人不太一样,魔一般的执着。兄弟俩都到了要结婚的年龄了,不管自家老爹怎么磨破嘴皮子,兄弟俩说不娶就不娶,老父母为兄弟两操碎了心...

如何磨出破洞牛仔裤?牛仔裤怎么剪破洞?

把牛仔裤磨出有线的破洞 1、具体工具就是磨脚石,下面垫一个硬物,然后用磨脚石一直磨一直磨,到把那块磨薄了,用手撕开就好了。出来的洞啊很自然的。需要猫须的话调几...

我就是扫描下图得到了敬业福和爱国福

先来看下敬业福和爱国福 今年春节,支付宝再次推出了“五福红包”活动,表示要“把欠大家的敬业福都还给大家”。 今天该活动正式启动,和去年一样,需要收集“五福”...

冰箱异味产生的原因和臭味去除的方法

有时候我们打开冰箱就会闻到一股异味,冰箱里的这种异味是因为一些物质发出的气味的混合体,闻起来让人恶心。 产生这些异味的主要原因有以下几点。 1、很多人有这种习...

 
 
  C yu yan de xue xi , yi ban de fang shi shi , xian xue C, ran hou shi C++, zui hao huan yao you hui bian yu yan he wei ji yuan li ji chu , ran hou cai shi Visual C++。 zhe yang de fang shi , dui xue xi zhe lai shuo , yao hua fei hen duo shi jian he nai li 。 er zai xue xiao jiao xue zhong , ye mei you shi jian shen ru xue xi Windows bian cheng de shi yong ji shu le 。    qi shi , ju you le C yu yan ji chu hou , zai you yi xie ji ben de C++ lei de gai nian , jiu ke yi zhi jie xue xi Windows C bian cheng le 。    yi 、 zou jin Windows C yu yan    hen duo yu yan dou ba xian shi yi ge “Hello,World!” zuo wei di yi ge ru men cheng xu , C yu yan de di yi ge cheng xu shi zhe yang de : #include<stdio.h> main() {  PRintf(“Hello,World!”); }    jia ru ba main han shu xie cheng dai shen shu de main han shu , ying gai shi : #include<stdio.h> main(int arge,char *argv[]) {  printf(“Hello,World!”); }   Windows C de di yi ge cheng xu he zhe ge cheng xu zai xing shi he yuan li shang dou shi yi zhi de , zhi shi you liang dian bu tong :   1. zhu han shu jie shou de xing shen bu zhi shi ming ling xing zhong de zi fu chuan de ge shu he zi fu chuan de shou di zhi 。   2. C yu yan de hen duo han shu zai Windows C zhong dou ke yi ji xu shi yong , dan xiang printf() ping mu xian shi deng han shu jiu bu neng ji xu shi yong le 。 yin wei Windows shi duo ren wu cao zuo xi tong , ping mu yi bu zai wei mou yi ge ying yong cheng xu suo du you ,Windows C ying yong cheng xu yao xian shi zi fu chuan , xu yao shi yong Windows ti gong de API han shu , kai zi ji de chuang kou    xia mian shi yi ge zui jian dan de , xian shi “Hello,World!” de Windows C cheng xu : #include<windows.h> APIENTRY WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance, LPSTR lpCmdLine,int nCmdShow) {  MessageBox(NULL,"Hello,World!"," di yi ge Windows C cheng xu ",MB_OKMB_ICONASTERISK); }    zhu han shu de xing shen you si ge :   1) Hinstance: jie shou cheng xu yun xing shi dang qian shi li de ju bing ;   2) HprivInstance: qian yi ge shi li de ju bing ;   3) LpCmdLine: cheng xu ming ling xing zhi zhen ;   4) NcmdShow: yi ge yong lai zhi ding chuang kou xian shi fang shi de zheng shu 。    zhe ji ge shen shu de shi yong wo men hui zai shen ru de xue xi zhong jie shao de 。    xian shi Hello,Word! zi fu chuan , wo men shi yong le yi ge MessageBox han shu , zhe ge han shu hui zai ping mu shang xian shi yi ge dui hua kuang , ta de yuan xing shi : int MessageBox(HWND hWnd,LPCTSTR lpText,LPCTSTR lpCaption,UNIT uType)    si ge shen shu fen bie shi :   1) HWnd: fu chuang kou de ju bing ;   2) LpText: yao xian shi zi fu chuan de zhi zhen ;   3) LpCaption: dui hua kuang biao ti zi fu chuan de zhi zhen ;   4) UType: xian shi zai dui hua kuang shang de xiao tu biao de lei xing 。    shi yong zhe ge han shu yao bao han windows.h tou wen jian 。    tiao shi yi xia , zen me yang ? chuang kou shang tan chu le yi ge “ di yi ge Windows C cheng xu ” dui hua kuang , shang mian you yi xing zi :“Hello,World!”。    shi jie zhen de hen mei hao a !!    shen ru bian cheng :    zai C yu yan zhong , han shu de sheng ming , jia ru mei you zhi ming fan hui zhi lei xing , que sheng zhi wei void, zhe ge cheng xu de zhu han shu jiu mei you fan hui zhi 。 bu guo , zai Windows bian cheng shi , wo men zui hao yang cheng ge hao xi guan , zhi ming han shu de fan hui zhi lei xing , yin wei zai C++ zhong , han shu fan hui zhi lei xing shi bu ke yi que sheng de 。 er wo men zai Windows C bian cheng shi , huan shi hui yong dao C++ de yi xie gai nian , zhe yang zuo , you li yu yi hou shen ru di xue xi 。    gui fan yi dian de cheng xu ying gai shi zhe yang de : #include<windows.h> int APIENTRY WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance, LPSTR lpCmdLine,int nCmdShow) { MessageBox(NULL,"Hello,World!"," di yi ge Windows C cheng xu ",MB_OKMB_ICONASTERISK); return 0; }    zhe li , wo men sheng ming de lei xing wei int xing , bing qie fan hui yi ge zhi 0, zhe yang de han shu jiu ke yi shi yong zai fu duo yi dian de han shu tiao yong zhong le 。    zai zhe yi jie zhong , wo men you ji chu dou ti dao le ju bing de gai nian , ju bing he zhi zhen de gai nian bu tong , ta shi zuo wei cao zuo xi tong nei bu suo yin biao zhong de yi ge zhi lai shi yong de , zhe yang ke yi fang zhi ying yong cheng xu zhi jie fang wen ming dui xiang de nei bu jie gou , ti xian le Windows zi yuan zhi li de you yue xing 。 pi ru shuo , yi ge chuang kou zhao kai zhi hou , hao dui ying nei cun zhong de yi ge nei cun kuai , zhe ge chuang kou suo zai de nei cun kuai di zhi wang wang hui you cao zuo xi tong zuo dong tai de tiao zheng , dan qi que bu hui sui zhi bian hua 。 bu guo , tong guo ta ke yi fang wen zhe ge chuang kou , suo yi zai shi yong de shi hou , ke yi ba ta dang zuo zhi zhen yi yang kan dai 。    er 、 huo qu ben di ji suan ji de zhu ji ming he ip di zhi    he C yu yan yi yang , han shu shi Windows C bian cheng de zui ji ben de dan wei 。 bu guo ,Windows C zhu yao shi yong API han shu , er wang luo bian cheng ze zhu yao shi yong Winsock ti gong de API han shu 。   Winsock shi 90 nian dai chu , wei le fang bian wang luo bian cheng , you Microsoft lian he le qi ta ji jia gong si gong tong zhi ding de yi tao WINDOWS xia de wang luo bian cheng jie kou , ta shi tong guo C yu yan de dong tai lian jie ku fang shi ti gong gei yong hu ji ruan jian kai fa zhe de , zhu yao you winsock.h tou wen jian he dong tai lian jie ku winsock.dll zu cheng , mu qian you liang ge ban ben :Winsock1.1 he Winsock2.0。    zai Win32 ping tai shang , fang wen zhong duo de ji ceng wang luo xie yi ,Winsock shi shou xuan jie kou 。    yong Visual C++6.0 bian yi Windows C cheng xu , shi yong Winsock API han shu shi , shou xian yao ba wsock32.lib tian jia dao ta de ku mo kuai zhong , fou gang zai lian jie de shi hou , hui chu xian “error LNK2001” cuo wu 。 tian jia wsock32.lib de ju ti bu zhou shi : da kai gong cheng cai dan , xuan ze she zhi , zai tan chu de Project settings dui hua kuang zhong , dian ji link xuan xiang ka , ran hou zai dui xiang / ku mo kuai wen ben kuang zhong tian jia wsock32.lib。    zui jian dan de wang luo bian cheng shi huo qu ben ji de zhu ji ming he IP di zhi , zhe ge cheng xu shi yong le WSAStart()、WSAClenaup()、gethostname()、gethostbyname() si ge winsock API han shu , zhe si ge han shu de gong neng he shi yong fang fa jie shao ru xia :   1. WSAStartup():   【 han shu yuan xing 】 int PASCAL FAR WSAStartup(WORD wVersionRequired, LPWSADATA lpWSAData);   【 shi yong shuo ming 】    mei yi ge shi yong winsock de ying yong cheng xu , dou bi xu jin xing WSAStart han shu tiao yong , bing qie zhi you zai tiao yong cheng gong zhi hou cai neng shi yong qi ta de winsock wang luo cao zuo han shu 。   WVersionRequired:< shu ru > biao shi yu shi yong de Winsock ban ben , zhe shi yi ge WORD lei xing de zheng shu , ta de gao wei zi jie ding yi de shi ci ban ben hao , di wei zi jie ding yi de shi zhu ban ben hao 。   LpWSAData:< shu chu > shi yi ge zhi xiang WSADATA zi liao de zhi zhen 。 zhe ge zi liao wo men yi ban bu shi yong 。    fan hui zhi : tiao yong cheng gong fan hui 0; fou ze , fan hui chu cuo xin xi 。   2. WSAClenaup():   【 han shu yuan xing 】 int PASCAL FAR WSACleanup(void);   【 shi yong shuo ming 】   winsock shi yong hou , yao tiao yong WSACleanup han shu guan bi wang luo she bei , yi bian shi fang qi zhan yong de zi yuan 。   3.gethostname()   【 han shu yuan xing 】 int PASCAL FAR gethostname (char FAR * name, int namelen);   【 shi yong shuo ming 】    gai han shu ke yi huo qu ben di zhu ji de zhu ji ming , qi zhong :   name:< shu chu > yong yu zhi xiang suo huo qu de zhu ji ming de huan chong qu de zhi zhen 。   Namelen:< shu ru > huan chong qu de da xiao , yi zi jie wei dan wei 。    fan hui zhi : ruo wu cuo wu , fan hui 0; fou ze , fan hui cuo wu dai ma 。   4.gethostbyname()   【 han shu yuan xing 】 strUCt hostent FAR * PASCAL FAR gethostbyname(const char FAR * name);   【 shi yong shuo ming 】    gai han shu ke yi cong zhu ji ming shu ju ku zhong de dao dui ying de “ zhu ji ”。    gai han shu wei yi de shen shu name jiu shi qian mian tiao yong han shu gethostname() de dao de zhu ji ming 。 ruo wu cuo wu , gang fan hui yi ge zhi xiang hostent jie gou de pi zhen , ta ke yi biao shi yi ge “ zhu ji ” lie biao 。   Hostent jie gou ding yi ru xia : Struct hostent { char FAR * h_name; char FAR FAR ** h_aliases; short h_addrtype; char FAR FAR ** h_addr_list; }    qi zhong :   h_name:< shu ru > zhu ji ming di zhi (PC)。   h_aliases: yi ge you zhu ji bei yong ming zu cheng de kong zhong zhi shu zu 。   H_addrtype: fan hui di zhi de lei xing , dui yu Winsock, zhe ge yu zong shi PF_INET。   H_lenth: mei ge di zhi de chang du ( zi jie shu ), dui ying yu PF_INET yu ying gai wei 4。   H_addr_list: ying gai yi kong zhi zhen jie yi de zhu ji di zhi de lie biao , fan hui de di zhi shi yi wang luo shun xu pai lie de 。    qi zhong ,h_addr_list[0] cun fang de jiu shi ben di zhu ji de 4 ge zi jie de IP di zhi , ji :   h_addr_list[0][0].h_addr_list[0][1].h_addr_list[0][2].h_addr_list[0][3]    yi ge jian dan de yong xiao xi kuang xian shi zhu ji ming he IP di zhi de yuan cheng xu ru xia : #include<winsock.h> int WSA_return; WSADATA WSAData; HOSTENT *host_entry; char host_name[256]; char host_address[256]; int APIENTRY WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance, LPSTR lpCmdLine,int nCmdShow) {  WSA_return=WSAStartup(0x0101,&WSAData);  if(WSA_return==0)  {   gethostname(host_name,256);   host_entry=gethostbyname(host_name);   if(host_entry!=0)   {    wsprintf(host_address,"%d.%d.%d.%d",     (host_entry->h_addr_list[0][0]&0x00ff),     (host_entry->h_addr_list[0][1]&0x00ff),     (host_entry->h_addr_list[0][2]&0x00ff),     (host_entry->h_addr_list[0][3]&0x00ff));    MessageBox(NULL,host_address,host_name,MB_OK);   }  }  WSACleanup();  return 0; }    shen ru bian cheng :    qian mian xian shi IP di zhi de shi hou , wo men shi yong de shi xiao xi kuang , gui fan yi dian de bian cheng ying gai shi yong dui hua kuang , ru he bian ji yi ge dui hua kuang , hen duo shu zhong dou you jie shao , bian ji de dui hua kuang ke shen kao tu 5 de yun xing jie mian 。    tou wen jian Get_IP.h ru xia : BOOL APIENTRY Hostname_ipDlgPro(HWND hDlg,UINT message,WPARAM wParam,LPARAM lParam);    zhe ge cheng xu zhi shi yong le yi ge dui hua kuang guo cheng , yi ban ba zhe ge guo cheng de sheng ming fang zai tou wen jian zhong 。    yuan cheng xu Get_IP.c: #include<winsock2.h> #include"Get_IP.h" #include"resource.h" // zhe ge tou wen jian zai chuang jian zi yuan de shi hou hui zi dong sheng cheng , // bing hui zai cha ru zi yuan shi zi dong sheng cheng kong jian biao shi hao . int WSA_return; WSADATA WSAData; HOSTENT *host_entry; char host_name[256]; char host_address[256]; int APIENTRY WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance, LPSTR lpCmdLine,int nCmdShow) {  WSA_return=WSAStartup(0x0101,&WSAData);  if(WSA_return==0)  {   gethostname(host_name,256);   host_entry=gethostbyname(host_name);   if(host_entry!=0)   {    wsprintf(host_address,"%d.%d.%d.%d",     (host_entry->h_addr_list[0][0]&0x00ff),     (host_entry->h_addr_list[0][1]&0x00ff),     (host_entry->h_addr_list[0][2]&0x00ff),     (host_entry->h_addr_list[0][3]&0x00ff));   }  }  WSACleanup();  DialogBox(hInstance,"DIALOG1",NULL,(DLGPROC)Hostname_ipDlgPro);  return 0; } BOOL APIENTRY Hostname_ipDlgPro(HWND hDlg,UINT message, WPARAM wParam,LPARAM lParam) {  switch(message)  {   case WM_INITDIALOG:    return(TRUE);   case WM_COMMAND:    if(LOWORD(wParam)==IDOK)    {     SetDlgItemText(hDlg,IDC_EDIT1,host_name);     SetDlgItemText(hDlg,IDC_EDIT2,host_address);     SetDlgItemText(hDlg,IDCANCEL," que ding ");    }    if(LOWORD(wParam)==IDCANCEL)     EndDialog(hDlg,TRUE);     return(TRUE);    break;  }  return(FALSE); }    san 、 li yong VisualC++6.0 bian yi Windows C cheng xu    li yong Visual C++6.0 bian yi Windows C cheng xu yi ban yao jing guo yi xia si ge bu zhou : xin jian xiang mu 、 tian jia dai ma 、 tian jia zi yuan he bian yi lian jie 。 xia mian wo men jian dan di jie shao yi xia cheng xu shang mian jie shao de gui fan de huo qu ben ji de zhu ji ming he IP di zhi cheng xu de bian yi guo cheng :   ( yi ) xin jian xiang mu   1. qi dong MicrosoftVisualC++, ran hou zai 【 wen jian 】 cai dan zhong xian ze 【 xin jian 】 ming ling , tan chu ru tu 1 suo shi de 【 xin jian 】 dui hua kuang : [url=http://www.wangchao.net.cn/bbs/pydetail_1785464.html][img]http://image.wangchao.net.cn/it/1323423033089.jpg[/img][/url] dian ji cha kan da tu tu 1   2. zai 【 xin jian 】 dui hua kuang zhong , xi tong da kai de shi mo ren de 【 gong cheng 】 xuan xiang ka ,【 gong cheng 】 xuan xiang ka zuo ce de lie biao kuang zhong you duo zhong jian li gong cheng de fang shi , wo men xuan zhong “Win32 application” xuan xiang 。   3. zai 【 wei zhi 】 wen ben kuang zhong shu ru xin jian gong cheng de lu jing ( li ru :F:\), zai 【 gong cheng 】 wen ben kuang zhong shu ru gong cheng ming cheng ( li ru :Get_IP)。   4. xuan zhong 【 ping tai 】 lie biao kuang zhong de Win32 fu xuan kuang , ran hou dan ji 【 que ding 】 an niu 。   5. zai sui hou de dui hua kuang zhong , dou xuan ze mo ren she zhi , wan cheng hou , jin ru tu 2 shi jie mian : [url=http://www.wangchao.net.cn/bbs/pydetail_1785464.html][img]http://image.wangchao.net.cn/it/1323423048418.jpg[/img][/url] dian ji cha kan da tu tu 2   ( er ) tian jia dai ma    zai VisualC++6.0 zhong , yuan dai ma yi ban cun fang zai yuan dai ma wen jian he tou wen jian zhong , wang xiang mu zhong tian jia yuan dai ma shi fei chang fang bian de , wei xiang mu xin jian yi ge yuan dai ma wen jian yi ban yao an xia shu fang fa cao zuo :   1. xuan ze 【 gong cheng 】【 tian jia gong cheng 】【 xin jian 】 xuan xiang , tan chu tu 3 suo shi 【 xin jian 】 dui hua kuang : [url=http://www.wangchao.net.cn/bbs/pydetail_1785464.html][img]http://image.wangchao.net.cn/it/1323423048759.jpg[/img][/url] dian ji cha kan da tu tu 3   2. zai dui hua kuang de 【 wen jian 】 xuan xiang ka zhong , zuo ce de lie biao kuang xuan zhong “C++ Source File” xuan xiang , you ce xuan zhong 【 tian jia gong cheng 】 fu xuan kuang , bing zai 【 wen jian 】 wen ben kuang zhong shu ru yuan wen jian ming ( li ru :Get_IP.c)。   3. dan ji 【 que ding 】 an niu ,【 xin jian 】 dui hua kuang jiang bei bi , yong hu jiu ke yi zai xin jian de Get_IP.c zhong shu ru cheng xu de yuan dai ma le 。   4. tian jia tou wen jian Get_IP.h de fang fa he shang mian suo shu guo cheng yi yang , zhi shi zai 【 wen jian 】 xuan xiang ka zhong , zuo ce de lie biao kuang yao xian zhong “C/C++ Header File” xuan xiang 。 zai 【 wen jian 】 wen ben kuang zhong shu ru tou wen jian ming ( li ru :Get_IP.h)。   ( san ) tian jia zi yuan    zai tian jia zi yuan qian , bi xu zai xiang mu zhong xian tian jia yi ge zi yuan wen jian , ran hou ke li yong Visual C++6.0 ti gong de zi yuan bian ji qi wei xiang mu xin jian yi ge zi yuan , ju ti bu zhou ru xia :   1. xuan ze 【 gong cheng 】【 tian jia gong cheng 】【 xin jian 】 xuan xiang , tan chu tu 3 suo shi 【 xin jian 】 dui hua kuang 。   2. zai dui hua kuang de 【 wen jian 】 xuan xiang ka zhong , zuo ce de lie biao kuang xuan zhong “Rsource Script” xuan xiang , you ce xuan zhong 【 tian jia gong cheng 】 fu xuan kuang , bing zai 【 wen jian 】 wen ben kuang zhong shu ru zi yuan wen jian ming ( li ru :Get_IP.rc)。   3. dan ji que ding , hui dao zhu chuang kou hou , xuan ze 【 cha ru 】【 zi yuan 】 xuan xiang , da kai 【 cha ru zi yuan 】 dui hua kuang , ru tu 4 suo shi , zai 【 zi yuan lei xing 】 lie biao kuang zhong xuan zhong “Dialog” xuan xiang , dan ji 【 xin jian 】 an niu , fan hui zhu chuang kou hou , ji ke li yong dui hua kuang bian ji qi jin xing bian ji le 。 bian ji hou de dui hua kuang ru tu [url=http://www.wangchao.net.cn/bbs/pydetail_1785464.html][img]http://image.wangchao.net.cn/it/1323423049082.jpg[/img][/url] tu 4 [url=http://www.wangchao.net.cn/bbs/pydetail_1785464.html][img]http://image.wangchao.net.cn/it/1323423049415.jpg[/img][/url] tu 5   ( si ) bian yi lian jie    zai tian jia le yuan dai ma yu zi yuan wen jian hou , jiu ke yi dui cheng xu bian yi lian jie le , ke an Ctrl+F7 jian bian yi , an F7 jian lian jie , an Ctrl+F5 jian yun xing cheng xu 。 zai lian jie qian shi yao zhu chong , zi yuan wen jian Get_IP.rc ye yao jin xing bian yi 。    you yu zhe ge cheng xu yin yong le Winsock API han shu , zai bian yi lian jie qian , huan yao tian jia wsock32.dll, ju ti fang fa qian mian yi jing jie shao guo , zhe li jiu bu zai zhui shu le 。    yi dian kan fa :    li yong C yu yan bian xie Windows ying yong cheng xu you liang zhong fang shi : yi zhong shi Windows C bian cheng fang shi , ling yi zhong shi Visual C++ bian cheng fang shi 。 zai yi ban qing kuang xia ,Visual C++ bian cheng fang shi bian xie de cheng xu yuan dai ma liang xiao 、 kai fa shi de gong zuo liang xiao 、 gong zuo nan du ye jiao xiao , dan bian yi hou de dai ma liang jiao da , yun xing su du lue di ; er Windows C bian cheng fang shi bian xie de cheng xu yuan dai ma liang sui ran jiao da , dan ke zhi xing dai ma xiao lv gao 。 sui zhe ji shu de jin bu ,Visual C++ bian cheng fang shi yi bei guang fan cai yong , dan xiang wang luo bian cheng deng yi xie dui su du yao qiu gao 、 dui ying jian cao zuo jiao duo de cheng xu , da duo shu huan shi yong Windows C bian cheng fang shi kai fa de 。 ling wai , xue xi Windows C cheng xu she ji , huan you zhu yu geng shen ru di le jie Windows de nei mu he Windows API。    cong jiao xue jiao du jiang , zai xue sheng ju bei le C yu yan he qi ta yi xie qian dao ke cheng ji chu hou , zhi jie jin ru Windows C wang luo bian cheng deng shi yong bian cheng ji shu ke cheng , bu jin ke yi rang xue sheng jin zao di jie chu dao qian yan de shi yong bian cheng ji shu , er qie huan ke yi ji da di tiao dong xue sheng de xue xi ji ji xing , zai you xian de shi jian li , xue dao geng duo de zhi shi he ji shu 。
󰈣󰈤
  免责声明:本文仅代表作者个人观点,与王朝网络无关。王朝网络登载此文出于传递更多信息之目的,并不意味着赞同其观点或证实其描述,其原创性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容、文字的真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
桌球宝贝_性感在蔓延(3)
桌球宝贝_性感在蔓延(2)
银杏树下清纯女孩(9)
银杏树下清纯女孩(8)
痞子的甘南日记
疑是银河落九天
雪域坝上四——纯美色
冬日恋歌——西城杨柳弄轻柔
 
>>返回首页<<
 
 
 为你推荐
 
 
 
 转载本文
 UBB代码 HTML代码
复制到剪贴板...
 
 热帖排行
 
 
 
 
 
©2005- 王朝网络 版权所有