Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
W

wangningyu

@wangningyu
About
Posts
133
Topics
51
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • How to distinguish the broad packets or normal packets?
    W wangningyu

    Thanks !

    C / C++ / MFC help tutorial question

  • How to distinguish the broad packets or normal packets?
    W wangningyu

    The following is a fragment of code:

    sockaddr\_in		from,a;
    WSADATA			wsdata;
    BOOL			optval = TRUE;
    u\_short			uPort  = m\_nPort;
    
    if(WSAStartup(0x0202,&wsdata) != 0)
    {
    	CString strErr;
    	strErr.Format(\_T("WSAStartup Init failed! Error code:%d"),WSAGetLastError());
    	AddNote(strErr);
    	\_endthreadex(0);
    	return FALSE;
    }
    
    a.sin\_family		= AF\_INET;
    a.sin\_addr.s\_addr	= 0;
    a.sin\_port			= htons(uPort);
    
    from.sin\_family			= AF\_INET;
    from.sin\_addr.s\_addr	= INADDR\_BROADCAST;
    from.sin\_port			= htons(uPort);
    
    int fromlength=sizeof(SOCKADDR);
    pThread->m\_socket = socket(AF\_INET,SOCK\_DGRAM,0);
    setsockopt(pThread->m\_socket,SOL\_SOCKET,SO\_BROADCAST,(char FAR \*)&optval,sizeof(optval));
    bind(pThread->m\_socket,(sockaddr \*)&a,sizeof(sockaddr\_in));
    
    char		buf\[BUF\_MAX\_LEN\] = {0x00};
    int			nLen = 0;
    char		\*pszIPClient = NULL;
    u\_short		uPortClient  = 0;
    THREADBOARD	\*pThreadBoard = NULL;
    CString		strInit = \_T("");
    
    strInit.Format(\_T("Port: %d Now waiting for clients..."),uPort);
    AddNote(strInit);
    
    while(true)
    {
    	nLen = recvfrom(pThread->m\_socket,buf,BUF\_MAX\_LEN,0,(struct sockaddr FAR \*)&from,(int FAR \*)&fromlength);
    	if(nLen > 0)
    	{
    		// How to distinguish is send broadcast , or normal send ?
    	}
    }
    

    Thanks for your reply !

    C / C++ / MFC help tutorial question

  • About opengl screen shot is black
    W wangningyu

    shot.h

    /*
    Class Name:

      CTGALoader.
    
      This class loads a tga texture into this object.
      
    shot.h
    

    */

    #ifndef CTGALOADER_H
    #define CTGALOADER_H

    // Remember to place all your GL/system header files that you will need to run class function

    class CTGALoader
    {
    public:
    CTGALoader(); // Constructor.
    ~CTGALoader(); // Destructor.

      bool LoadTGAFile(char \*filename);   // Load a .tga image file.
      void SaveTGAScreenShot(char \*filename,
                             int width,
                             int height); // Save a .tga screen shot.
      void FreeImage();                   // Delete a image.
    
      unsigned int ID;                    // ID used for generating the textures in OpenGl.
      int imageWidth;                     // Width of a texture.
      int imageHeight;                    // Height of a texture.
    

    protected:
    void GenerateTexture(); // Generate a texture in OpenGL.
    bool LoadTGA(char *filename); // Load a tga image.
    bool WriteTGA(char *file, short int width,
    short int height,
    unsigned char *image); // Write a tga file.

      unsigned char \*image;               // Texture image.
      bool textureExist;                  // This will be used if the image was loaded.
      int type;                           // Image format.
    

    };

    #endif

    shot.cpp

    /*
    Class Name:

      CTGALoader.
    
    shot.h
    

    */

    #include"shot.h"

    #include
    #include <./gl/GL.H>
    #include <./gl/GLU.H>
    #include

    #pragma comment(lib,"OPENGL32.LIB")
    #pragma comment(lib,"Glu32.lib")

    CTGALoader::CTGALoader()
    {
    // Give everything default values.
    image = 0;
    textureExist = false;
    type = 0;
    }

    CTGALoader::~CTGALoader()
    {
    FreeImage(); // Delete all images and dynamic memory.
    }

    bool CTGALoader::LoadTGAFile(char *file)
    {
    if(textureExist)
    FreeImage();

    if(!LoadTGA(file))
    return false;

    // Make sure the image loaded.
    if(image == 0)
    {
    return false;
    }

    GenerateTexture();

    textureExist = true;

    return true;
    }

    void CTGALoader::GenerateTexture()
    {
    // Generate the texture and text the id to the images id.
    glGenTextures(1, &ID);

    // Here we bind the texture and set up the filtering.
    glBindTexture(GL_TEXTURE_2D, ID);
    glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

    C / C++ / MFC c++ graphics game-dev performance

  • How to ban ip in the chatroom ?
    W wangningyu

    the vector and map like same as. what's the mean ?

    C / C++ / MFC graphics sysadmin tutorial question

  • How to ban ip in the chatroom ?
    W wangningyu

    The chatroom server app is used TCP WSAasyncSelect mode . I want ban some ip in the chatroom,let him doesn't connect the server. Now I use a vector list to save the ip, when someone connect ,it will traversal search . if in the black list, then call closesocket. But this is the low efficiency. Is there any other way? Thanks for you replay !

    C / C++ / MFC graphics sysadmin tutorial question

  • About the screen shot is black or desktop.
    W wangningyu

    I use GDI or DirectX way to capture the screen shot. In windows xp or 2003, the picture is normal, but in some win7 (32 or 64) system: It is the desktop's image or whole black , when running a full screen game. what's wrong ? and how to fix it ? :)

    C / C++ / MFC graphics game-dev help tutorial question

  • How to insert a "#" to some lines ?
    W wangningyu

    try to use CStdioFile::ReadString to read one line once. :)

    C / C++ / MFC tutorial question

  • How to defense attack of the WSAAsyncSelect TCP Server ?
    W wangningyu

    How to defense attack of the WSAAsyncSelect TCP Server ?[^] The server program is attacked buy many connection, like WEB DDOS. Please Help !

    C / C++ / MFC com sysadmin help tutorial question

  • How to get unplug the Ethernet cable message in WSAAsyncSelect ?
    W wangningyu

    thanks ! :)

    C / C++ / MFC sysadmin tutorial question

  • How to get unplug the Ethernet cable message in WSAAsyncSelect ?
    W wangningyu

    First , thanks for your reply ! but how can I get it offline real-time ? I set a timer to call CheckIsOnline() to find the client struct's m_nLastActive; the client call SendHeartPacket() every 30 second, and the server recv it then set the m_nLastActive. when (GetTickCount() - m_nLastActive) >= (1000 * 10),I will remove from the list. but when I run some days in wlan server, it be crashed,I cound't found what's wrong with it. :( This is my biggest headache !

    C / C++ / MFC sysadmin tutorial question

  • How to get unplug the Ethernet cable message in WSAAsyncSelect ?
    W wangningyu

    when I unplug the Ethernet cable,the client doesn't send the FD_CLOSE event to the server so the server's online list isn't fresh new. How about this ?

    C / C++ / MFC sysadmin tutorial question

  • How to get the client's abort message with WSAAsyncSelect ?
    W wangningyu

    may be is right , but is there any way to fix it ?

    C / C++ / MFC sysadmin help tutorial question

  • How to get the client's abort message with WSAAsyncSelect ?
    W wangningyu

    Hello ! I use WSAAsyncSelect to do a small ChatSystem in the WLAN Server. (the max client may be has 100-200 online,and the ordinary time is 30-50 online at the same time.) like this:

    SOCKET sock = (SOCKET) wParam;
    if(WSAGETSELECTERROR(lParam)){
    DeleteClient(sock);
    return;
    }

    switch(WSAGETSELECTEVENT(lParam)){
    case FD_ACCEPT:
    sClient = accept(wParam, (struct sockaddr *)&client, &iAddrSize);
    // Add to the CPtrList
    // ......
    WSAAsyncSelect(sClient, hwnd, WM_SOCKET, FD_READ | FD_CLOSE);
    break;

    case FD_READ:
    ReadData(sock); // Paser the data.
    break;

    case FD_CLOSE:
    DeleteClient(sock); //Del from the CPtrList.
    break;

    default:
    break;
    }

    at last ,when add/del client, it will refresh onlines info to the Server's list control. May be it doesn't receive the FD_CLOSE message. but usually ,it has some few days ago results. I run in the Lan and use other Lan computer to test it, but can't found this problem. How about this ? Thanks for you reply !

    C / C++ / MFC sysadmin help tutorial question

  • How to fix the WinInet's block bug ?
    W wangningyu

    I use WinInet + MFC to post some form to the web server. I add the log module, at last found this: 1. call CInternetSession::GetHttpConnection 2. call CInternetSession::OpenURL 3. call CHttpFile::SendRequest 4. call CHttpFile::QueryInfoStatusCode (block) at the step 4, some computer is ok, but some computer is block here. when is block , the last error code:12002 ,it means time out. I search in this web and google, but usually saied that's the WinInet's bug. What should I do? ////////////////////////////////////////////// Thanks for your reply ! :)

    C / C++ / MFC help c++ sysadmin tutorial question

  • How to use tcp keepalive to check the client is alive?
    W wangningyu

    I use the WSAAsyncSelect now, and then the server use the vector to save the client. the server has a ListCtrl to show the online's client,and then FD_ACCEPT it will push_back into the vector. and then FD_CLOSE it will earse from the vector. but it often not receive FD_CLOSE when the client's power failure. I found the setsockopt from google, but don't quite understand the Windows Socket TCP Keepalive. how to use it ? Thanks for your reply !

    C / C++ / MFC graphics sysadmin tutorial question

  • How to use CreateRemoteThread in Win7/Vista ?
    W wangningyu

    Thanks ! :)

    C / C++ / MFC com help tutorial question

  • How to use CreateRemoteThread in Win7/Vista ?
    W wangningyu

    The program running in xp is no problem ,bu in Win7 ,it doesn't use the CreateRemoteThread to inject a dll to other process. if I use the administrator to run,is also failed ! It's there any where to do this in Win7/Vista ? ;P I found this note: http://www.codeproject.com/Messages/3625827/It-dont-work-on-64bit-win7-system.aspx[^] but I can't open the url, because the country's gateway shield it. Thanks for your reply ! Best Regards !

    C / C++ / MFC com help tutorial question

  • How about the CPropertyPage OnOK ? [modified]
    W wangningyu

    :-D

    C / C++ / MFC question

  • How about the CPropertyPage OnOK ? [modified]
    W wangningyu

    Hello everybody ! this is a SDI Project,in the toolbar,there are two button,it used to show different dialog.

    class CTestView;

    void CTestView::OnShowDlgA()
    {
    // TODO: Add your command handler code here
    CPropertySheet sheet(_T("TestDlgA"));
    CTestDlgA dlg;

    sheet.AddPage(&dlg);
    if(IDOK == sheet.DoModal())
    {
    	// do something.
    }
    

    }

    void CTestView::OnShowDlgB()
    {
    // TODO: Add your command handler code here
    CPropertySheet sheet(_T("TestDlgB"));
    CTestDlgB dlg;

    sheet.AddPage(&dlg);
    if(IDOK == sheet.DoModal())
    {
    	// do something.
    }
    

    }

    class CTestDlgA : public CPropertyPage
    {
    // ...
    }

    // add the virtual function
    void CTestDlgA ::OnOK()
    {
    // when is false,it will return ,and then end the dialog.
    // I don't want it closed.
    if( !SaveParams() )
    return;

    EndDialog(IDOK);
    //CPropertyPage::OnOK();
    

    }

    class CTestDlgB : public CPropertyPage
    {
    // ...
    }

    // add the virtual function
    void CTestDlgB ::OnOK()
    {
    // usually, this dialogB doesn't closed when is false.
    // but the dialogA is closed at this.
    if( !SaveParams() )
    return;

    EndDialog(IDOK);
    //CPropertyPage::OnOK();
    

    }

    Why will appear this kind of circumstance? Thanks for your reply ! Best Regards !

    modified on Wednesday, May 11, 2011 3:34 AM

    C / C++ / MFC question

  • How to use the mysql in the child thread ?
    W wangningyu

    I setup the mysql5.0 and sdk. now I create a mfc dialog project, and use it in the Main Thread ,it's no problem. but I create another thread, in the thread function I define a variables like this: DWORD CTestDlg::ThreadFun(LPVOID lParam) { CTestDlg *pDlg = (CTestDlg *)lParam; MYSQL mysql; mysql_init(&mysql); // here is access violation. Unhandled exception in Test.exe(MYSQLD.exe): 0xc0000005: Access Violation. // if I use it in the main thread,is ok. } so how to use the mysql in the child thread ?

    C / C++ / MFC c++ mysql help tutorial question
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups