一个有关error LNK2001的问题!

zhou80bin 2002-12-11 10:24:04
以下是我的代码
就放在了一个cpp文件中;
#include "windows.h"

HINSTANCE hinst;
HWND hwndMain;

LRESULT CALLBACK MainWndProc(
HWND hwnd, // handle to window
UINT uMsg, // message identifier
WPARAM wParam, // first message parameter
LPARAM lParam) // second message parameter
{

switch (uMsg)
{
case WM_CREATE:
// Initialize the window.
return 0;

case WM_PAINT:
// Paint the window's client area.
return 0;

case WM_SIZE:
// Set the size and position of the window.
return 0;

case WM_DESTROY:
// Clean up window-specific data objects.
return 0;

//
// Process other messages.
//

default:
return DefWindowProc(hwnd, uMsg, wParam, lParam);
}
return 0;
}


int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpszCmdLine, int nCmdShow)
{
MSG msg;
BOOL bRet;
WNDCLASS wc;
UNREFERENCED_PARAMETER(lpszCmdLine);

// Register the window class for the main window.

if (!hPrevInstance)
{
wc.style = 0;
wc.lpfnWndProc = (WNDPROC) MainWndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon((HINSTANCE) NULL,
IDI_APPLICATION);
wc.hCursor = LoadCursor((HINSTANCE) NULL,
IDC_ARROW);
wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
wc.lpszMenuName = "MainMenu";
wc.lpszClassName = "MainWndClass";

if (!RegisterClass(&wc))
return FALSE;
}

hinst = hInstance; // save instance handle

// Create the main window.

hwndMain = CreateWindow("MainWndClass", "Sample",
WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT, (HWND) NULL,
(HMENU) NULL, hinst, (LPVOID) NULL);

// If the main window cannot be created, terminate
// the application.

if (!hwndMain)
return FALSE;

// Show the window and paint its contents.

ShowWindow(hwndMain, nCmdShow);
UpdateWindow(hwndMain);

// Start the message loop.

while( (bRet = GetMessage( &msg, NULL, 0, 0 )) != 0)
{
if (bRet == -1)
{
// handle the error and possibly exit
}
else
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}

// Return the exit code to the system.

return msg.wParam;
}

编译都通过了
可是就是build的时候出错。
Compiling...
testsdk.cpp
Linking...
LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Debug/testsdk.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
Creating browse info file...

testsdk.exe - 2 error(s), 0 warning(s)
我去看msdn里的相关部分,不过还是没弄懂!
...全文
108 13 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
xiaomahui 2002-12-11
  • 打赏
  • 举报
回复
把你的.cpp 改为.c OK.
zswzwy 2002-12-11
  • 打赏
  • 举报
回复
去文档中心看看吧, 那有详细的说明
zhou80bin 2002-12-11
  • 打赏
  • 举报
回复
嗯,知道了!
不好意思,还想问一下!
那么系统帮我创建的default project里面并不会使工程成为win32 application或是win32 console了?
xuwt 2002-12-11
  • 打赏
  • 举报
回复
逍遥子说得对,你建一个Win32 Application 应用工程,建完后,建c++源程序,加如该工程里,在编译云型就可以了
YP2002CN 2002-12-11
  • 打赏
  • 举报
回复
你程序是一窗口運行方式的程序
當然用win32 appli或者mfc appwiz.

Mfc APPWizard[Exe]和Win32 Application生成的EXE并没有不同,这两者生成的都是以窗口方式运行的程序。只是编写MFC程序有大量现成的类库可以使用,而编写Win32 Application不使用类库,直接调用API,对于开发者而言,MFC容易些。
Win32 Console APPlication生成的是以命令行方式运行的程序,有点象DOS程序,但可以调用API函数,不同在DOS运行。NT下有很多这样的程序。Regsvr32.exe就是一个这样的程序。
cbc 2002-12-11
  • 打赏
  • 举报
回复
main or winmain函数:
应该是选择工程类型的时候有错误,因为系统会根据subsystem的选项来决定调用main或winmain作为程序的入口函数,如果是console,会选择main, 否则如果是windows,则选择winmain。所以,如果程序没有main或者winmain的实现部分,就会出现LNK2001.

console工程默认入口是main()函数,而你这里是sdk程序,当然要用win32 application了,不知道这样你能不能明白
zhou80bin 2002-12-11
  • 打赏
  • 举报
回复
楼上的能说的详细一点吗!

cbc(逍遥子) 在win32 application中添加该cpp后可以解决问题!

不过,我想知道为什么!(小弟喜欢知其所以然)

谢谢,各位帮忙!!
nustchenhf 2002-12-11
  • 打赏
  • 举报
回复
remove the symbol _ATL_MIN_CRT from the release configurations you'll use
zhou80bin 2002-12-11
  • 打赏
  • 举报
回复
我就是直接用vc打开了这个cpp文件
工程是它自己创建的(它不是会提示让你把这个cpp加入到一个工程里吗!就是那个工程了)
cbc 2002-12-11
  • 打赏
  • 举报
回复
你用的win32 console工程做的?
改为win32 Application,重建一个工程,就ok了
zhou80bin 2002-12-11
  • 打赏
  • 举报
回复
其实,程序本身是没问题了!!
大家可以不用再意代码,其实就是做个最简单的sdk程序罢了
zhou80bin 2002-12-11
  • 打赏
  • 举报
回复
好了,结贴
zhou80bin 2002-12-11
  • 打赏
  • 举报
回复
我昨天看过文档中心,好像没有啊!

16,548

社区成员

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

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

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