|
-
Jun 21st, 2001, 01:48 PM
#1
Thread Starter
Hyperactive Member
once again illegal operation
Code:
#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;
}
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 problem
Matt 
-
Jun 21st, 2001, 02:38 PM
#2
What type of error is it? (e.g: Invalid Page fault). Press the "Details" button to get this information.
-
Jun 21st, 2001, 03:43 PM
#3
Frenzied Member
Hmm I had a bunch of problems with your code. I am not sure how you got some of it to run, or if it did, but here are the changes I had to make to get it to work
You were taking control of WM_COMMAND and not returning a default for those things that you did not need to control.
PHP Code:
case WM_COMMAND:
if(LOWORD(wParam) == BN_CLICKED && (HWND)lParam == button)
{
cpyfile();
}
else
return DefWindowProc(hwnd, msg, wParam, lParam);
I also had to remove your windows name pointers in CreateWindow.
PHP Code:
editbx1 = CreateWindow("Edit",NULL/*"Enter File here"*/, WS_CHILD | WS_VISIBLE |WS_BORDER,120,150,240,40,hwnd,NULL,(HINSTANCE)hInstance,NULL);
editbx2 = CreateWindow("Edit",NULL/*"Enter destination here"*/, WS_CHILD | WS_VISIBLE| WS_BORDER,120,200,240,40,hwnd,NULL,hInstance,NULL);
As for you file copy, you need to add 1 to your lenght because you are not getting the entire string.
PHP Code:
int len = GetWindowTextLength(editbx1);
TCHAR *pcbuf = new TCHAR[len + 2];
GetWindowText(editbx1, pcbuf,len+1);
int len2 = GetWindowTextLength(editbx2);
TCHAR *buf = new TCHAR[len2 + 2];
GetWindowText(editbx2, buf,len2+1);
valofcpyfile = CopyFile(pcbuf,buf,FALSE);
MSVS 6, .NET & .NET 2003 Pro
I HATE MSDN with .NET & .NET 2003!!!
Check out my sites:
http://www.filthyhands.com
http://www.techno-coding.com

-
Jun 21st, 2001, 08:19 PM
#4
Thread Starter
Hyperactive Member
I finally solved the problem, thanks anyway guys!
Matt 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|