VC6 在XP系统,可以编译源文件(compile),却不能执行exe文件(build),是怎么回事呢?俺本来是从事硬件设计的,最近才兴趣用API编程,望高手们不吝赐教.源程序如下:
#include <windows.h>
LPCTSTR lpszAppName=TEXT("MyApp"); LPCTSTR lpszTitle=TEXT("My Application");
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
HINSTANCE hInstance;
int APIENTRY WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow) { MSG msg; HWND hwnd; WNDCLASS wc;
wc.style=CS_HREDRAW|CS_VREDRAW; wc.lpfnWndProc=(WNDPROC)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(GetStockObject(WHITE_BRUSH)); wc.lpszMenuName=NULL; wc.lpszClassName=lpszAppName;
RegisterClass(&wc);
hwnd=CreateWindow( lpszAppName, lpszTitle, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL );
ShowWindow(hwnd,nCmdShow); UpdateWindow(hwnd); while (GetMessage(&msg,NULL,0,0)) { TranslateMessage(&msg); DispatchMessage(&msg); }
return msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam) { char MsgLBTN[]="L botton"; char MsgRBTN[]="R botton"; switch (message) { case WM_RBUTTONDOWN: MessageBeep(MB_ICONINFORMATION); MessageBox(GetFocus(),MsgRBTN,"Message",MB_OK|MB_ICONINFORMATION); break;
case WM_LBUTTONDOWN: MessageBeep(MB_ICONINFORMATION); MessageBox(GetFocus(),MsgLBTN,"Message",MB_OK|MB_ICONINFORMATION); break;
case WM_DESTROY: PostQuitMessage(0); break;
default: DefWindowProc(hwnd,message,wParam,lParam);
}
return 0;
}
上面源码只是要实现简单的界面,当有鼠标按键按下时出现提示框并喇叭会叫一下.
在VC6.0中建立工程,将源文件命名为a.cpp,执行compile,出现以后提示:
--------------------Configuration: a - Win32 Debug-------------------- Compiling... a.cpp
a.obj - 0 error(s), 0 warning(s)
再执行build a.exe,却出现:
--------------------Configuration: a - Win32 Debug-------------------- Linking... LINK : fatal error LNK1168: cannot open Debug/a.exe for writing Error executing link.exe.
a.exe - 1 error(s), 0 warning(s)
在工程的文件夹下有一debug文件夹,之中有一个名为a的无后缀文件.
请问是什么原因使得不能执行程序呢? 奇怪的是,我记得以前也曾编译类似的源文件,但没有问题(操作系统重装过几个不同版本了),但在一段时间后莫名其妙就这样不能执行程序了.
|