为什么会出现这种错误???

dreamup 2004-03-23 12:37:26
编绎能够正常通过,但却无法创建.exe文件。。。。。

提示说:
--------------------Configuration: keyboard - Win32 Debug-----------------
Linking...
LINK : fatal error LNK1168: cannot open Debug/keyboard.exe for writing
Error executing link.exe.

keyboard.exe - 1 error(s), 0 warning(s)

源码如下:

#include"windows.h"
#include"stdlib.h"
#include"string.h"
long WINAPI WndProc
( HWND hWnd,
UINT iMessage,
UINT wParam,
LONG lParam
);
void WINAPI CaretPos(HWND hWnd,int nArrayPos,char *cCharBuf,int *xCaret,int *yCaret,int nCharWidth);
BOOL InitWindowsClass(HINSTANCE hInstance);
BOOL InitWindows(HINSTANCE hInstance, int nCmdShow);
HWND hWndMain;

int WINAPI WinMain
(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow
)
{
MSG Message;
if(! InitWindowsClass(hInstance))
return FALSE;
if( ! InitWindows(hInstance,nCmdShow))
return FALSE;
while(GetMessage(&Message,0,0,0))
{TranslateMessage(&Message);
DispatchMessage(&Message);
}
return Message.wParam;
}
long WINAPI WndProc
(HWND hWnd,
UINT iMessage,
UINT wParam,
LONG lParam)
{
#define BufSize 30
static char cCharBuf[BufSize];
static int nNumChar=0;
static int nArrayPos=0;
static int nLnHeight;
static int nCharWidth;
static int xCaret, yCaret;
int x;
HDC hDC;
TEXTMETRIC tm;
PAINTSTRUCT PtStr;
switch(iMessage)
{
case WM_CHAR:
{ if(wParam==VK_BACK)
{ if(nArrayPos==0)
MessageBox(hWnd, "当前位置是文本的起始位置,不有回退",NULL,MB_OK);
else
{
nArrayPos=nArrayPos-1;
CaretPos(hWnd,nArrayPos,cCharBuf,&xCaret,&yCaret,nCharWidth);
for(x=nArrayPos;x<nNumChar;x=x+1)
cCharBuf[x]=cCharBuf[x+1];
nNumChar=nNumChar-1;
InvalidateRect(hWnd,NULL,TRUE);
}
break;
}
if(wParam==VK_ESCAPE)
{
MessageBox(hWnd,"您现在不能按ESC键,请继续其他操作",NULL,MB_OK);
break;
}

if(nNumChar>=BufSize)
{
MessageBox(hWnd, "缓冲区已满,不能再输入字符了\n若需要删除字符,请用BackSpace键",NULL,MB_OK);
break;
}
for(x=nNumChar;x>nArrayPos;x=x-1)
cCharBuf[x]=cCharBuf[x-1];
cCharBuf[nArrayPos]=(unsigned char)wParam;
nArrayPos=nArrayPos+1;
nNumChar=nNumChar+1;
CaretPos(hWnd,nArrayPos,cCharBuf,&xCaret,&yCaret,nCharWidth);
InvalidateRect(hWnd,NULL,TRUE);
}
break;
case WM_CREATE:
hDC=GetDC(hWnd);
GetTextMetrics(hDC,&tm);
nLnHeight=tm.tmHeight+tm.tmExternalLeading;
nCharWidth=tm.tmAveCharWidth;
yCaret=nLnHeight;
ReleaseDC(hWnd,hDC);
break;
case WM_SETFOCUS:
CreateCaret(hWnd,0,0,nLnHeight);
CaretPos(hWnd,nArrayPos,cCharBuf,&xCaret,&yCaret,nCharWidth);
ShowCaret(hWnd);
break;
case WM_KILLFOCUS:
DestroyCaret();
break;
case WM_KEYDOWN:
switch(wParam)
{
case VK_END:
nArrayPos=nNumChar;
CaretPos(hWnd,nArrayPos,cCharBuf,&xCaret,&yCaret,nCharWidth);
break;
case VK_HOME:
nArrayPos=0;
CaretPos(hWnd,nArrayPos,cCharBuf,&xCaret,&yCaret,nCharWidth);
break;
case VK_DELETE:
if(nArrayPos==nNumChar)
MessageBox(hWnd,"缓冲区已空,没有字符可供删除",NULL,MB_OK);
else
{for(x=nArrayPos;x<nNumChar;x=x+1)
cCharBuf[x]=cCharBuf[x+1];
nNumChar=nNumChar-1;
InvalidateRect(hWnd,NULL,TRUE);
}
break;
case VK_LEFT:
if(nArrayPos>0)
{
nArrayPos=nArrayPos-1;
CaretPos(hWnd,nArrayPos,cCharBuf,&xCaret,&yCaret,nCharWidth);
}
else
MessageBox(hWnd,"您已经移动到起始位置,不能再住前了",NULL,MB_OK);
break;
case VK_RIGHT:
if(nArrayPos<nNumChar)
{
nArrayPos=nArrayPos+1;
CaretPos(hWnd,nArrayPos,cCharBuf,&xCaret,&yCaret,nCharWidth);
}
else
MessageBox(hWnd,"已经到缓冲区末,不能再向右移动了 ",NULL,MB_OK);
break;
}
break;
case WM_PAINT:
hDC=BeginPaint(hWnd,&PtStr);
TextOut(hDC,nCharWidth,nLnHeight,cCharBuf,nNumChar);
EndPaint(hWnd,&PtStr);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return(DefWindowProc(hWnd,iMessage,wParam,lParam));
}
return 0;
}
void WINAPI CaretPos(HWND hWnd, int nArrayPos, char *cCharBuf,int *xCaret,int *yCaret,int nCharWidth)
{
DWORD dWord;

HDC hDC;

hDC=GetDC(hWnd);
ReleaseDC(hWnd,hDC);
*xCaret=LOWORD(dWord)+nCharWidth;
SetCaretPos(*xCaret,*yCaret);
}


