鱼C论坛

 找回密码
 立即注册
查看: 2268|回复: 2

directx编程问题

[复制链接]
发表于 2015-12-17 11:58:11 | 显示全部楼层 |阅读模式
18鱼币


编译不通过爆出下面一连串错误求解:dizzy:

1>MSVCRTD.lib(crtexe.obj) : error LNK2019: 无法解析的外部符号 _main,该符号在函数 ___tmainCRTStartup 中被引用
1>D:\visual studio sdk\游戏编程\ConsoleApplication1\Debug\ConsoleApplication1.exe : fatal error LNK1120: 1 个无法解析的外部命令



  1. #include <windows.h>   
  2. #include <windowsx.h>
  3. #include <mmsystem.h>
  4. #include <iostream>
  5. #include <conio.h>
  6. #include <stdlib.h>
  7. #include <malloc.h>
  8. #include <memory.h>
  9. #include <string.h>
  10. #include <stdarg.h>
  11. #include <stdio.h>
  12. #include <math.h>
  13. #include <io.h>
  14. #include <fcntl.h>

  15. #include <ddraw.h> // include directdraw


  16. using namespace std;


  17. #define WINDOW_CLASS_NAME TEXT("WINCLASS1")


  18. #define SCREEN_WIDTH    640  // size of screen
  19. #define SCREEN_HEIGHT   480
  20. #define SCREEN_BPP      8    // bits per pixel
  21. #define MAX_COLORS      256  // maximum colors

  22. typedef unsigned short USHORT;
  23. typedef unsigned short WORD;
  24. typedef unsigned char  UCHAR;
  25. typedef unsigned char  BYTE;

  26. #define KEYDOWN(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 1 : 0)
  27. #define KEYUP(vk_code)   ((GetAsyncKeyState(vk_code) & 0x8000) ? 0 : 1)

  28. #define DD_INIT_STRUCT(ddstruct) { memset(&ddstruct,0,sizeof(ddstruct)); ddstruct.dwSize=sizeof(ddstruct); }


  29. HWND      main_window_handle = NULL; // globally track main window
  30. HINSTANCE hinstance_app = NULL; // globally track hinstance



  31. LPDIRECTDRAW7         lpdd = NULL;   
  32. LPDIRECTDRAWSURFACE7  lpddsprimary = NULL;   
  33. LPDIRECTDRAWSURFACE7  lpddsback = NULL;   
  34. LPDIRECTDRAWPALETTE   lpddpal = NULL;  
  35. LPDIRECTDRAWCLIPPER   lpddclipper = NULL;  
  36. PALETTEENTRY          palette[256];         
  37. PALETTEENTRY          save_palette[256];     
  38. DDSURFACEDESC2        ddsd;                  
  39. DDBLTFX               ddbltfx;               
  40. DDSCAPS2              ddscaps;               
  41. HRESULT               ddrval;               
  42. DWORD                 start_clock_count = 0;

  43. // these defined the general clipping rectangle
  44. int min_clip_x = 0,                          // clipping rectangle
  45. max_clip_x = SCREEN_WIDTH - 1,
  46. min_clip_y = 0,
  47. max_clip_y = SCREEN_HEIGHT - 1;

  48. // these are overwritten globally by DD_Init()
  49. int screen_width = SCREEN_WIDTH,            // width of screen
  50. screen_height = SCREEN_HEIGHT,           // height of screen
  51. screen_bpp = SCREEN_BPP;              // bits per pixel


  52. char buffer[80];                     // general printing buffer

  53. // FUNCTIONS //////////////////////////////////////////////
  54. LRESULT CALLBACK WindowProc(HWND hwnd,
  55.         UINT msg,
  56.         WPARAM wparam,
  57.         LPARAM lparam)
  58. {
  59.         // this is the main message handler of the system
  60.         PAINTSTRUCT                ps;                // used in WM_PAINT
  61.         HDC                                hdc;        // handle to a device context
  62.         char buffer[80];        // used to print strings

  63.         // what is the message
  64.         switch (msg)
  65.         {
  66.         case WM_CREATE:
  67.         {
  68.                 // do initialization stuff here
  69.                 // return success
  70.                 return(0);
  71.         } break;

  72.         case WM_PAINT:
  73.         {
  74.                 // simply validate the window
  75.                 hdc = BeginPaint(hwnd, &ps);

  76.                 // end painting
  77.                 EndPaint(hwnd, &ps);

  78.                 // return success
  79.                 return(0);
  80.         } break;

  81.         case WM_DESTROY:
  82.         {

  83.                 // kill the application, this sends a WM_QUIT message
  84.                 PostQuitMessage(0);

  85.                 // return success
  86.                 return(0);
  87.         } break;

  88.         default:break;

  89.         } // end switch

  90.         // process any messages that we didn't take care of
  91.         return (DefWindowProc(hwnd, msg, wparam, lparam));

  92. } // end WinProc

  93. ///////////////////////////////////////////////////////////

  94. int Game_Main(void *parms = NULL, int num_parms = 0)
  95. {
  96.         // this is the main loop of the game, do all your processing
  97.         // here

  98.         // for now test if user is hitting ESC and send WM_CLOSE
  99.         if (KEYDOWN(VK_ESCAPE))
  100.                 SendMessage(main_window_handle, WM_CLOSE, 0, 0);

  101.         // return success or failure or your own return code here
  102.         return(1);

  103. } // end Game_Main

  104. ////////////////////////////////////////////////////////////

  105. int Game_Init(void *parms = NULL, int num_parms = 0)
  106. {
  107.         // this is called once after the initial window is created and
  108.         // before the main event loop is entered, do all your initialization
  109.         // here

  110.         // create IDirectDraw interface 7.0 object and test for error
  111.         if (FAILED(DirectDrawCreateEx(NULL, (void **)&lpdd, IID_IDirectDraw7, NULL)))
  112.                 return(0);

  113.         // set cooperation to full screen
  114.         if (FAILED(lpdd->SetCooperativeLevel(main_window_handle,
  115.                 DDSCL_FULLSCREEN | DDSCL_ALLOWMODEX |
  116.                 DDSCL_EXCLUSIVE | DDSCL_ALLOWREBOOT)))
  117.         {
  118.                 // error
  119.                 return(0);
  120.         } // end if

  121.         // set display mode to 640x480x8
  122.         if (FAILED(lpdd->SetDisplayMode(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, 0, 0)))
  123.         {
  124.                 // error
  125.                 return(0);
  126.         } // end if


  127.         // return success or failure or your own return code here
  128.         return(1);

  129. } // end Game_Init

  130. /////////////////////////////////////////////////////////////

  131. int Game_Shutdown(void *parms = NULL, int num_parms = 0)
  132. {
  133.         // this is called after the game is exited and the main event
  134.         // loop while is exited, do all you cleanup and shutdown here

  135.         // simply blow away the IDirectDraw4 interface
  136.         if (lpdd)
  137.         {
  138.                 lpdd->Release();
  139.                 lpdd = NULL;
  140.         } // end if

  141.         // return success or failure or your own return code here
  142.         return(1);

  143. } // end Game_Shutdown

  144. // WINMAIN ////////////////////////////////////////////////
  145. int WINAPI WinMain(HINSTANCE hinstance,
  146.         HINSTANCE hprevinstance,
  147.         LPSTR lpcmdline,
  148.         int ncmdshow)
  149. {

  150.         WNDCLASSEX winclass; // this will hold the class we create
  151.         HWND           hwnd;         // generic window handle
  152.         MSG                   msg;                 // generic message
  153.         HDC        hdc;      // graphics device context

  154.         // first fill in the window class stucture
  155.         winclass.cbSize = sizeof(WNDCLASSEX);
  156.         winclass.style = CS_DBLCLKS | CS_OWNDC |
  157.                 CS_HREDRAW | CS_VREDRAW;
  158.         winclass.lpfnWndProc = WindowProc;
  159.         winclass.cbClsExtra = 0;
  160.         winclass.cbWndExtra = 0;
  161.         winclass.hInstance = hinstance;
  162.         winclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
  163.         winclass.hCursor = LoadCursor(NULL, IDC_ARROW);
  164.         winclass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
  165.         winclass.lpszMenuName = NULL;
  166.         winclass.lpszClassName = WINDOW_CLASS_NAME;
  167.         winclass.hIconSm = LoadIcon(NULL, IDI_APPLICATION);

  168.         // save hinstance in global
  169.         hinstance_app = hinstance;

  170.         // register the window class
  171.         if (!RegisterClassEx(&winclass))
  172.                 return(0);

  173.         // create the window
  174.         if (!(hwnd = CreateWindowEx(NULL,                  // extended style
  175.                 WINDOW_CLASS_NAME,     // class
  176.                 TEXT("DirectDraw Full-Screen Demo"), // title
  177.                 WS_POPUP | WS_VISIBLE,
  178.                 0, 0,          // initial x,y
  179.                 SCREEN_WIDTH, SCREEN_HEIGHT,  // initial width, height
  180.                 NULL,          // handle to parent
  181.                 NULL,          // handle to menu
  182.                 hinstance,// instance of this application
  183.                 NULL)))        // extra creation parms
  184.                 return(0);

  185.         // save main window handle
  186.         main_window_handle = hwnd;

  187.         // initialize game here
  188.         Game_Init();

  189.         // enter main event loop
  190.         while (TRUE)
  191.         {
  192.                 // test if there is a message in queue, if so get it
  193.                 if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
  194.                 {
  195.                         // test if this is a quit
  196.                         if (msg.message == WM_QUIT)
  197.                                 break;

  198.                         // translate any accelerator keys
  199.                         TranslateMessage(&msg);

  200.                         // send the message to the window proc
  201.                         DispatchMessage(&msg);
  202.                 } // end if

  203.                 // main game processing goes here
  204.                 Game_Main();

  205.         } // end while

  206.         // closedown game here
  207.         Game_Shutdown();

  208.         // return to Windows like this
  209.         return(msg.wParam);

  210. }
复制代码

想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2015-12-29 01:25:19 | 显示全部楼层
哈哈 太複雜了
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2015-12-29 16:03:22 | 显示全部楼层
这个要几个文件一起编译的。
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-4-25 02:49

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表