Loading Resource from dll fails
-
I have created a win32 resource dll which has only string table, also i have included \NOENTRY in linker options in-order to make it as resource only dll Now I am loading the dll in MFC application and loads fine but when I am try to get the string from the string table it doens't load. Here is my code:
HINSTANCE hinsttance = ::LoadLibrary("SampleEN.dll"); DWORD dwError = GetLastError(); if (!hinsttance) { AfxMessageBox("Failed to load"); } else { HINSTANCE hInstResourceClient = AfxGetResourceHandle(); // Use DLL's instance handle AfxSetResourceHandle(hinsttance); LPCTSTR lpszName = MAKEINTRESOURCE(1); //IDC\_STATIC\_TOP has been defined as 1 in the dll HRSRC hrsrc = FindResource(m\_hinstLib, lpszName, RT\_STRING); if (hrsrc) { TCHAR szTemp\[256\]; LoadString(m\_hinstLib, IDC\_STATIC\_TOP, szTemp, 255); } AfxSetResourceHandle(hInstResourceClient); }
what could be the problem???
-
I have created a win32 resource dll which has only string table, also i have included \NOENTRY in linker options in-order to make it as resource only dll Now I am loading the dll in MFC application and loads fine but when I am try to get the string from the string table it doens't load. Here is my code:
HINSTANCE hinsttance = ::LoadLibrary("SampleEN.dll"); DWORD dwError = GetLastError(); if (!hinsttance) { AfxMessageBox("Failed to load"); } else { HINSTANCE hInstResourceClient = AfxGetResourceHandle(); // Use DLL's instance handle AfxSetResourceHandle(hinsttance); LPCTSTR lpszName = MAKEINTRESOURCE(1); //IDC\_STATIC\_TOP has been defined as 1 in the dll HRSRC hrsrc = FindResource(m\_hinstLib, lpszName, RT\_STRING); if (hrsrc) { TCHAR szTemp\[256\]; LoadString(m\_hinstLib, IDC\_STATIC\_TOP, szTemp, 255); } AfxSetResourceHandle(hInstResourceClient); }
what could be the problem???
Super Hornet wrote:
HRSRC hrsrc = FindResource(m_hinstLib, lpszName, RT_STRING);
What is m_hinstLib? It should be hinsttance. Then use the handle returned by
FindResource
in a call toLoadResource
. To access the actual resource callLockResource
on the handle returned byLoadResource
.«_Superman_» I love work. It gives me something to do between weekends.
-
I have created a win32 resource dll which has only string table, also i have included \NOENTRY in linker options in-order to make it as resource only dll Now I am loading the dll in MFC application and loads fine but when I am try to get the string from the string table it doens't load. Here is my code:
HINSTANCE hinsttance = ::LoadLibrary("SampleEN.dll"); DWORD dwError = GetLastError(); if (!hinsttance) { AfxMessageBox("Failed to load"); } else { HINSTANCE hInstResourceClient = AfxGetResourceHandle(); // Use DLL's instance handle AfxSetResourceHandle(hinsttance); LPCTSTR lpszName = MAKEINTRESOURCE(1); //IDC\_STATIC\_TOP has been defined as 1 in the dll HRSRC hrsrc = FindResource(m\_hinstLib, lpszName, RT\_STRING); if (hrsrc) { TCHAR szTemp\[256\]; LoadString(m\_hinstLib, IDC\_STATIC\_TOP, szTemp, 255); } AfxSetResourceHandle(hInstResourceClient); }
what could be the problem???
Super Hornet wrote:
m_hinstLib
What's that? Your resource DLL's handle is
hinsttance
... -
Super Hornet wrote:
HRSRC hrsrc = FindResource(m_hinstLib, lpszName, RT_STRING);
What is m_hinstLib? It should be hinsttance. Then use the handle returned by
FindResource
in a call toLoadResource
. To access the actual resource callLockResource
on the handle returned byLoadResource
.«_Superman_» I love work. It gives me something to do between weekends.
Actually it's - hinsttance, mistakenly written here as m_hinstLib
-
Actually it's - hinsttance, mistakenly written here as m_hinstLib
Where exactly does it fail? Is it the
FindResource
that is failing or is itLoadString
? Try it without theAfxSetResourceHandle
call.«_Superman_» I love work. It gives me something to do between weekends.
-
Super Hornet wrote:
HRSRC hrsrc = FindResource(m_hinstLib, lpszName, RT_STRING);
What is m_hinstLib? It should be hinsttance. Then use the handle returned by
FindResource
in a call toLoadResource
. To access the actual resource callLockResource
on the handle returned byLoadResource
.«_Superman_» I love work. It gives me something to do between weekends.
Modified code according to your suggestion:
HINSTANCE hinstance = ::LoadLibrary("SampleEN.dll"); if (!hinstance) { AfxMessageBox("Failed to load"); } else { HINSTANCE hInstResourceClient = AfxGetResourceHandle(); // Use DLL's instance handle AfxSetResourceHandle(hinstance); LPCTSTR lpszName = MAKEINTRESOURCE(1); //IDC\_STATIC\_TOP has been defined as 1 in the dll HRSRC hrsrc = FindResource(hinstance, lpszName, RT\_STRING); if (hrsrc) { HGLOBAL hglobal = LoadResource(hinstance, hrsrc); LockResource(hglobal); TCHAR szTemp\[256\]; LoadString(hinstance, IDC\_STATIC\_TOP, szTemp, 255); } AfxSetResourceHandle(hInstResourceClient); }
even now the string is empty. I get the error code: 1814 - which says resource couldn't be found. But I have re-verfied that the ID exists in the string table
-
Super Hornet wrote:
m_hinstLib
What's that? Your resource DLL's handle is
hinsttance
...thank you for pointing the error
-
Super Hornet wrote:
HRSRC hrsrc = FindResource(m_hinstLib, lpszName, RT_STRING);
What is m_hinstLib? It should be hinsttance. Then use the handle returned by
FindResource
in a call toLoadResource
. To access the actual resource callLockResource
on the handle returned byLoadResource
.«_Superman_» I love work. It gives me something to do between weekends.
I have tried commenting the statement AfxSetResourceHandle(hinstance); but the same error The error code 1814 comes after LaodString call
-
Super Hornet wrote:
HRSRC hrsrc = FindResource(m_hinstLib, lpszName, RT_STRING);
What is m_hinstLib? It should be hinsttance. Then use the handle returned by
FindResource
in a call toLoadResource
. To access the actual resource callLockResource
on the handle returned byLoadResource
.«_Superman_» I love work. It gives me something to do between weekends.
Now I am able to get the correct value's The problem is with resource id's, I haven't defined same resource id in dll and in mfc application.