BOOL InitWindowsClass(HINSTANCE hInstance)
{
WNDCLASS WndClass;
WndClass.cbClsExtra=0;
WndClass.cbWndExtra=0;
WndClass.hbrBackground=(HBRUSH)(GetStockObject(WHITE_BRUSH));
WndClass.hCursor=LoadCursor(NULL,IDC_ARROW);
WndClass.hIcon=LoadIcon(NULL,"END");
WndClass.hInstance=hInstance;
WndClass.lpfnWndProc=WndProc;
WndClass.lpszClassName="WinKeyboard";
WndClass.lpszMenuName=NULL;
WndClass.style=CS_HREDRAW|CS_VREDRAW;
return RegisterClass(&WndClass);
}

BOOL InitWindows(HINSTANCE hInstance,int nCmdShow)
{
HWND hWnd;
hWnd=CreateWindow("WinKeyboard",
" 键盘操作例程",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
0,
CW_USEDEFAULT,
0,
NULL,
NULL,
hInstance,
NULL);
if(!hWnd)
return FALSE;
hWndMain=hWnd;
ShowWindow(hWnd,nCmdShow);
UpdateWindow(hWnd);
return TRUE;
}
...全文
19 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
wangjs720 2004-03-23
  • 打赏
  • 举报
回复
打开进程管理器,把keyboard结束掉
zhaoriyue 2004-03-23
  • 打赏
  • 举报
回复
LINK : fatal error LNK1168: cannot open Debug/keyboard.exe for writing
如果我没猜错的话,你的程序名就叫keyboard.
这说明你的keyboard.exe正在运行,指上一次运行的那个.
所以它不可写入.只要把它关掉,再链接就不会有问题了!
社会栋梁 2004-03-23
  • 打赏
  • 举报
回复
恩,的确
工程中多了个模块
|External Dependencies
|--basetsd.h
smallbull 2004-03-23
  • 打赏
  • 举报
回复
这段程序可以运行!!!!!!
你应该新建一个空的“Win32 Application”,然后新建一个空的C++ Source File加到项目中,然后把这段代码拷贝到文件中即可编译运行,没问题的。

16,473

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