Binary resource in Windows service?
-
Have you tried calling
FindResourceEx
with aNULL
instance parameter directly? Also, try usingFindResource
if language is not an concern (and it sounds like it is not). Also, how are the resources identified, by number or by string? Are you using the correct Resource Type value? Peace! -=- James
If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
Tip for new SUV drivers: Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
DeleteFXPFiles & CheckFavorites (Please rate this post!) -
Yes, I tried FindResourceEx() with the NULL instance parameter. The resources are identified by number, their type is "TEXT".
Are you using
MAKEINTRESOURCE
to specify the identifying number? This might go faster if we had a code snippet of the code you are using... Peace! -=- James
If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
Tip for new SUV drivers: Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
DeleteFXPFiles & CheckFavorites (Please rate this post!) -
Are you using
MAKEINTRESOURCE
to specify the identifying number? This might go faster if we had a code snippet of the code you are using... Peace! -=- James
If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
Tip for new SUV drivers: Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
DeleteFXPFiles & CheckFavorites (Please rate this post!)This code fails - the m_hInstance member is null: CWinApp* lpApp = AfxGetApp(); HINSTANCE hInstance = lpApp->m_hInstance; This code fails - fires an assert in debug, throws an exception in release version: HINSTANCE hInstance = AfxGetInstanceHandle(); This code never executes because of the above failures: HANDLE hHandle1 = LoadResource( hInstance, FindResource( hInstance, MAKEINTRESOURCE( IDR_RES1 ), "TEXT" ) ); HANDLE hHandle2 = LoadResource( hInstance, FindResource( hInstance, MAKEINTRESOURCE( IDR_RES2 ), "TEXT" ) ); This code works in 3 other Windows desktop applications. It just doesn't work here because of the runtime environment, the service. I am trying to find a way around the fact that the embedded resources aren't accessible when the service is loading, or even after it is loaded. Thanks for your help, Royce
-
This code fails - the m_hInstance member is null: CWinApp* lpApp = AfxGetApp(); HINSTANCE hInstance = lpApp->m_hInstance; This code fails - fires an assert in debug, throws an exception in release version: HINSTANCE hInstance = AfxGetInstanceHandle(); This code never executes because of the above failures: HANDLE hHandle1 = LoadResource( hInstance, FindResource( hInstance, MAKEINTRESOURCE( IDR_RES1 ), "TEXT" ) ); HANDLE hHandle2 = LoadResource( hInstance, FindResource( hInstance, MAKEINTRESOURCE( IDR_RES2 ), "TEXT" ) ); This code works in 3 other Windows desktop applications. It just doesn't work here because of the runtime environment, the service. I am trying to find a way around the fact that the embedded resources aren't accessible when the service is loading, or even after it is loaded. Thanks for your help, Royce
If your resources are contained directly within your EXE file, then use
GetModuleHandle(NULL)
to retrieve the 'instance' handle used for loading the resources :cool: -
This code fails - the m_hInstance member is null: CWinApp* lpApp = AfxGetApp(); HINSTANCE hInstance = lpApp->m_hInstance; This code fails - fires an assert in debug, throws an exception in release version: HINSTANCE hInstance = AfxGetInstanceHandle(); This code never executes because of the above failures: HANDLE hHandle1 = LoadResource( hInstance, FindResource( hInstance, MAKEINTRESOURCE( IDR_RES1 ), "TEXT" ) ); HANDLE hHandle2 = LoadResource( hInstance, FindResource( hInstance, MAKEINTRESOURCE( IDR_RES2 ), "TEXT" ) ); This code works in 3 other Windows desktop applications. It just doesn't work here because of the runtime environment, the service. I am trying to find a way around the fact that the embedded resources aren't accessible when the service is loading, or even after it is loaded. Thanks for your help, Royce
When you said an "MFC based service" before, do you really mean a MFC service, or an ATL service with "support MFC" checked. If you have the latter, you need to "fool" MFC by doing the following:
CWinApp waWA; waWA.m_hInstance = _Module.GetModuleInstance(); afxCurrentInstanceHandle = _Module.GetModuleInstance(); // Or ::GetModuleHandle( NULL ) afxCurrentResourceHandle = _Module.GetResourceInstance(); // Or ::GetModuleHandle( NULL )
Then things that refrence the global
CWinApp
instance will work correctly. Kludgy, but that is what you get for mixing MFC and ATL with VC++ 6.0! :) Peace! -=- James
If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
Tip for new SUV drivers: Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
DeleteFXPFiles & CheckFavorites (Please rate this post!) -
When you said an "MFC based service" before, do you really mean a MFC service, or an ATL service with "support MFC" checked. If you have the latter, you need to "fool" MFC by doing the following:
CWinApp waWA; waWA.m_hInstance = _Module.GetModuleInstance(); afxCurrentInstanceHandle = _Module.GetModuleInstance(); // Or ::GetModuleHandle( NULL ) afxCurrentResourceHandle = _Module.GetResourceInstance(); // Or ::GetModuleHandle( NULL )
Then things that refrence the global
CWinApp
instance will work correctly. Kludgy, but that is what you get for mixing MFC and ATL with VC++ 6.0! :) Peace! -=- James
If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
Tip for new SUV drivers: Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
DeleteFXPFiles & CheckFavorites (Please rate this post!) -
When you said an "MFC based service" before, do you really mean a MFC service, or an ATL service with "support MFC" checked. If you have the latter, you need to "fool" MFC by doing the following:
CWinApp waWA; waWA.m_hInstance = _Module.GetModuleInstance(); afxCurrentInstanceHandle = _Module.GetModuleInstance(); // Or ::GetModuleHandle( NULL ) afxCurrentResourceHandle = _Module.GetResourceInstance(); // Or ::GetModuleHandle( NULL )
Then things that refrence the global
CWinApp
instance will work correctly. Kludgy, but that is what you get for mixing MFC and ATL with VC++ 6.0! :) Peace! -=- James
If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
Tip for new SUV drivers: Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
DeleteFXPFiles & CheckFavorites (Please rate this post!) -
Have you tried using it? Even if it was invalid, using
FindResource(...)
with aNULL
hModule parameter should default to using the load image (EXE). Are the resources present in the executable itself, and not in another DLL? Are you sure they are being linked in correctly? One way to test is to open a new instance of DevStudio, and open the EXE file being sure to specify "Resources" in the "Open As" combobox. You can them be sure that the resources are actually there and accessable - you should be able to double-click on them and see them in the binary editor. I am running out of ideas here... Peace! -=- James
If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
Tip for new SUV drivers: Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
DeleteFXPFiles & CheckFavorites (Please rate this post!) -
Have you tried using it? Even if it was invalid, using
FindResource(...)
with aNULL
hModule parameter should default to using the load image (EXE). Are the resources present in the executable itself, and not in another DLL? Are you sure they are being linked in correctly? One way to test is to open a new instance of DevStudio, and open the EXE file being sure to specify "Resources" in the "Open As" combobox. You can them be sure that the resources are actually there and accessable - you should be able to double-click on them and see them in the binary editor. I am running out of ideas here... Peace! -=- James
If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
Tip for new SUV drivers: Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
DeleteFXPFiles & CheckFavorites (Please rate this post!) -
Have you tried using it? Even if it was invalid, using
FindResource(...)
with aNULL
hModule parameter should default to using the load image (EXE). Are the resources present in the executable itself, and not in another DLL? Are you sure they are being linked in correctly? One way to test is to open a new instance of DevStudio, and open the EXE file being sure to specify "Resources" in the "Open As" combobox. You can them be sure that the resources are actually there and accessable - you should be able to double-click on them and see them in the binary editor. I am running out of ideas here... Peace! -=- James
If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
Tip for new SUV drivers: Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
DeleteFXPFiles & CheckFavorites (Please rate this post!)