Jump to content
  • Advertisement

White Scorpion

Member
  • Content Count

    238
  • Joined

  • Last visited

Community Reputation

148 Neutral

About White Scorpion

  • Rank
    Member
  1. White Scorpion

    accept() fails

    I finally found the problem. It's because of my ugly design. I re-designed it with a friend. The deal was that when connect() ended successfully, it called TerminateThread() on ListeningThreadProc() which would make it impossible for it to call accept(). My friend told me to make a separate server program and then a client program. Thank you guys though.
  2. White Scorpion

    accept() fails

    Annoying. It's still not working =/ Keep suggestions coming = /
  3. White Scorpion

    accept() fails

    What should I bind it to then ? Isn't it the hole point to bind the port on my computer ? I don't really know what bind() does to tell the truth.
  4. White Scorpion

    accept() fails

    1. I made it so my router forwards the connection to my computer. 2. What does the above post tries to say ? O_o
  5. White Scorpion

    accept() fails

    Hey guys. I'm working on my app right now and there's something not working. I tried connecting to one of my friend's computer -- to whom I gave the application -- but the message box test located in ListeningThreadProc() never popped up which means that accept() failed. Here's the code: #include <windows.h> #include "Scintilla.h" #include "SciLexer.h" #include "tabctrl.h" #include "mdi_child.h" #include "network.h" #include "resource.h" HWND client; LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); BOOL CALLBACK DlgProc(HWND, UINT, WPARAM, LPARAM); int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int) { OC_Interface::RegisterMDIChildClass(); OC_Net::Initialize(); WNDCLASSEX wc; ZeroMemory(&wc, sizeof(WNDCLASSEX)); wc.cbSize = sizeof(WNDCLASSEX); wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1); wc.hCursor = LoadCursor(0, IDC_ARROW); wc.hIcon = LoadIcon(0, IDI_WINLOGO); wc.lpfnWndProc = WndProc; wc.lpszClassName = "Online Coder"; if(!RegisterClassEx(&wc)) MessageBox(0, "Couldn't register class", 0, 0); HWND hwnd = CreateWindow("Online Coder", "", WS_OVERLAPPEDWINDOW, 0, 0, CW_USEDEFAULT, CW_USEDEFAULT, 0, 0, 0, 0); UpdateWindow(hwnd); ShowWindow(hwnd, true); DialogBox(0, MAKEINTRESOURCE(IDD_DIALOG1), hwnd, DlgProc); MSG msg; while(true) { while(PeekMessage(&msg, 0, 0, 0, PM_REMOVE) != 0) { if(msg.message == WM_QUIT) break; if(!TranslateMDISysAccel(client, &msg)) { TranslateMessage(&msg); DispatchMessage(&msg); } } if(msg.message == WM_QUIT) break; } return 0; } HWND whatever; LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wprm, LPARAM lprm) { switch(msg) { case WM_CREATE: { CLIENTCREATESTRUCT ccs; ZeroMemory(&ccs, sizeof(CLIENTCREATESTRUCT)); ccs.idFirstChild = MDIFIRSTCHILD; client = CreateWindowEx(0, "mdiclient", 0, WS_CHILD | WS_CLIPCHILDREN | WS_VSCROLL | WS_HSCROLL | WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, hwnd, 0, 0, (LPVOID)&ccs); OC_Interface::CreateNewMDIChild(client, "whatever"); } break; case WM_DESTROY: OC_Interface::UnregisterMDIChildClass(); PostQuitMessage(0); break; default: return DefFrameProc(hwnd, client, msg, wprm, lprm); } return 0; } BOOL CALLBACK DlgProc(HWND hdlg, UINT msg, WPARAM wprm, LPARAM lprm) { switch(msg) { case WM_INITDIALOG: return TRUE; case WM_COMMAND: switch(LOWORD(wprm)) { case IDOK: static char temp[20]; GetDlgItemText(hdlg, IDC_IPBOX, temp, 20); OC_Net::ConnectToIP(temp); EndDialog(hdlg, 0); return TRUE; } return TRUE; default: return FALSE; } return FALSE; } #ifndef _NETWORK_H_INCLUDED_ #define _NETWORK_H_INCLUDED_ #define NET_DEFAULTPORT 1234 #define NET_ERR_NOTCONNECTEd 0x #include <winsock.h> #include <windows.h> #pragma comment(lib, "wsock32.lib") namespace OC_Net { DWORD WINAPI ListeningThreadProc(void*); void ConnectToIP(const char*); void Initialize(); extern SOCKET ConnSocket; extern HANDLE ListeningThread; }; #endif // _NETWORK_H_INCLUDED_ #include "network.h" namespace OC_Net { SOCKET ConnSocket = INVALID_SOCKET; HANDLE ListeningThread = 0; DWORD WINAPI ListeningThreadProc(void* unused) { sockaddr_in sin; ZeroMemory(&sin, sizeof(sockaddr_in)); sin.sin_addr.s_addr = inet_addr("127.0.0.1"); sin.sin_family = AF_INET; sin.sin_port = htons(NET_DEFAULTPORT); SOCKET s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); if(s != INVALID_SOCKET) { bind(s, (sockaddr*)&sin, sizeof(sin)); if(listen(s, SOMAXCONN) != SOCKET_ERROR) { int add_len = sizeof(sin); while(ConnSocket == INVALID_SOCKET) ConnSocket = accept(s, NULL, NULL); MessageBox(0,"ok",0,0); } } return 0; } void ConnectToIP(const char* ip_addr) { if(ConnSocket == INVALID_SOCKET) { DWORD exit_code = 0; GetExitCodeThread(ListeningThread, &exit_code); if(exit_code == STILL_ACTIVE) { sockaddr_in sin; ZeroMemory(&sin, sizeof(sockaddr_in)); sin.sin_addr.s_addr = inet_addr(ip_addr); sin.sin_family = AF_INET; sin.sin_port = htons(NET_DEFAULTPORT); SOCKET s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); if(s != INVALID_SOCKET) { int err = connect(s, (sockaddr*)&sin, sizeof(sin)); if(err != SOCKET_ERROR) { ConnSocket = s; TerminateThread(ListeningThread, 0); } } } } } void Initialize( ) { WSADATA data; WSAStartup(MAKEWORD(1,1), &data); ListeningThread = CreateThread(0, 0, ListeningThreadProc, 0, 0, 0); } }; All return values are fine so I assume that accept() is failing, is the fact that I am under a router the explication to all of this ? Thanks. PS: Further info. The value returned by GetLastError() tells me that the connection timed out. Any idea why this could happen ? (error code 10060 if you want to see for yourself). [Edited by - White Scorpion on May 16, 2006 9:15:18 PM]
  6. White Scorpion

    Framed bitmaps

    Ahah... wow thanks guys. I effectively forgot to call CreateSprite with the correct parameters. I must admit that I was pretty tired but hey *smashes head on computer desk*. Now the correct animation is displayed but the animation slides through the different frames instead of just skipping to the next frame :\ What could cause this ? I will try to use a debugger but if you wish to see what I mean I can give you more code to compile or simply host an executable file but that's never a good idea. Thanks for the info again, I will try to solve it but if you have an idea, don't be shy ;-) *Edit* After further verifications with the debugger, it seems that everything is going fine : [Edited by - White Scorpion on January 6, 2006 12:27:55 PM]
  7. White Scorpion

    Framed bitmaps

    Hey guys. I am currently finishing writing a small class to take care of framed bitmaps for my project and there seems to be a weird bug. I want my application, as a test, to display the first 5 frames of a framed image indefinitely. What the application does, though, is simply show me the whole bitmap (all frames) and even when it's redrawn it always redraw the whole bitmap. I have rewritten most of the code related to frames yet it seems that there is still an error I haven't. Since it was too hard to understand my code I also added a little bit of comments which will surely help you guys help me find what's wrong. I'll provide you guys with as less code as possible, since there is already code I have tested and know works. Here's how it goes: /////////////////////////////////////////////////////////// // // // Bitmap rendering module // // // /////////////////////////////////////////////////////////// class Bitmap { public: Bitmap(); ~Bitmap(); virtual void Create(HDC, const char*, int x = 0, int y = 0); virtual void Render(HDC); virtual void Update(); inline bool& Visible() { return is_visible;} inline bool& IsMasked() { return is_masked; } inline COLORREF& Mask() { return mask; } inline int& Width() { return w; } inline int& Height() { return h; } inline POINT& Position() { return pos; } inline Bitmap& operator = (const Bitmap&); protected: HDC mem_dc; HBITMAP old_bmp; POINT pos; int w; int h; bool is_visible; bool is_masked; COLORREF mask; BITMAP bmp_info; }; class Sprite : public Bitmap { public: Sprite(); void CreateSprite(HDC, const char*, int x = 0, int y = 0, int nfx = 1, int nfy = 1); void Render(HDC); void Update(); inline bool& IsMoving() { return is_moving; } inline bool& IsAccel() { return is_accel; } inline float& MaxSpeed() { return max_speed; } inline int& Num_Frames_Used() { return num_frames_used; } // starting index of the first frame inline int& X_Index() { return index_x; } inline int& Y_Index() { return index_y; } protected: Vec_2D speed; Vec_2D accel; int num_frames_used; // total number of frame per axis int num_frames_x; int num_frames_y; // size of each frame int frame_w; int frame_h; // starting index of the first frame int index_x; int index_y; float max_speed; bool is_moving; bool is_accel; }; /////////////////////////////////////////////////////////// // // // Bitmap rendering module // // // /////////////////////////////////////////////////////////// /* ============ Bitmap class ============ */ Bitmap::Bitmap() : w(0), h(0), is_visible(false), is_masked(false) { /* empty */ } Bitmap::~Bitmap() { /* irrelevant code */ } void Bitmap::Create(HDC hdc, const char* file_name, int x, int y) { /* tested and works */ } void Bitmap::Render(HDC hdc) { /* irrelevant code */} void Bitmap::Update() { /* empty */ } Bitmap& Bitmap::operator = (const Bitmap& b) { /* irrelevant code */ } /* ============ Sprite class ============ */ Sprite::Sprite() : accel(1,1) { is_moving = false; is_accel = false; max_speed = 0; index_x = 0; index_y = 0; num_frames_used = 1; } void Sprite::CreateSprite(HDC hdc, const char* file_name, int x, int y, int nfx, int nfy) { Create(hdc, file_name, x, y); num_frames_x = nfx; num_frames_y = nfy; frame_w = w / num_frames_x; frame_h = h / num_frames_y; } void Sprite::Render(HDC hdc) { if(is_moving) { Update(); } if(is_visible) { // counter that counts how many frames were // displayed since the last reset static int frame_count = 0; // index of the current frame to be displayed static int cur_x_frame = index_x; static int cur_y_frame = index_y; // location of the current frame to be displayed int x = cur_x_frame * frame_w; int y = cur_y_frame * frame_h; // Blit to the screen if(is_masked) { ::TransparentBlt(hdc, pos.x, pos.y, frame_w, frame_h, mem_dc, x, y, frame_w, frame_h, mask); } else { ::BitBlt(hdc, pos.x, pos.y, frame_w, frame_h, mem_dc, x, y, SRCCOPY); } // if we reached the end of the row but we still // aren't in the last column allowed if(++cur_x_frame >= num_frames_x && !(cur_y_frame >= num_frames_y)) { // start from left and one step lower cur_x_frame = 0; cur_y_frame++; } // if we reached the last frame yet the counter // didn't burst or if the counter bursts if((cur_x_frame + (cur_y_frame * cur_x_frame)) >= num_frames_used || ++frame_count >= num_frames_used) { // reset both indices and the frame count cur_x_frame = index_x; cur_y_frame = index_y; frame_count = 0; } } } void Sprite::Update() { /* irrelevant code */ } *PS: Sorry if a little bit of the indentation is off, it went wrong while copying it to the forums. Thanks.
  8. White Scorpion

    TabControl class

    I have somewhat spotted the error. I removed the code relative to the subclassing and it solved the problem; therefore, I simply decided not to subclass it since I didn't really have a good reason to do so. If you guys have any idea what was wrong with the subclassing code, though, I'd be very happy to know your opinion.
  9. White Scorpion

    TabControl class

    Well, I tried using WinSpy++ and it tells me that it found the tab control created. What does it mean ? I made sure to use the WS_VISIBLE and WS_CHILD styles and I even tried calling UpdateWindow() to no avail :\
  10. Try not assigning anything to the WNDCLASSEX::lpszMenuName field and just call LoadMenu() and SetMenu().
  11. White Scorpion

    TabControl class

    Here's the WinMain code. That's all I can do right now since the connection I am working on right now is too slow to download programs, I'll download WinSpy when I get back home:#include "core.hpp" #include <windows.h> LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int) { WNDCLASSEX wc = { 0 }; wc.cbSize = sizeof(wc); wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1); wc.hIcon = LoadIcon(0, IDI_WINLOGO); wc.hIconSm = LoadIcon(0, IDI_WINLOGO); wc.hCursor = LoadCursor(0, IDC_ARROW); wc.lpfnWndProc = WndProc; wc.lpszClassName = "blah"; RegisterClassEx(&wc); HWND hwnd = CreateWindow("blah", "", WS_OVERLAPPEDWINDOW, 0, 0, CW_USEDEFAULT, CW_USEDEFAULT, HWND_DESKTOP, 0, 0, 0); UpdateWindow(hwnd); ShowWindow(hwnd, true); MSG msg; while(GetMessage(&msg, 0, 0, 0) > 0) { TranslateMessage(&msg); DispatchMessage(&msg); } return 0; } LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wprm, LPARAM lprm) { static SmartPtr<TabControl> tab; switch(msg) { case WM_CREATE: { ErrorLogger.Create(true); RECT rc = {0, 0, 100, 100}; tab = new TabControl; ErrorLogger.WriteMessage(__FILE__, __LINE__, TL_FATAL, tab != NULL, "Creating first tab"); tab->Create(hwnd, "Tab, whatever", 0, rc); tab->AddTab("blah", 2); } break; case WM_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc(hwnd, msg, wprm, lprm); } return 0; } *Edit* Don't mind the SmartPtr<> class, I know it works as I want it to, I've tested it on dummy classes to make sure that it doesn't bother me later.
  12. White Scorpion

    TabControl class

    Changed it but it still says it succeeded.
  13. White Scorpion

    TabControl class

    Hey guys. I've been working on this project of mine lately yet I have encountered an issue that neither my friends nor myself could solve. I am trying to make a little (nothing too fancy) wrapper for a few controls that I need. My current problem is that when I create and use my TabControl class, it doesn't show the control on the main window. The tab just won't show up, which is quite annoying. I've tried using my error logger class but everything succeeds everywhere so I must have missed something important elsewhere : /////////////////////////////////////////////////////////// // // // Interface module // // // // The interface module regroups many classes that // // represent the different controls used in the // // application. // // /////////////////////////////////////////////////////////// class IControl : public IMMObject { protected: IControl(); virtual ~IControl() { } public: virtual void OnResize() = 0; virtual void OnEnable() = 0; virtual void OnDisable() = 0; public: static HWND hwnd_top_parent; bool enabled; HWND hwnd_self; int control_id; }; class TabControl : public IControl { public: TabControl() { }; void OnResize(); void OnEnable(); void OnDisable(); void Create(HWND, const char*, int, RECT); void Create(HWND, const char*, int, int, int, int, int); void AddTab(LPTSTR, int); protected: struct Parent { Parent() : old_wnd_proc(0) { } std::list<SmartPtr<TabControl> > tab_list; WNDPROC old_wnd_proc; }; static LRESULT CALLBACK SubWndProc(HWND, UINT, WPARAM, LPARAM); static std::map<HWND, Parent> tab_list; RECT display_area; bool active; }; /////////////////////////////////////////////////////////// // // // Interface module // // // /////////////////////////////////////////////////////////// // static variable HWND IControl::hwnd_top_parent; IControl::IControl() : enabled(true) { INITCOMMONCONTROLSEX icc = { 0 }; icc.dwSize = sizeof(icc); icc.dwICC = ICC_TAB_CLASSES; bool err = InitCommonControlsEx(&icc); ErrorLogger.WriteMessage(__FILE__, __LINE__, TL_FATAL, err == true, "Initializing common controls"); } // static variable std::map<HWND, TabControl::Parent> TabControl::tab_list; void TabControl::OnResize() { if(active && enabled) SendMessage(hwnd_self, TCM_ADJUSTRECT, (WPARAM)true, (LPARAM)&display_area); } void TabControl::OnEnable() { // Provided for compatibility with IControl } void TabControl::OnDisable() { // Provided for compatibility with IControl } void TabControl::Create(HWND hwnd, const char* caption, int id, RECT rc) { Parent* p = &tab_list[hwnd]; hwnd_self = CreateWindowEx(0, WC_TABCONTROL, caption, WS_CHILD | WS_VISIBLE, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, hwnd, NULL, GetModuleHandle(0), NULL); ErrorLogger.WriteMessage(__FILE__, __LINE__, TL_WARNING, hwnd_self != INVALID_HANDLE_VALUE, "TabControl handle creation"); p->tab_list.push_back(this); if(p->old_wnd_proc == NULL) { p->old_wnd_proc = (WNDPROC)SetWindowLongPtr(hwnd_self, GWLP_WNDPROC, (LONG_PTR)SubWndProc); ErrorLogger.WriteMessage(__FILE__, __LINE__, TL_WARNING, p != NULL, "TabControl sub-classing operation"); } display_area = rc; } void TabControl::Create(HWND hwnd, const char* caption, int id, int x, int y, int x2, int y2) { RECT rc = { x, y, x2, y2 }; Create(hwnd, caption, id, rc); } void TabControl::AddTab(LPTSTR txt, int id) { TCITEM tci = { 0 }; tci.mask = TCIF_TEXT; tci.pszText = txt; int err = TabCtrl_InsertItem(hwnd_self, id, &tci); ErrorLogger.WriteMessage(__FILE__, __LINE__, TL_WARNING, err != -1, "TabControl adding a tab"); } LRESULT CALLBACK TabControl::SubWndProc(HWND hwnd, UINT msg, WPARAM wprm, LPARAM lprm) { Parent* p = &tab_list[hwnd]; std::list<SmartPtr<TabControl> >::iterator iter; for(iter = p->tab_list.begin(); iter != p->tab_list.end(); iter++) { switch(msg) { case WM_DESTROY: MessageBox(0,0,0,0); break; default: return p->old_wnd_proc(hwnd, msg, wprm, lprm); } } return 0; } Quote:[core.cpp:326] -> Initializing common controls succeeded [main.cpp:54] -> Creating first tab succeeded [core.cpp:372] -> TabControl handle creation succeeded [core.cpp:385] -> TabControl sub-classing operation succeeded [core.cpp:408] -> TabControl adding a tab succeededDo you guys have any idea ? I want to answer it explicitly before anyone asks the odd and obvious question "did you call InitCommonControlsEx()", yes. It may not appear to you guys very easily since it's not that obvious but I placed it in IControl's empty constructor. Many thanks.
  14. Hey guys, I have decided not to use WxWidgets and to program only for Windows. I have a problem, though. When I initialize the common controls, my compiler doesn't recognize InitCommonControlsEx() nor INITCOMMONCONTROLSEX nor ICC_STANDARD_CLASSES but it recognizes ICC_TAB_CLASSES (wonder why :lol: ) which is a little bit disturbing because I include windows.h, commctrl.h and I link comctl32.a. Do you guys have any idea why my compiler bugs me like that ? IControl::IControl() : enabled(true) { INITCOMMONCONTROLSEX icc = { 0 }; icc.dwSize = sizeof(icc); icc.dwICC = ICC_TAB_CLASSES; InitCommonControlsEx(&icc); } A friend solved my problem over MSN by adding "#define _WIN32_IE 0x0300" but could someone explain why and were to find a reference where it says when it is needed to define a value such as this one ? I looked up on MSDN but couldn't find it.
  15. White Scorpion

    WxWidgets

    Hey. I'm currently installing WxWidgets and I am following the install.txt file to guide me. My problem is that when I call make.exe with the command-line parameters as said in the file, I get this error:Quote:c:\wx\build\msw\makefile.gcc:7: config.gcc: No such file or directory make: *** No rule to make target 'config.gcc'. StopUsing this line:Quote:make -f c:\wx\build\msw\makefile.gccThe thing is: I know config.gcc is in the same directory, I double-checked. Do you guys know what's wrong ? I'm using Dev-Cpp. *I'm sorry, I know it shouldn't be in the Game API sub-forum, but I couldn't find a better place*
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!