鱼C论坛

 找回密码
 立即注册
查看: 2325|回复: 4

DirectX 8.0 源码报错

[复制链接]
发表于 2020-12-17 16:45:37 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
学一本书《Direct3D中的2D编程》,书中只写理论,没有实验操作步骤。
第一章第一节的源码,就没有通过。

实验配置:
Windows7、DX8_SDK
Cfree5.0,设置了Include和Library目录。源码未通过。
VC++6.0,设置了Include和Library目录。源码未通过。

网上看到DX9相关参考:
“第二步:添加链接所需的库文件,如dxguid.lib、d3d9.lib、d3dx9.lib等,……”

不知是否因为缺少这一步骤?针对DX8和本源码,该如何设置?


  1. //Example1_1
  2. //main.cpp
  3. //Ernest Pazera
  4. //04OCT2001
  5. //TGO-01-C
  6. //Libs: d3d8.lib

  7. #include <windows.h>    //include windows stuff
  8. #include <stdio.h>        //standard input/output
  9. #include "D3D8.h"    //include direct3d8 stuff

  10. //constants
  11.     //window class name
  12.     const char* WINDOWCLASS = "3D42DGP" ;
  13.     //window title
  14.     const char* WINDOWTITLE = "Example 1.1 (TGO-01-C): Creating and Destroying an IDirect3D8 object" ;

  15. //globals
  16.     //instance handle
  17.     HINSTANCE g_hInstance = NULL ;
  18.     //window handle
  19.     HWND g_hWnd = NULL ;
  20.     //IDirect3D8 pointer
  21.     IDirect3D8* g_pd3d = NULL ;

  22. //function prototypes
  23.     //winmain
  24.     int WINAPI WinMain ( HINSTANCE hInstance , HINSTANCE hPrevInstance , LPSTR lpCmdLine , int nShowCmd ) ;
  25.     //window procedure
  26.     LRESULT CALLBACK TheWindowProc ( HWND hWnd , UINT uMsg , WPARAM wParam , LPARAM lParam ) ;
  27.     //initialization
  28.     void Prog_Init ( ) ;
  29.     //clean up
  30.     void Prog_Done ( ) ;


  31. //window procedure
  32. LRESULT CALLBACK TheWindowProc ( HWND hWnd , UINT uMsg , WPARAM wParam , LPARAM lParam )
  33. {
  34.     //which message did we get?
  35.     switch ( uMsg )
  36.     {
  37.     case WM_DESTROY : //window being destroyed
  38.         {
  39.             //quit

  40.             PostQuitMessage ( 0 ) ;

  41.             //message handled, return 0

  42.             return ( 0 ) ;

  43.         } break ;
  44.     default:  //all other messages, send to default handler
  45.         return ( DefWindowProc ( hWnd , uMsg , wParam , lParam ) ) ;
  46.     }
  47. }

  48. //winmain
  49. int WINAPI WinMain ( HINSTANCE hInstance , HINSTANCE hPrevInstance , LPSTR lpCmdLine , int nShowCmd )
  50. {
  51.     //grab instance handle
  52.     g_hInstance = hInstance ;

  53.     //redirect stderr and stdout output
  54.     freopen ( "stderr.txt" , "w" , stderr ) ;
  55.     freopen ( "stdout.txt" , "w" , stdout ) ;

  56.     //fill in window class
  57.     WNDCLASSEX wc ;
  58.     wc.cbClsExtra = 0 ;    //no extra class information
  59.     wc.cbSize = sizeof ( WNDCLASSEX ) ; //size of structure
  60.     wc.cbWndExtra = 0 ;    //no extra window information
  61.     wc.hbrBackground = ( HBRUSH ) GetStockObject ( BLACK_BRUSH ) ;    //black brush
  62.     wc.hCursor = NULL ;    //no cursor
  63.     wc.hIcon = NULL ;    //no icon
  64.     wc.hIconSm = NULL ;    //no small icon
  65.     wc.hInstance = g_hInstance ;    //instance handle
  66.     wc.lpfnWndProc = TheWindowProc ;    //window procedure
  67.     wc.lpszClassName = WINDOWCLASS ;    //name of class
  68.     wc.lpszMenuName = NULL ;    //no menu
  69.     wc.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS | CS_OWNDC ;    //class styles

  70.     //register window class
  71.     RegisterClassEx ( &wc ) ;

  72.     //create window
  73.     g_hWnd = CreateWindowEx ( 0 , WINDOWCLASS , WINDOWTITLE , WS_OVERLAPPEDWINDOW , 0 , 0 , 320 , 240 , NULL , NULL , g_hInstance , NULL ) ;

  74.     //show the window
  75.     ShowWindow ( g_hWnd , nShowCmd ) ;

  76.     //initialization
  77.     Prog_Init ( ) ;

  78.     MSG msg ;
  79.     //message pump
  80.     for ( ; ; )
  81.     {
  82.         //check for a message
  83.         if ( PeekMessage( &msg , NULL , 0 , 0 , PM_REMOVE ) )
  84.         {
  85.             //message exists

  86.             //check for quit message
  87.             if ( msg.message == WM_QUIT ) break ;

  88.             //translate the message
  89.             TranslateMessage ( &msg ) ;

  90.             //dispatch the message
  91.             DispatchMessage ( &msg ) ;
  92.         }
  93.     }

  94.     //clean up
  95.     Prog_Done ( ) ;

  96.     //exit
  97.     return ( msg.wParam ) ;
  98. }

  99. //initialization
  100. void Prog_Init ( )
  101. {
  102.     //create the IDirect3D8 object
  103.     g_pd3d = Direct3DCreate8 ( D3D_SDK_VERSION ) ;

  104.     //error check
  105.     if ( g_pd3d )
  106.     {
  107.         //success
  108.         fprintf ( stdout , "IDirect3D8 object created successfully.\n" ) ;
  109.     }
  110.     else
  111.     {
  112.         //failure
  113.         fprintf ( stderr , "IDirect3D8 object creation failed.\n" ) ;
  114.     }
  115. }

  116. //clean up
  117. void Prog_Done ( )
  118. {
  119.     //safe release of IDirect3D8 object
  120.     if ( g_pd3d )
  121.     {
  122.         //release
  123.         g_pd3d->Release ( ) ;

  124.         //set to null
  125.         g_pd3d = NULL ;

  126.         //report action
  127.         fprintf ( stdout , "IDirect3D8 object released.\n" ) ;
  128.     }
  129. }
复制代码


小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2020-12-18 08:59:31 | 显示全部楼层
错误信息呢?
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-12-18 09:05:21 | 显示全部楼层
如果是链接错误,请指定链接库文件

#pragma comment(lib,"D3D8.lib")
#pragma comment(lib,"D3DX8.lib")
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2020-12-18 10:56:57 | 显示全部楼层

CFree5.0报错信息:

--------------------配置: mingw5 - GUI Debug, 编译器类型: MinGW--------------------

检查文件依赖性...
正在连接...
[Error] E:\Direct2D\chap01\Example01_1\main.cpp:127: undefined reference to `Direct3DCreate8@4'
[Error] collect2: ld returned 1 exit status

构建中止 main: 2 个错误, 0 个警告
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-12-18 12:03:44 | 显示全部楼层
如果是链接错误,请指定链接库文件


  1. #pragma comment(lib,"D3D8.lib")
  2. #pragma comment(lib,"D3DX8.lib")
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-5-8 02:44

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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