Its always a good practice to have the resource into a seperate DLL. The major benefit of having the resource into seperate dll is, it can be easily skinned. Also it has the benefit of seperating the GUI from the code which is better for maintainance.
Here are the simple steps to do the same.
Create a new Win32 Dynamic-Link Library With a simple Win32 Dll project.
Add the following resource file to the project
SepRes.rc
Add the following resource.h file to the project
Now compile the code and the dll will be created.
Now add new MFC Dialog based application project to the workspace. Remove the rc and the resource.h file from the dialog based application workspace. You can even safely delete them from the Hard disk after removing them from the workspace. or even can edit it to have the version info for the executable.
Now add the following lines to the InitInstance of the application
Now copy the dll from the Output folder of the dll project to the location where executable will be created after compiling.
Thats it Run the application.
Here are the simple steps to do the same.
Create a new Win32 Dynamic-Link Library With a simple Win32 Dll project.
Add the following resource file to the project
SepRes.rc
Code: CPP
// Microsoft Visual C++ generated resource script.
//
#include "resource.h"
#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include "afxres.h"
/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS
#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//
1 TEXTINCLUDE DISCARDABLE
BEGIN
"resource.h\0"
END
2 TEXTINCLUDE DISCARDABLE
BEGIN
"#include ""afxres.h""\r\n"
"\0"
END
3 TEXTINCLUDE DISCARDABLE
BEGIN
"#define _AFX_NO_SPLITTER_RESOURCES\r\n"
"#define _AFX_NO_OLE_RESOURCES\r\n"
"#define _AFX_NO_TRACKER_RESOURCES\r\n"
"#define _AFX_NO_PROPERTY_RESOURCES\r\n"
"\r\n"
"#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)\r\n"
"#ifdef _WIN32\r\n"
"LANGUAGE 9, 1\r\n"
"#pragma code_page(1252)\r\n"
"#endif //_WIN32\r\n"
"#include ""res\\SepResApp.rc2"" // non-Microsoft Visual C++ edited resources\r\n"
"#include ""afxres.rc"" // Standard components\r\n"
"#endif\r\n"
"\0"
END
/////////////////////////////////////////////////////////////////////////////
#endif // APSTUDIO_INVOKED
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
#ifdef _WIN32
LANGUAGE 9, 1
#pragma code_page(1252)
#endif //_WIN32
/////////////////////////////////////////////////////////////////////////////
//
// Dialog
//
IDD_ABOUTBOX DIALOG DISCARDABLE 0, 0, 235, 55
STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "About SepResApp"
FONT 8, "MS Sans Serif"
BEGIN
ICON IDR_MAINFRAME,IDC_STATIC,11,17,20,20
LTEXT "SepResApp Version 1.0",IDC_STATIC,40,10,119,8,
SS_NOPREFIX
LTEXT "Copyright (C) 2006",IDC_STATIC,40,25,119,8
DEFPUSHBUTTON "OK",IDOK,178,7, 50,14,WS_GROUP
END
IDD_SEPRESAPP_DIALOG DIALOGEX 0, 0, 320, 200
STYLE DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
EXSTYLE WS_EX_APPWINDOW
CAPTION "SepResApp"
FONT 8, "MS Sans Serif"
BEGIN
DEFPUSHBUTTON "OK",IDOK,260,7,50,14
PUSHBUTTON "Cancel",IDCANCEL,260,23,50,14
LTEXT "TODO: Place dialog controls here.",IDC_STATIC,50,90,200,8
END
/////////////////////////////////////////////////////////////////////////////
//
// Version
//
VS_VERSION_INFO VERSIONINFO
FILEVERSION 1,0,0,1
PRODUCTVERSION 1,0,0,1
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
#else
FILEFLAGS 0x0L
#endif
FILEOS 0x4L
FILETYPE 0x1L
FILESUBTYPE 0x0L
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "040904B0"
BEGIN
VALUE "CompanyName", "\0"
VALUE "FileDescription", "SepResApp MFC Application\0"
VALUE "FileVersion", "1, 0, 0, 1\0"
VALUE "InternalName", "SepResApp\0"
VALUE "LegalCopyright", "Copyright (C) 2006\0"
VALUE "LegalTrademarks", "\0"
VALUE "OriginalFilename","SepResApp.EXE\0"
VALUE "ProductName", "SepResApp Application\0"
VALUE "ProductVersion", "1, 0, 0, 1\0"
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x409, 1200
END
END
/////////////////////////////////////////////////////////////////////////////
//
// DESIGNINFO
//
#ifdef APSTUDIO_INVOKED
GUIDELINES DESIGNINFO DISCARDABLE
BEGIN
IDD_ABOUTBOX, DIALOG
BEGIN
LEFTMARGIN, 7
RIGHTMARGIN, 228
TOPMARGIN, 7
BOTTOMMARGIN, 48
END
IDD_SEPRESAPP_DIALOG, DIALOG
BEGIN
LEFTMARGIN, 7
RIGHTMARGIN, 313
TOPMARGIN, 7
BOTTOMMARGIN,193
END
END
#endif // APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// String Table
//
STRINGTABLE DISCARDABLE
BEGIN
IDS_ABOUTBOX "&About SepResApp..."
END
#endif
#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//
#define _AFX_NO_SPLITTER_RESOURCES
#define _AFX_NO_OLE_RESOURCES
#define _AFX_NO_TRACKER_RESOURCES
#define _AFX_NO_PROPERTY_RESOURCES
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
#ifdef _WIN32
LANGUAGE 9, 1
#pragma code_page(1252)
#endif //_WIN32
#include "afxres.rc" // Standard components
#endif
/////////////////////////////////////////////////////////////////////////////
#endif // not APSTUDIO_INVOKED
Code: CPP
//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ generated include file.
// Used by SEPRESAPP.RC
//
#define IDR_MAINFRAME 128
#define IDM_ABOUTBOX 0x0010
#define IDD_ABOUTBOX 100
#define IDS_ABOUTBOX 101
#define IDD_SEPRESAPP_DIALOG 102
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 129
#define _APS_NEXT_CONTROL_VALUE 1000
#define _APS_NEXT_SYMED_VALUE 101
#define _APS_NEXT_COMMAND_VALUE 32771
#endif
#endif
Now add new MFC Dialog based application project to the workspace. Remove the rc and the resource.h file from the dialog based application workspace. You can even safely delete them from the Hard disk after removing them from the workspace. or even can edit it to have the version info for the executable.
Now add the following lines to the InitInstance of the application
Code: CPP
HINSTANCE hResourceDll = (HINSTANCE) AfxLoadLibrary(_T("SepResSampleDll.dll"));
if (!hResourceDll)
{
AfxMessageBox(_T("Error: Cannot find component \"SepResSampleDll.dll\""));
return FALSE;
}
AfxSetResourceHandle (hResourceDll);
Thats it Run the application.

