Hi there,
I'm currently working on a framework using static libraries and have hit a problem concerning dialog boxes within static libraries. Basically I have a set up screen to which the user chooses the resolution for the project at startup but when calling the dialog to open I get the error 'The specific resource type cannot be found in the image file'. I've done some searching on google to see if I could find a solution to the problem and the only things I could find where along the lines of the application instance can't be put into the static library... but the issue is that the static library also hold the instance to the application and all code related to the windows side of things, the only part of the program that does work currently is the dialog but I'm unsure what is causing the problem and am hoping someone might be able to help me resolve this issue. The coding for the dialog is as follows:
Within the Application class I make a call to a setup function which creates a new instance of the cSettings class which in turn calls the function to show the dialog, but the dialog return -1 with the message posted above constantly no matter how I try to adjust the code to find the underlying issue.
Please help.
Regards
Dave
I'm currently working on a framework using static libraries and have hit a problem concerning dialog boxes within static libraries. Basically I have a set up screen to which the user chooses the resolution for the project at startup but when calling the dialog to open I get the error 'The specific resource type cannot be found in the image file'. I've done some searching on google to see if I could find a solution to the problem and the only things I could find where along the lines of the application instance can't be put into the static library... but the issue is that the static library also hold the instance to the application and all code related to the windows side of things, the only part of the program that does work currently is the dialog but I'm unsure what is causing the problem and am hoping someone might be able to help me resolve this issue. The coding for the dialog is as follows:
// File cSettings.h #ifndef __CSETTINGS_H__ #define __CSETTINGS_H__ // Includes #include <DXGI.h> #include <tchar.h> #include <vector> #include <string> #include "resource.h" class cSettings{ public: cSettings(); ~cSettings(); void ShowDlg(HINSTANCE hInst); DXGI_MODE_DESC Display(){return m_Display;} BOOL IsFullscreen(){return m_Fullscreen;} BOOL VSyncEnabled(){return m_vSync;} void ConfirmSettings(HWND hWnd); void CleanUp(); BOOL CALLBACK DlgProc(HWND, UINT, WPARAM, LPARAM); // Message processor for the dialog DXGI_ADAPTER_DESC GetAdapterDesc(){return adapterDesc;} std::vector<DXGI_MODE_DESC> GetModes(){return vModes;} HWND GetHandle(){return DlghWnd;} static cSettings* GetSettings() { return m_pSettings; } private: // Private functions void GetAdapters(); void GetOutputs(); void GetDisplayModes(); // Private variables IDXGIAdapter* pAdapter; std::vector<IDXGIAdapter*> vAdapters; std::vector<IDXGIOutput*> vOutputs; std::vector<DXGI_MODE_DESC> vModes; DXGI_ADAPTER_DESC adapterDesc; // contain information of the graphics adapter HWND DlghWnd; // variable of the final settings DXGI_MODE_DESC m_Display; // contain the select width, height and format BOOL m_Fullscreen; // is the app to run in fullscreen BOOL m_vSync; // is VSYNC enabled protected: static cSettings* m_pSettings; }; // Functions inline cSettings* Settings() { return cSettings::GetSettings(); } #endif
// File: cSettings.cpp // Includes #include "stdafx.h" #include "cSettings.h" cSettings* cSettings::m_pSettings = NULL; BOOL CALLBACK DlgProcWrap(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam){ // Check we have a valid main window assert( Settings() ); // if so return the windoow classes wndProc function return Settings()->DlgProc( hDlg, msg, wParam, lParam ); }; cSettings::cSettings(): DlghWnd( NULL ){ if( m_pSettings ) { throw cError(L"Window object already instantiated!\n" ); } m_pSettings = this; ShowDlg(AppInstance()); } cSettings::~cSettings(){ DestroyWindow( DlghWnd ); m_pSettings = NULL; } void cSettings::ShowDlg(HINSTANCE hInst){ GetAdapters(); GetOutputs(); GetDisplayModes(); HRESULT hr = DialogBox(AppInstance(), MAKEINTRESOURCE(IDD_DIALOG1), GetHandle(), reinterpret_cast<DLGPROC>(DlgProcWrap)); DWORD err = GetLastError(); LPVOID lpMsgBuf; FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language (LPTSTR) &lpMsgBuf, 0, NULL); MessageBoxW( NULL, (LPCTSTR)lpMsgBuf, L"Error", MB_OK | MB_ICONINFORMATION ); // Free the buffer. LocalFree( lpMsgBuf ); if( FAILED(hr)){ MessageBox(NULL, L"Problem with Dialog", L"Error", MB_OK); } } void cSettings::GetAdapters(){ IDXGIFactory * pFactory = NULL; CreateDXGIFactory(__uuidof(IDXGIFactory) ,(void**)&pFactory); for (UINT i = 0; pFactory->EnumAdapters(i, &pAdapter) != DXGI_ERROR_NOT_FOUND; ++i){ vAdapters.push_back(pAdapter); } if(pFactory) { pFactory->Release(); } vAdapters[0]->GetDesc(&adapterDesc); } void cSettings::GetOutputs(){ UINT i = 0; IDXGIOutput * pOutput; while(vAdapters[0]->EnumOutputs(i, &pOutput) != DXGI_ERROR_NOT_FOUND) { vOutputs.push_back(pOutput); ++i; } } void cSettings::GetDisplayModes(){ UINT Modes = 0; DXGI_FORMAT format = DXGI_FORMAT_R8G8B8A8_UNORM; // Get the number of elements vOutputs[0]->GetDisplayModeList( format, 0, &Modes, NULL); vModes.resize(Modes); // Get the list vOutputs[0]->GetDisplayModeList( format, 0, &Modes, vModes.data()); } void cSettings::ConfirmSettings(HWND hWnd){ HWND List = GetDlgItem(hWnd, IDC_RESOLUTION); int lbItem = 0; lbItem = SendDlgItemMessage(hWnd, IDC_RESOLUTION, LB_GETCURSEL, 0, 0); this->m_Display = vModes[lbItem]; this->m_Fullscreen = IsDlgButtonChecked(hWnd, IDC_FULLSCREEN ); this->m_vSync = IsDlgButtonChecked(hWnd, IDC_VSYNC ); CleanUp(); } void cSettings::CleanUp(){ // Release all adapter information UINT i = 0; for( i; i < vAdapters.size(); i++ ) vAdapters[i]->Release(); for( i = 0; i < vOutputs.size(); i++ ) vOutputs[i]->Release(); vAdapters.clear(); vOutputs.clear(); vModes.clear(); } BOOL CALLBACK cSettings::DlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam){ WCHAR s[128]; switch(msg) { case WM_INITDIALOG: // Here we initialize our dialog to display the info SetDlgItemText(hWnd, IDC_ADAPTERNAME, (LPCWSTR)this->GetAdapterDesc().Description); SetDlgItemInt(hWnd, IDC_DEDMEM, (this->GetAdapterDesc().DedicatedVideoMemory)/1024/1024, false); SetDlgItemInt(hWnd, IDC_SHAREDMEM, this->GetAdapterDesc().SharedSystemMemory/1024/1024, false); for(int i = 0; i < this->GetModes().size(); i++ ){ swprintf( s, TEXT("%i, %i, 32-Bit"), this->GetModes()[i].Width, this->GetModes()[i].Height); SendDlgItemMessage(hWnd, IDC_RESOLUTION, CB_ADDSTRING, (WPARAM)i, (LPARAM)s); } return TRUE; case WM_DESTROY: EndDialog(hWnd, 0); return TRUE; case WM_COMMAND: switch(wParam) { case IDOK: this->ConfirmSettings(hWnd); EndDialog(hWnd, 0); return TRUE; case IDCANCEL: EndDialog(hWnd, 0); return TRUE; } break; } return FALSE; }
Within the Application class I make a call to a setup function which creates a new instance of the cSettings class which in turn calls the function to show the dialog, but the dialog return -1 with the message posted above constantly no matter how I try to adjust the code to find the underlying issue.
Please help.
Regards
Dave