Linking...
Generic.obj : error LNK2001: unresolved external symbol "int __cdecl InitInstance(void *,int)" (?InitInstance@@YAHPAXH@Z)
Generic.obj : error LNK2001: unresolved external symbol "int __cdecl InitApplication(void *)" (?InitApplication@@YAHPAX@Z)
Debug/FirstWin.exe : fatal error LNK1120: 2 unresolved externals
Error executing link.exe.
Creating browse info file...这是创建窗口的基本程序
我一直用Delphi,学VC,在VC创建Win32 Application工程,还不知道这是什么错误.源代码
Generic.h
BOOL InitApplication(HANDLE hInstance);
BOOL InitInstance(HANDLE hInstance,int nCmdShow);
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
LRESULT CALLBACK About(HWND,UINT,WPARAM,LPARAM);Generic.cpp
#include <windows.h>
#include "Generic.h"
#include "resource.h"HINSTANCE _hInst;   //实例句柄
HWND _hWnd;         //窗口句柄char _szAppName[]="Generic";    //程序名称
char _szTitle[]="莫祖繁的窗口";//-----------------------------------------------------------------
// WinMain  - 程序的入口点
//-----------------------------------------------------------------
int CALLBACK WinMain(HINSTANCE hInstance,HINSTANCE hPreInstance,LPSTR lpCmdLine,int nCmdShow)
{
MSG msg;
UNREFERENCED_PARAMETER(lpCmdLine);  //避免编译时警告
if (!hPreInstance) 
if (!InitApplication(hInstance))
return(FALSE); 
if (!InitInstance(hInstance,nCmdShow))
return(FALSE) ;
while (GetMessage(&msg,NULL,0,0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return(msg.wParam); 
}//--------------------------------------------------------------------
// InitApplication - 注册窗口类
//--------------------------------------------------------------------
BOOL InitApplication(HINSTANCE hInstance)
{
WNDCLASS wc;
wc.style=CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc=(WNDPROC) WndProc;  //函数窗口
wc.cbClsExtra=0;                   //not used (should be zero) MSDN
wc.cbWndExtra=0;                   //not used (should be zero) MSDN  
wc.hInstance=hInstance;                          //窗体实例
wc.hIcon=LoadIcon(hInstance,"jjhouricon");       //读取图标
wc.hCursor=LoadCursor(NULL,IDC_ARROW);           //读取光标
wc.hbrBackground=  WHITE_BRUSH;  //GetStockObject(WHITE_BRUSH);      //窗体后台颜色
wc.lpszMenuName="GenericMenu";
wc.lpszClassName = _szAppName;
return (RegisterClass(&wc));
}//--------------------------------------------------------------------
// InitInstance - 产生窗体
//-------------------------------------------------------------------- 
BOOL InitInstance(HINSTANCE hInstance,int nCmdShow)
{
_hInst=hInstance;       //储存为全局变量 _hWnd=CreateWindow(
_szAppName,
_szTitle,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
hInstance,
NULL
);
if (!_hWnd)
return (FALSE);
ShowWindow(_hWnd,nCmdShow);   //显示窗口
UpdateWindow(_hWnd);
return(TRUE); 
}//------------------------------------------------------------
// WndProc - 窗口函数
//------------------------------------------------------------
LRESULT CALLBACK WndProc(HWND hWnd,UINT message,
 WPARAM wParam,LPARAM lParam)
{
int hmId,wmEvent; switch (message) {
case WM_COMMAND:
hmId=LOWORD(wParam);
wmEvent=HIWORD(wParam); switch (hmId){
case IDM_ABOUT:
DialogBox(_hInst,
  "AboutBox",
  hWnd,
  (DLGPROC)About
  );
break;
case IDM_EXIT:
DestroyWindow(hWnd);
break;
default:
return(DefWindowProc(hWnd,message,wParam,lParam));
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return(DefWindowProc(hWnd,message,wParam,lParam));
}
return(0);
}//------------------------------------------------------------
// About - 对话框函数
//------------------------------------------------------------
LRESULT CALLBACK About(HWND hDlg,UINT message,
WPARAM wParam,LPARAM lParam)
{
UNREFERENCED_PARAMETER(lParam);       //避免编译时的警告
switch (message) {
case WM_INITDIALOG:
return (TRUE);
case WM_COMMAND:
if (LOWORD(wParam)==IDOK || LOWORD(wParam)==IDCANCEL) {
EndDialog(hDlg,TRUE);
return(TRUE);        //TRUE 表示我已经处理过这个消息
}
break;
}
return(FALSE);   //False表示我没有处理这个消息
}

解决方案 »

  1.   

    #include <windows.h>
    //#include "resource.h"BOOL InitApplication(HANDLE hInstance);
    BOOL InitInstance(HANDLE hInstance,int nCmdShow);
    LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);HINSTANCE _hInst;   //实例句柄
    HWND _hWnd;         //窗口句柄char _szAppName[]="Generic";    //程序名称
    char _szTitle[]="莫祖繁的窗口";int CALLBACK WinMain(HINSTANCE hInstance,HINSTANCE hPreInstance,LPSTR lpCmdLine,int nCmdShow)
    {
    MSG msg;  
    if (!hPreInstance) 
    if (!InitApplication(hInstance))
    return(FALSE); 
    if (!InitInstance(hInstance,nCmdShow))
    return(FALSE) ;
    while (GetMessage(&msg,NULL,0,0)) {
    TranslateMessage(&msg);
    DispatchMessage(&msg);
    }
    return(msg.wParam); 
    }BOOL InitApplication(HINSTANCE hInstance)
    {
    WNDCLASS wc;
    wc.style=CS_HREDRAW | CS_VREDRAW;
    wc.lpfnWndProc=(WNDPROC) WndProc;  //函数窗口
    wc.cbClsExtra=0;                   //not used (should be zero) MSDN
    wc.cbWndExtra=0;                   //not used (should be zero) MSDN  
    wc.hInstance=hInstance;                          //窗体实例
    wc.hIcon=LoadIcon(hInstance,"jjhouricon");       //读取图标
    wc.hCursor=LoadCursor(NULL,IDC_ARROW);           //读取光标
    wc.hbrBackground=  BLACK_BRUSH;  //GetStockObject(WHITE_BRUSH);      //窗体后台颜色
    wc.lpszMenuName="GenericMenu";
    wc.lpszClassName = _szAppName;
    return (RegisterClass(&wc));
    }BOOL InitInstance(HINSTANCE hInstance,int nCmdShow)
    {
    _hInst=hInstance;       //储存为全局变量 _hWnd=CreateWindow(
    _szAppName,
    _szTitle,
    WS_OVERLAPPEDWINDOW,
    CW_USEDEFAULT,
    CW_USEDEFAULT,
    CW_USEDEFAULT,
    CW_USEDEFAULT,
    NULL,
    NULL,
    hInstance,
    NULL
    );
    if (!_hWnd)
    return (FALSE);
    ShowWindow(_hWnd,nCmdShow);   //显示窗口
    UpdateWindow(_hWnd);
    return(TRUE); 
    }//------------------------------------------------------------
    // WndProc - 窗口函数
    //------------------------------------------------------------
    LRESULT CALLBACK WndProc(HWND hWnd,UINT message,
     WPARAM wParam,LPARAM lParam)
    {
    int hmId,wmEvent; switch (message) {
    case WM_COMMAND:
    hmId=LOWORD(wParam);
    wmEvent=HIWORD(wParam); switch (hmId)
    {
    default:
    return(DefWindowProc(hWnd,message,wParam,lParam));
    }
    break;
    case WM_DESTROY:
    PostQuitMessage(0);
    break;
    default:
    return(DefWindowProc(hWnd,message,wParam,lParam));
    }
    return(0);
    }
      

  2.   

    上面是我完全复制你的代码做的,只是部分,你只要建立一个空的win32 application,然后建立一个.c文件把上面的代码复制进去就可以。不用.h .cpp的形式
      

  3.   

    通过了,谢谢
    但我不是很明白为什么用.CPP就不行