Article ID: 118609
Article Last Modified on 11/21/2006
126606 INFO: Accessing CREATE_DB, REPAIR_DB, and COMPACT_DB
mdb_file MDB_RESOURCE filename.mdb
where:
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.
CreateMDBFile()
{
// 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";
TRY
{
// Create the .mdb file
CFile f( szFileName, CFile::modeCreate | CFile::modeWrite );
// Write the user-defined resource to the .mdb file
f.WriteHuge(lpnRes, dwResSize);
f.Flush();
}
CATCH( CFileException, e )
{
#ifdef _DEBUG
afxDump << "File could not be opened " << e->m_cause << "\n";
#endif
}
END_CATCH
#ifndef WIN32 //Unlock Resource is obsolete in the Win32 API
::UnlockResource(hRes);
#endif
::FreeResource(hRes);
}
}
Additional query words: 2.50 2.51 2.52 3.00 3.10 ODBC
Keywords: kbdatabase kbhowto kbprogramming KB118609