Well this time in this illegal operation I ge thte error before the program even starts. I've looked this code over countless times and can't find the problemCode:#include <windows.h> HWND button; HWND editbx1; HWND editbx2; int cpyfile(); const char g_szClassName[] = "mywindowclass"; LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { switch(msg) { case WM_COMMAND: if(LOWORD(wParam) == BN_CLICKED && (HWND)lParam == button){ cpyfile(); } case WM_CLOSE: DestroyWindow(hwnd); break; case WM_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc(hwnd, msg, wParam, lParam); } return 0; } int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { WNDCLASSEX wc; HWND hwnd; MSG Msg; wc.cbSize = sizeof(WNDCLASSEX); wc.style = 0; wc.lpfnWndProc = WndProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = hInstance; wc.hIcon = LoadIcon(NULL, IDI_APPLICATION); wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+5); wc.lpszMenuName = NULL; wc.lpszClassName = g_szClassName; wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION); if(!RegisterClassEx(&wc)) { MessageBox(NULL, "Cannot register window","Error creating window", MB_OK); return 0; } hwnd = CreateWindowEx(WS_EX_CLIENTEDGE,g_szClassName, "Parse string",WS_OVERLAPPEDWINDOW, 150,40,400,500,NULL,NULL, hInstance,NULL); button = CreateWindow("Button","name",WS_CHILD | WS_VISIBLE,150,50,100,40,hwnd,NULL,hInstance,NULL); editbx1 = CreateWindow("Edit","Enter File here", WS_CHILD | WS_VISIBLE |WS_BORDER,120,150,240,40,hwnd,NULL,hInstance,NULL); editbx2 = CreateWindow("Edit","Enter destination here", WS_CHILD | WS_VISIBLE| WS_BORDER,120,200,240,40,hwnd,NULL,hInstance,NULL); if(hwnd == NULL) { MessageBox(NULL, "Something is screwed up!", "ERROR", MB_OK); return 0; } ShowWindow(hwnd, nCmdShow); UpdateWindow(hwnd); while(GetMessage(&Msg, NULL, 0,0)) { TranslateMessage(&Msg); DispatchMessage(&Msg); } return Msg.wParam; } int cpyfile() { BOOL valofcpyfile; int len = GetWindowTextLength(editbx1); TCHAR *pcbuf = new TCHAR[len + 1]; GetWindowText(editbx1, pcbuf,len); int len2 = GetWindowTextLength(editbx2); TCHAR *buf = new TCHAR[len2 + 1]; GetWindowText(editbx2, buf,len2); valofcpyfile = CopyFile(pcbuf,buf,FALSE); if(valofcpyfile==0){ MessageBox(NULL,"Error","Error",MB_OK); } delete [] pcbuf; delete [] buf; return 0; }![]()





Reply With Quote