void CZhaoyn_GetIPView::OnDraw(CDC* pDC)
{
CZhaoyn_GetIPDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here char name[50];
gethostname(name,50);
CString strName;
strName = name; HDC hdc = ::GetDC( m_hWnd );
TextOut(hdc,200,200,strName,strName.GetLength());
}
错误是:error LNK2001: unresolved external symbol __imp__gethostname@8是什么原因呢?(跟头文件有关吗)

解决方案 »

  1.   

    头文件之下加上 #pragma comment(lib, “ws2_32");
      

  2.   

    先得包含ws2_32.lib,然后调用一个WSAStartup函数,再使用gethostname,name最好用memset初始化一下
    关于WSAStartup,msdn是这样写的:
    WORD wVersionRequested;
    WSADATA wsaData;
    int err;
     
    wVersionRequested = MAKEWORD( 2, 2 );
     
    err = WSAStartup( wVersionRequested, &wsaData );
    if ( err != 0 ) {
        /* Tell the user that we could not find a usable */
        /* WinSock DLL.                                  */
        return 1;
    }
     
    /* Confirm that the WinSock DLL supports 2.2.*/
    /* Note that if the DLL supports versions greater    */
    /* than 2.2 in addition to 2.2, it will still return */
    /* 2.2 in wVersion since that is the version we      */
    /* requested.                                        */
     
    if ( LOBYTE( wsaData.wVersion ) != 2 ||
            HIBYTE( wsaData.wVersion ) != 2 ) {
        /* Tell the user that we could not find a usable */
        /* WinSock DLL.                                  */
        WSACleanup( );
        return 1; 
    }
     
    /* The WinSock DLL is acceptable. Proceed. */
      

  3.   

    Zhaoyn_GetIPView.h 文件中加:Zhaoyn_GetIPView.h #include "winsock2.h"
    #pragma comment(lib, "ws2_32")Zhaoyn_GetIPView.cpp 文件中加:CZhaoyn_GetIPView::CZhaoyn_GetIPView()
    {
    // TODO: add construction code here
    WORD wVersionRequested;
    WSADATA wsaData;
    wVersionRequested = MAKEWORD( 2, 2 );
     
    WSAStartup( wVersionRequested, &wsaData );}