我是初学者,遇到了问题请帮忙!

shgciom 2002-03-22 09:48:57
程序是最简单的helloword程序,我就使用的csdn的首页上的文档的No MFC Only API里面的例子;以前自己也敲进去一个但是出现同样的错误:

Linking...
LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Debug/demo1.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.

demo1.exe - 2 error(s), 0 warning(s)

我实在找不出怎么解决!所以专程请教!
...全文
49 16 打赏 收藏 转发到动态 举报
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
shgciom 2002-04-16
  • 打赏
  • 举报
回复
问题还没解决!
RegisterClassEx(&winclass);
一句返回为0;
不知道怎么回事?
shgciom 2002-03-22
  • 打赏
  • 举报
回复
cxiaobao(风子) :同样还是不显示窗口!???
cxiaobao 2002-03-22
  • 打赏
  • 举报
回复
看看你这里:
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
return (msg.wParam);
^^^^^^^^-^^^^^^^^^^^^
|---------------->程序运行一下子就结束了。
}
改为:
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return (msg.wParam);

shgciom 2002-03-22
  • 打赏
  • 举报
回复
我为什么生成不了窗口?
shgciom 2002-03-22
  • 打赏
  • 举报
回复
iamknight(侠客) :link里面已经是了!

kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /incremental:yes /pdb:"Debug/DEMO2_1.pdb" /debug /machine:I386 /out:"Debug/DEMO2_1.exe" /pdbtype:sept
shgciom 2002-03-22
  • 打赏
  • 举报
回复
zjp009(高手) :我用WIZARD生成一个,调试的时候发现if(!hWnd)一句返回的为0,我前面的程序就使返回1,不知道怎么回事!
iamknight 2002-03-22
  • 打赏
  • 举报
回复
工程设置不对。

project ->setting :

link->project options
修改
/subsystem:console 为 /subsystem:windows
shgciom 2002-03-22
  • 打赏
  • 举报
回复
现在不显示错了,就是不出现窗口!
iamknight 2002-03-22
  • 打赏
  • 举报
回复
把主函数改为 void main()
shgciom 2002-03-22
  • 打赏
  • 举报
回复
#define WIN32_LEAN_AND_MEAN

#include <windows.h>
#include <windowsx.h>
#include <windows.h>
//#include <stdafx.h>
#include <stdio.h>
#include <math.h>

#define WINDOW_CLASS_NAME "WINCLASS1"
//globals

//functions
//--------------------
LRESULT CALLBACK WindowProc(HWND hwnd,
UINT msg,
WPARAM wparam,
LPARAM lparam)
{

//系统信息句柄
PAINTSTRUCT ps;
HDC hdc;
//What is the message?
switch(msg)
{
case WM_CREATE:
{
return(0);
}break;
case WM_PAINT:
{
hdc=BeginPaint(hwnd,&ps);

EndPaint(hwnd,&ps);
return(0);
}break;
case WM_DESTROY:
{
PostQuitMessage(0);

return(0);
}break;
default :{
return (0);
//return RegisterClassEx(&winclass);
//return hwnd;
return DefWindowProc(hwnd, msg, wparam, lparam);
}break;
}
}
//--------------------
//winmain函数

int WINAPI WinMain(HINSTANCE hinstance,
HINSTANCE hprevinstance,
LPSTR lpcmdline,
int ncmdshow)
{
//定义WNDCLASSEX类对象;
WNDCLASSEX winclass;
//定义窗口句柄
HWND hwnd;
//定义消息
MSG msg;

winclass.cbSize=sizeof(WNDCLASSEX);
winclass.style=CS_DBLCLKS|CS_OWNDC|CS_HREDRAW|CS_VREDRAW;
//winclass.style=CS_HREDRAW | CS_VREDRAW;
winclass.lpfnWndProc=WindowProc;
winclass.cbClsExtra=0;
winclass.cbWndExtra=0;
winclass.hInstance=hinstance;
winclass.hIcon=LoadIcon(NULL,IDI_APPLICATION);
winclass.hCursor=LoadCursor(NULL,IDC_ARROW);
winclass.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
//winclass.hbrBackground=GetStockObject(BLACK_BRUSH);
winclass.lpszMenuName=NULL;
winclass.lpszClassName=WINDOW_CLASS_NAME;
winclass.hIconSm=LoadIcon(NULL,IDI_APPLICATION);

RegisterClassEx(&winclass);
if(!RegisterClassEx(&winclass))
return(0);

//if(!(hwnd=

// MessageBox(NULL,"there can be only one!!",
// "my first windwos program",
// MB_OK|MB_ICONEXCLAMATION);
// return(0);
//creat the window
// TCHAR szWindowClass[MAX_LOADSTRING];

hwnd=CreateWindowEx(0,//NULL,
//NDOW_CLASS_NAME,
"WINCLASS",
"your basic windwo",
WS_OVERLAPPEDWINDOW,//WS_OVERLAPPEDWINDOW|WS_VISIBLE,
50,50,//x,y
400,400,//width,high
NULL,
NULL,
hinstance,
//winclass,
NULL);
ShowWindow(hwnd,ncmdshow);
UpdateWindow(hwnd);
if(!hwnd)
{
//ShowWindow(hwnd,ncmdshow);
return (0);
}
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
return (msg.wParam);
}
return (0);
}
谢谢!
dancetime 2002-03-22
  • 打赏
  • 举报
回复
把你的整个程序的代码贴出来看看撒。
cxiaobao 2002-03-22
  • 打赏
  • 举报
回复
工程类型不对。选console->empty project.然后敲自己的代码(just like Trubo C)。
zjp009 2002-03-22
  • 打赏
  • 举报
回复
可以用WIZARD直接生成你要的HELLO WORLD程序啊,
然后看看你错在那里。
zjp009 2002-03-22
  • 打赏
  • 举报
回复
建立一个工程(选择WIN32 APPLICATION),然后加入你的CPP文件。
clouds_wang 2002-03-22
  • 打赏
  • 举报
回复
没有定义main()入口函数
zhuwenzheng 2002-03-22
  • 打赏
  • 举报
回复
save as *.cpp,and compile it again

1,650

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 非技术类
社区管理员
  • 非技术类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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