MFC links Access 2007 databases

Source: Internet
Author: User
Tags ole win32

Tag: res token on () generates SAGE result download using CST


God horse doesn't say anything, just give the source code and project
Principle this thing under Google. It's all coming out. I'm going to say that as a novice,
1 should print out, link error reason2 The database should be placed below project, paying particular attention to this


Give some of the source code. can also go to see my uploaded project

StdAfx.h

StdAfx.h: The standard system includes documents including files,//or items that are often used but infrequently changed//project-specific include files #pragma once#ifndef _secure_atl#define _secure_atl 1#endif# Ifndef vc_extralean#define Vc_extralean//exclude rarely used data from the Windows header #endif#include "targetver.h" #define _atl_cstrin G_explicit_constructors///Some CString constructors will be explicit//Shut down MFC's hidden # define _afx_all_warnings#include for some common but often reassuring warning messages <a Fxwin.h>//MFC core components and standard components # include <afxext.h>//MFC extensions # include <afxdisp.h>//MFC own Active class #ifndef _afx_no_ole_support#include <afxdtctl.h>//MFC support for Internet Explorer 4 common Controls #endif#ifndef _AF X_no_afxcmn_support#include <afxcmn.h>//MFC support for Windows Common Controls #endif//_afx_no_afxcmn_support#include <afxcontrolbars.h>//MFC support for ribbon and control bars include <afxdb.h> #ifdef _unicode#if defined _m_ix86#pragma comment (l inker, "/manifestdependency:\" Type= ' Win32 ' Name= ' Microsoft.windows.common-controls ' version= ' 6.0.0.0 ' Processorarchitecture= ' x86 ' publickeytoken= ' 6595b64144CCF1DF ' language= ' * ' "") #elif defined _m_x64#pragma COMMENT (linker, "/manifestdependency:\" Type= ' Win32 ' Name= ' Microsoft.windows.common-controls ' version= ' 6.0.0.0 ' processorarchitecture= ' amd64 ' publickeytoken= ' 6595B64144CCF1DF ' language= ' * ' "") #else #pragma comment (linker, "/manifestdependency:\" Type= ' Win32 ' Name= ' Microsoft.windows.common-controls ' version= ' 6.0.0.0 ' processorarchitecture= ' * ' publickeytoken= ' 6595b64144ccf1df ' Language= ' * ' "")/* #import "c:\program Files\Common Files\system\ado\msado15.dll" No_namespace rename ("EOF", "adoeof" ) using namespace adodb;*/#endif #import "C:\Program Files\Common Files\system\ado\msado15.dll" No_namespace rename (" EOF "," adoeof ") Rename (" BOF "," Adobof ")//using namespace ADODB; #endif

Link code. cpp

MfcLinkAccess.cpp: Defines the class behavior of the application. #include "stdafx.h" #include "mfcLinkAccess.h" #include "mfcLinkAccessDlg.h" #ifdef _debug#define new Debug_new#endif Cmfclinkaccessappbegin_message_map (Cmfclinkaccessapp, CWinApp) on_command (Id_help, &cwinapp::onhelp) END_ Message_map ()//Cmfclinkaccessapp constructs Cmfclinkaccessapp::cmfclinkaccessapp () {//supports another boot manager m_ Dwrestartmanagersupportflags = afx_restart_manager_support_restart;//TODO: Add construction code here,//Place all important initializations in InitInstance} The only one Cmfclinkaccessapp object Cmfclinkaccessapp theapp;//Cmfclinkaccessapp initialize bool Cmfclinkaccessapp::initinstance () { Suppose an application manifest that executes on Windows XP specifies that you want///use ComCtl32.dll version number 6 or higher to enable visualization,//Initcommoncontrolsex () is required. Otherwise, the form cannot be created.

AfxEnableControlContainer ();//Join the Initialize ole/com Environment code if (! AfxOleInit ()) {AfxMessageBox (_t ("Initialize OLE DLL failed!")); return FALSE; HRESULT hr =:: CoInitialize (NULL); if (! SUCCEEDED (HR)) {AfxMessageBox (_t ("Initial exchange COM failure"));///Display error message}_connectionptr m_pconnection;//_bstr_t strconnect ( strconnction) try{hr = M_pconnection.createinstance (__uuidof (Connection));///Create Connection object; if (SUCCEEDED (HR)) {HR = M_pconnection->open ("Provider=microsoft.ace.oledb.12.0;data source=demo.mdb; Persist Security Info=false "," "," ", admodeunknown);///Connection Database///The provider in the connection string in the above sentence is for ACCESS2000 environment, for ACCESS97,// Need to change to: Provider=microsoft.jet.oledb.3.51;//afxmessagebox (_t ("Link succeeded! "));}} catch (_com_error e) {CString errormessage; ErrorMessage. Format (_t ("Connection database failed!\r\n error message:%s"), E.errormessage ()); AfxMessageBox (errormessage)/////Display error message AfxMessageBox (E.description ());///Display error message return-1;} Initcommoncontrolsex initctrls;initctrls.dwsize = sizeof (initctrls);//Set it to include all//common control classes to be used in the application. INITCTRLS.DWICC = Icc_win95_classes;initcommoncontrolsex (&AMp;initctrls); CWinApp::InitInstance (); AfxEnableControlContainer ();//Create Shell Manager in case the dialog box includes//no matter what Shell tree view control or Shell List view control. CShellManager *pshellmanager = new cshellmanager;//standard initialization//assuming that these features are not used and that you want to reduce//Finally the size of the executable file, you should remove the following//non-required specific initialization routines// Change the registry entry used to store settings//TODO: The string should be modified appropriately,//such as change to company or organization name Setregistrykey (_t ("Application wizard generated local application"); Cmfclinkaccessdlg Dlg;m_pmainwnd = &dlg;int_ptr Nresponse = dlg. DoModal (); if (nresponse = = IDOK) {//TODO: The code in this place processing when//"OK" to close the dialog box}else if (nresponse = = IDCANCEL) {//TODO: When to place processing in// Cancel to close the Code for the dialog box}//Delete the shell manager created above. if (Pshellmanager! = NULL) {delete Pshellmanager;} Because the dialog box is closed, FALSE is returned to exit the application,//instead of starting the application's message pump. return FALSE;}


Download my project before you know it!

MFC links Access 2007 databases

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.