游戏开发论坛

 找回密码
 立即注册
搜索
查看: 3476|回复: 14

[问]关于VC

[复制链接]

72

主题

710

帖子

783

积分

高级会员

Rank: 4

积分
783
发表于 2004-9-15 12:48:00 | 显示全部楼层 |阅读模式
第一次用DX

结果就遭到问题了

我是编译一个示例程序

结果出如下错误

Linking...
LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Debug/DX.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.

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


我安装的是最新的DX9 SDK

那个示例程序DX8的

但在下以为应该可以向下兼容吧

很菜的问题但急切求解

谢谢

18

主题

579

帖子

583

积分

高级会员

Rank: 4

积分
583
发表于 2004-9-15 13:05:00 | 显示全部楼层

Re:[问]关于VC

因为DX8用了<iostream.h>现在都是<iostream>了。
在链接选项中用/nodefaultlib:libcd.lib看看能行吗?

72

主题

710

帖子

783

积分

高级会员

Rank: 4

积分
783
 楼主| 发表于 2004-9-15 13:17:00 | 显示全部楼层

Re:[问]关于VC

应该不是.h的问题

要不要都是可以的

添加/nodefaultlib:libcd.lib我试过了

还是不行

不过谢谢阁下了

18

主题

579

帖子

583

积分

高级会员

Rank: 4

积分
583
发表于 2004-9-15 13:54:00 | 显示全部楼层

Re:[问]关于VC

_main是个什么啊?改改能行吗?

72

主题

710

帖子

783

积分

高级会员

Rank: 4

积分
783
 楼主| 发表于 2004-9-15 14:14:00 | 显示全部楼层

Re:[问]关于VC

那个是DX内部的

源码里没有

我放上源码

72

主题

710

帖子

783

积分

高级会员

Rank: 4

积分
783
 楼主| 发表于 2004-9-15 14:15:00 | 显示全部楼层

Re:[问]关于VC

#include <d3d8.h>

LPDIRECT3D8 g_pD3D = NULL;
LPDIRECT3DDEVICE8 g_pD3DDevice = NULL;

HRESULT InitialiseD3D(HWND hWnd)
{
    //First of all, create the main D3D object. If it is created successfully we
    //should get a pointer to an IDirect3D8 interface.
    g_pD3D = Direct3DCreate8(D3D_SDK_VERSION);
    if(g_pD3D == NULL)
    {
        return E_FAIL;
    }

    //Get the current display mode
    D3DDISPLAYMODE d3ddm;
    if(FAILED(g_pD3D->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &d3ddm)))
    {
        return E_FAIL;
    }

    //Create a structure to hold the settings for our device
    D3DPRESENT_PARAMETERS d3dpp;
    ZeroMemory(&d3dpp, sizeof(d3dpp));

    //Fill the structure.
    //We want our program to be windowed, and set the back buffer to a format
    //that matches our current display mode
    d3dpp.Windowed = TRUE;
    d3dpp.SwapEffect = D3DSWAPEFFECT_COPY_VSYNC;
    d3dpp.BackBufferFormat = d3ddm.Format;

    //Create a Direct3D device.
    if(FAILED(g_pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd,
                                   D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp,
                                   &g_pD3DDevice)))
    {
        return E_FAIL;
    }
   
    return S_OK;
}

void Render()
{
    if(g_pD3DDevice == NULL)
    {
        return;
    }

    //Clear the back buffer to a green colour
    g_pD3DDevice->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 255, 0), 1.0f, 0);
   
    //Begin the scene
    g_pD3DDevice->BeginScene();
   
    //Rendering of our game objects will go here
   
    //End the scene
    g_pD3DDevice->EndScene();
   
    //Filp the back and front buffers so that whatever has been rendered on the
    //back buffer will now be visible on screen (front buffer).
    g_pD3DDevice-&gtresent(NULL, NULL, NULL, NULL);
}

void CleanUp()
{
    if(g_pD3DDevice != NULL)
    {
        g_pD3DDevice->Release();
        g_pD3DDevice = NULL;
    }

    if(g_pD3D != NULL)
    {
        g_pD3D->Release();
        g_pD3D = NULL;
    }
}

void GameLoop()
{
    //Enter the game loop
    MSG msg;
    BOOL fMessage;

    PeekMessage(&msg, NULL, 0U, 0U, PM_NOREMOVE);
   
    while(msg.message != WM_QUIT)
    {
        fMessage = PeekMessage(&msg, NULL, 0U, 0U, PM_REMOVE);

        if(fMessage)
        {
            //Process message
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
        else
        {
                //No message to process, so render the current scene
            Render();
        }

    }
}

//The windows message handler
LRESULT WINAPI WinProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
    switch(msg)
    {
        case WM_DESTROY:
            PostQuitMessage(0);
            return 0;
        break;
        case WM_KEYUP:
            switch (wParam)
            {
                case VK_ESCAPE:
                    //User has pressed the escape key, so quit
                    DestroyWindow(hWnd);
                    return 0;
                break;
            }
        break;

    }

    return DefWindowProc(hWnd, msg, wParam, lParam);
}

//Application entry point
INT WINAPI WinMain(HINSTANCE hInst, HINSTANCE, LPSTR, INT)
{
    //Register the window class
    WNDCLASSEX wc = {sizeof(WNDCLASSEX), CS_CLASSDC, WinProc, 0L, 0L,
                     GetModuleHandle(NULL), NULL, NULL, NULL, NULL,
                     "DX Project 1", NULL};
    RegisterClassEx(&wc);

    //Create the application's window
    HWND hWnd = CreateWindow("DX Project 1", "www.andypike.com: Tutorial 1",
                              WS_OVERLAPPEDWINDOW, 50, 50, 500, 500,
                              GetDesktopWindow(), NULL, wc.hInstance, NULL);

    //Initialize Direct3D
    if(SUCCEEDED(InitialiseD3D(hWnd)))
    {
        //Show our window
        ShowWindow(hWnd, SW_SHOWDEFAULT);
        UpdateWindow(hWnd);

        //Start game running: Enter the game loop
        GameLoop();
    }
   
    CleanUp();

    UnregisterClass("DX Project 1", wc.hInstance);
   
    return 0;
}

89

主题

822

帖子

847

积分

高级会员

Rank: 4

积分
847
发表于 2004-9-15 15:34:00 | 显示全部楼层

Re:[问]关于VC

你用了MFC,但编译的时候禁止MFC,或者MFC链接方式不对

28

主题

685

帖子

703

积分

高级会员

Rank: 4

积分
703
发表于 2004-9-15 17:09:00 | 显示全部楼层

Re:[问]关于VC

option->link
  not use console, but window type

18

主题

69

帖子

69

积分

注册会员

Rank: 2

积分
69
QQ
发表于 2004-9-15 17:53:00 | 显示全部楼层

Re:[问]关于VC

55555555,你会用DX,啊,我还不会用~~

72

主题

710

帖子

783

积分

高级会员

Rank: 4

积分
783
 楼主| 发表于 2004-9-15 18:29:00 | 显示全部楼层

Re: Re:[问]关于VC

sevencat: re:[问]关于vc

option->link
  not use console, but window type


果然是这个问题

感谢阁下

也感谢一直帮我出主意的楼上的dkxw大虾

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

本版积分规则

作品发布|文章投稿|广告合作|关于本站|游戏开发论坛 ( 闽ICP备17032699号-3 )

GMT+8, 2025-8-18 16:02

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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