C3767:候选功能无法访问

时间:2014-01-05 15:11:08

标签: managed-c++ hinstance

我有这堂课:

 
#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并且一切正常,但我需要它,所以有人可以解释为什么我收到此错误,我该如何解决?提前谢谢!

1 个答案:

答案 0 :(得分:1)

我已经用这种方式解决了:

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


// other code
}

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

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

IntPtr instance(hInstance);

game->Run(instance);
}