欢迎来到天天文库
浏览记录
ID:34722508
大小:80.68 KB
页数:4页
时间:2019-03-10
《c获取ip地址和主机名》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、C++获取IP地址和主机名一个简单的c++程序,用于获取主机名和IP地址。源码下载地址:http://www.vdisk.cn/down/index/10540450该程序通过自己的测试,能在visualc++6.0中完美运行。\GetIP.cpp#ifdef_DEBUG#definenewDEBUG_NEW#undefTHIS_FILEstaticcharTHIS_FILE[]=__FILE__;#endif////////////////////////////////////////////////////
2、///////////////////////////CGetIPAppBEGIN_MESSAGE_MAP(CGetIPApp,CWinApp)//{{AFX_MSG_MAP(CGetIPApp)//NOTE-theClassWizardwilladdandremovemappingmacroshere.//DONOTEDITwhatyouseeintheseblocksofgeneratedcode!//}}AFX_MSGON_COMMAND(ID_HELP,CWinApp::OnHelp)END_MESSAGE
3、_MAP()///////////////////////////////////////////////////////////////////////////////CGetIPAppconstructionCGetIPApp::CGetIPApp(){//TODO:addconstructioncodehere,//PlaceallsignificantinitializationinInitInstance}//////////////////////////////////////////////////
4、/////////////////////////////TheoneandonlyCGetIPAppobjectCGetIPApptheApp;///////////////////////////////////////////////////////////////////////////////CGetIPAppinitializationBOOLCGetIPApp::InitInstance(){if(!AfxSocketInit()){AfxMessageBox(IDP_SOCKETS_INIT_FAI
5、LED);returnFALSE;}AfxEnableControlContainer();//Standardinitialization//Ifyouarenotusingthesefeaturesandwishtoreducethesize//ofyourfinalexecutable,youshouldremovefromthefollowing//thespecificinitializationroutinesyoudonotneed.#ifdef_AFXDLLEnable3dControls();//
6、CallthiswhenusingMFCinasharedDLL#elseEnable3dControlsStatic();//CallthiswhenlinkingtoMFCstatically#endifCGetIPDlgdlg;m_pMainWnd=&dlg;intnResponse=dlg.DoModal();if(nResponse==IDOK){//TODO:Placecodeheretohandlewhenthedialogis//dismissedwithOK}elseif(nResponse==I
7、DCANCEL){//TODO:Placecodeheretohandlewhenthedialogis//dismissedwithCancel}WSADATAwsaData;WSAStartup(MAKEWORD(1,1),&wsaData);//Sincethedialoghasbeenclosed,returnFALSEsothatweexitthe//application,ratherthanstarttheapplication'smessagepump.returnFALSE;}intCGetIPA
8、pp::ExitInstance(){WSACleanup();returnCWinApp::ExitInstance();}\GetIP.h//GetIP.h:mainheaderfilefortheGETIPapplication//#if!defined(AFX_GETIP_H__4F5A3E39_11E1_4654_A5DA_75F3810AD47
此文档下载收益归作者所有