首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

请问:出现非常奇怪的异常,请帮小弟我看看,多谢

2012-02-10 
请教:出现非常奇怪的错误,请各位大哥帮我看看,谢谢!#include windows.h#include stdio.h#includeincl

请教:出现非常奇怪的错误,请各位大哥帮我看看,谢谢!
#include <windows.h>
#include <stdio.h>
#include   "include\hge.h "
#pragma     comment(lib, "lib\\vc\\hge.lib ");                   //库
#pragma     comment(lib, "lib\\vc\\hgehelp.lib ");           //库


int   i;

HGE   *hge   =   0;

//   This   function   will   be   called   by   HGE   once   per   frame.
//   Put   your   game   loop   code   here.   In   this   example   we
//   just   check   whether   ESC   key   has   been   pressed.
bool   FrameFunc()
{
//   By   returning   "true "   we   tell   HGE
//   to   stop   running   the   application.
if   (hge-> Input_GetKeyState(HGEK_ESCAPE))   return   true;

//   Continue   execution
return   false;
}

LONGg_lOldProc   =   NULL;               //全局变量

HRESULT   MyWndProc(   HWND   hWnd,   UINT   nMsg,   WPARAM   wParam,   LPARAM   lParam   )
{
HDC   hdc;
PAINTSTRUCT   ps;
RECT   rect;
char   temp[128];  
switch(   nMsg   )
{
caseWM_RBUTTONDOWN:
{
MessageBox(   hWnd,   "你在我身上点了右键,你想干嘛? ",   "测试 ",   0   );
}
break;
        case   WM_TIMER:
i++;
if   (i%2)
{
  hdc   =   GetDC(hWnd);
                  sprintf(temp, "x:   %d   ,   y:   %d ",50,50);
                  TextOut(hdc,100,100,temp,strlen(temp));
  ReleaseDC(hWnd,hdc);
}
else
{
                    hdc   =   GetDC(hWnd);
                  sprintf(temp, "x:   %d   ,   y:   %d ",60,60);
                  TextOut(hdc,100,100,temp,strlen(temp));
  ReleaseDC(hWnd,hdc);
}
  break   ;
//在这里,   作你想做的事情~~~~~~
}
if(   g_lOldProc   !=   NULL   )
return   CallWindowProc(   (WNDPROC)g_lOldProc,   hWnd,   nMsg,   wParam,   lParam   );//调用原来的窗口处理函数
else
return   DefWindowProc(   hWnd,   nMsg,   wParam,   lParam   );
}

int   WINAPI   WinMain(HINSTANCE,   HINSTANCE,   LPSTR,   int)
{
//   Here   we   use   global   pointer   to   HGE   interface.
//   Instead   you   may   use   hgeCreate()   every
//   time   you   need   access   to   HGE.   Just   be   sure   to
//   have   a   corresponding   hge-> Release()
//   for   each   call   to   hgeCreate()
hge   =   hgeCreate(HGE_VERSION);             //创建   HGE  

//   Set   our   frame   function
hge-> System_SetState(HGE_FRAMEFUNC,   FrameFunc);     //回调函数   FrameFunc



//   Set   the   window   title
hge-> System_SetState(HGE_TITLE,   "HGE   Tutorial   01   -   Minimal   HGE   application ");

//   Run   in   windowed   mode
//   Default   window   size   is   800x600
hge-> System_SetState(HGE_WINDOWED,   true);

//   Don 't   use   BASS   for   sound
hge-> System_SetState(HGE_USESOUND,   false);

//   Tries   to   initiate   HGE   with   the   states   set.
//   If   something   goes   wrong,   "false "   is   returned
//   and   more   specific   description   of   what   have
//   happened   can   be   read   with   System_GetErrorMessage().

     
i=0;
if(hge-> System_Initiate())
{
//   Starts   running   FrameFunc().
//   Note   that   the   execution   "stops "   here
//   until   "true "   is   returned   from   FrameFunc().
HWND   hWnd   =   hge-> System_GetState(   HGE_HWND   );//获得hge的窗口句柄
 
if(hWnd   !=   NULL   )
{
                        SetTimer(hWnd,1,1000,NULL);
g_lOldProc   =   SetWindowLong(   hWnd,   GWL_WNDPROC,   (LONG)MyWndProc   );//设置窗口处理函数为你自己定义的,   并且保存原来的窗口处理函数
}
hge-> System_Start();
}
else
{
//   If   HGE   initialization   failed   show   error   message
MessageBox(NULL,   hge-> System_GetErrorMessage(),   "Error ",   MB_OK   |   MB_ICONERROR   |   MB_APPLMODAL);
}

//   Now   ESC   has   been   pressed   or   the   user
//   has   closed   the   window   by   other   means.

//   Restore   video   mode   and   free
//   all   allocated   resources
hge-> System_Shutdown();

//   Release   the   HGE   interface.
//   If   there   are   no   more   references,
//   the   HGE   object   will   be   deleted.
hge-> Release();

return   0;
}


请教,编译时提示:
--------------------Configuration:   hge_tut01   -   Win32   Debug--------------------
Linking...
hge_tut01.obj   :   error   LNK2001:   unresolved   external   symbol   __imp__TextOutA@20
Debug/hge_tut01.exe   :   fatal   error   LNK1120:   1   unresolved   externals
Error   executing   link.exe.

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


这是什么原因啊?
谢谢!


[解决办法]
包含头文件的时候加extern“C”估计就好了


[解决办法]
#pragma comment(lib, "lib\\vc\\hge.lib "); //库
#pragma comment(lib, "lib\\vc\\hgehelp.lib "); //库

没有对应的 h 文件声明这两个 lib 中的函数原型?

extern“C” 加在函数原型上。

热点排行