1

我有这堂课:

#pragma once

#ifndef _DEFINES_H_
#include "Defines.h"
#endif
#ifndef _GAMETIME_H_
#include "GameTime.h"
#endif
#ifndef _UTILITIES_H_
#include "Utilities.h"
#endif

#ifndef _GAME_H_

using namespace System;

namespace BSGameFramework
{
public ref class Game
{
    public:

        Game();
        virtual ~Game();

        void Run(HINSTANCE instance);

        string Title;
        int WindowWidth;
        int WindowHeight;

    protected:

        virtual void Initialize();
        virtual void LoadContent();
        virtual void UnloadContent();
        virtual void Update(GameTime^ gameTime);
        virtual void Draw(GameTime^ gameTime);

    private:

        HINSTANCE windowHandler;
        HWND window;
        DateTime lastTime;
        TimeSpan totalGameTime;

        D3D_DRIVER_TYPE driverType_;
        D3D_FEATURE_LEVEL featureLevel_;

        ID3D11Device* d3dDevice_;
        ID3D11DeviceContext* d3dContext_;
        IDXGISwapChain* swapChain_;
        ID3D11RenderTargetView* backBufferTarget_;

        void Shutdown();
};
}

#define _GAME_H_

#endif

这是它的孩子:

#pragma once

using namespace BSGameFramework;

public ref class MyGame : Game
{
public:

    MyGame()
    {

    }
};

然后在我的 Main 我调用我的 Run 函数:

#include <Windows.h>
#include "MyGame.h"

using namespace BSGameFramework;

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
MyGame ^game = gcnew MyGame();

game->Run(hInstance); // Here the error
}

我收到此错误:

Error   1   error C3767: 'BSGameFramework::Game::Run': candidate function(s) not accessible
C:\Users\Nicola\Desktop\directx prove\BSGameFramework\FrameworkTestCpp\Main.cpp 10  1   FrameworkTestCpp

我试图从运行参数中删除 HINSTANCE 并且一切正常,但我需要它以便有人可以解释我为什么会收到此错误以及如何解决?提前致谢!

4

1 回答 1

1

我以这种方式解决了:

inline void Game::Run(IntPtr instance)
{
windowHandler = (HINSTANCE)instance.ToPointer();


// other code
}

现在我正在传递一个不是本机类型的 IntPtr,所以在主函数上我有这个:

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
MyGame ^game = gcnew MyGame();

IntPtr instance(hInstance);

game->Run(instance);
}
于 2014-01-05T16:15:37.693 回答