Ejemplo n.º 1
0
LPTA_RESULT LptaRenderer::CreateDevice(std::string api)
{
    if (api == "Direct3D") {
        dllHandle = LoadLibrary(L"LaputaD3D.dll");
        if (!dllHandle) {
            MessageBox(NULL, L"Loading LaputaD3D.dll failed.", L"LaputaEngine - error", 
                       MB_OK | MB_ICONERROR);
            return LPTA_RDR_FAIL;
        }
    }
    else {
        std::wstringstream ss;
        ss << "API " << api.c_str() << " not supported";
        MessageBox(NULL, ss.str().c_str(), L"LaputaEngine - error",
                   MB_OK | MB_ICONERROR);
        return LPTA_RDR_FAIL;
    }
    
    CREATERENDERDEVICE _CreateRenderDevice = 0;
    HRESULT hr;

    _CreateRenderDevice = (CREATERENDERDEVICE)GetProcAddress(dllHandle, "CreateRenderDevice");
    
    if (!_CreateRenderDevice) {
        LPVOID errorMessage;
        FormatMessage(
            FORMAT_MESSAGE_ALLOCATE_BUFFER |
            FORMAT_MESSAGE_FROM_SYSTEM |
            FORMAT_MESSAGE_IGNORE_INSERTS,
            NULL,
            GetLastError(),
            0, // Default language
            (LPWSTR) &errorMessage,
            0,
            NULL
            );
        MessageBox(NULL, (LPWSTR) errorMessage, L"LaputaEngine - error", MB_OK | MB_ICONERROR);
        return LPTA_RDR_FAIL;
    }

    hr = _CreateRenderDevice(dllHandle, renderDevice);
    if (FAILED(hr)) {
        MessageBox(NULL, L"CreateRenderDevice() from lib failed.", L"LaputaEngine - error", MB_OK | MB_ICONERROR);
        renderDevice = NULL;
        return LPTA_RDR_FAIL;
    }
    return LPTA_OK;
}
Ejemplo n.º 2
0
AI_RESULT nAhmadENGINE::createRenderDevice( const c8 *deviceName )
{
	typedef AI_RESULT ( *CREATERENDERDEVICE )( HINSTANCE, Video::IRenderDevice **, IAhmadENGINE * );

	if (strcmp(deviceName, "Direct3D") == 0)
	{
        m_hDLL = LoadLibrary("renderD3D.dll");
		if (!m_hDLL)
		{
			Platform::IForms::AlertOK( "nAhmadENGINE::CreateDevice(): Error loading library.", "ERROR" );
			return AI_FAIL;
		}
	}
	else
	{
		Platform::IForms::AlertOK( "nAhmadENGINE::CreateDevice(): Rendering API not supported.", "ERROR" );
		return AI_FAIL;
	}

	CREATERENDERDEVICE _CreateRenderDevice = 0;
	HRESULT hr = 0;
	
	_CreateRenderDevice = (CREATERENDERDEVICE)GetProcAddress(m_hDLL, "CreateRenderDevice");
	if (!_CreateRenderDevice)
	{
		MessageBox(0, "nAhmadENGINE::CreateDevice(): Error sniffing library.", "ERROR", MB_OK | MB_ICONERROR);
		return E_FAIL;
	}

	hr = _CreateRenderDevice(m_hDLL, &m_pDevice, this);
	if (FAILED(hr))
	{
		MessageBox(0, "nAhmadENGINE::CreateDevice(): Device creation error.", "ERROR", MB_OK | MB_ICONERROR);
		m_pDevice = NULL;
		return E_FAIL;
	}

	return S_OK;
}