You can use one of the following methods to have an application configure a data source on your computer:
- Ship and install the .mdb file along with the application.
- Make the .mdb file into a user-defined resource. Then, copy the .mdb file at run time.
- Create an .mdb file either by using Microsoft Access or MSQuery.
- Create the .mdb file as a user-defined resource by adding the following line to your .RC file:where:
mdb_file MDB_RESOURCE filename.mdb
mdb_file is a name for identifying the resource.
MDB_RESOURCE is a name for identifying the type of the resource
and can be any user-defined type.
filename.mdb is the name of the .mdb file.
- Load the resource and write it out to an .mdb file. You can use the following function, from anywhere in your application, to create the .mdb file. (A typical place for creating the .mdb file would be the override of the CWinApp::InitInstance() function.)
// Get the instance handle - required for loading the resource
HINSTANCE hInst = AfxGetInstanceHandle();
// Load the user-defined resource.
HRSRC hmdbFile = ::FindResource(hInst, "mdb_file", "MDB_RESOURCE");
HGLOBAL hRes = ::LoadResource(hInst, hmdbFile);
DWORD dwResSize = ::SizeofResource(hInst, hmdbFile);
if (hRes != NULL)
UINT FAR* lpnRes = (UINT FAR*)::LockResource(hRes);
CString szFileName = "Filename.mdb";
// Create the .mdb file
CFile f( szFileName, CFile::modeCreate | CFile::modeWrite );
// Write the user-defined resource to the .mdb file
CATCH( CFileException, e )
afxDump << "File could not be opened " << e->m_cause << "\n";
#ifndef WIN32 //Unlock Resource is obsolete in the Win32 API
For additional information on configuring a data source programmatically, please see the following articles in the Microsoft Knowledge Base:
Artikel-id: 118609 - Laatst bijgewerkt: 21 nov. 2006 - Revisie: 1