: : CoInitialize (NULL);
M_pConnection. CreateInstance (_uuidof (Connection));
Try
{
M_pConnection - & gt; Open (" Provider=Microsoft. Jet. The OLEDB. 4.0; Data Source=E: \ \ HistoryFault MDB ", ""," ", adModeUnknown);
}
Catch _com_error (e)
{
Cstrings errormessage;
Errormessage. Format (" connect to database failure! \ r \ n error message: % s ", e.E rrorMessage ());
AfxMessageBox (errormessage);///display an error message
return FALSE;
}
CodePudding user response:
M_pConnection. CreateInstance to judge whether the return value is S_OKCan be installed on other machines VS remote debugger for remote debugging
CodePudding user response:
In a 64 - bit Windows:64 exe and DLL in the directory c: \ Windows \ sys tem32 directory.
32 bit exe and DLL in the directory c: \ Windows \ sys wow64 directory.
So pay attention to:
In win64 system registered under 32-bit ocx DLL to 32 ocx or copy the DLL to the c: \ Windows \ syswow64 \ directory,
And registered to c: \ Windows \ syswow64 \ regsvr32 XXXXXXX ocx or DLL
Under win64 a system set up 32-bit programs use a database alias to c: \ Windows \ \ syswow64 \ cliconfg exe
Under win64 a system set up a 32-bit application system DSN to c: \ Windows \ \ syswow64 \ odbcad32 exe
CodePudding user response:
Problem solved, should use relative path connection access,Cstrings sPath m_strPath;
GetModuleFileName (NULL, sPath GetBufferSetLength (MAX_PATH + 1), MAX_PATH);
SPath. ReleaseBuffer ();
Int len=sPath. ReverseFind (' \ \ ') + 1;
M_strPath=sPath. Left (len);
Cstrings strConnection="Provider=Microsoft. Jet. The OLEDB. 4.0. Data Source="+ m_strPath +" Data \ \ "+" HistoryFault MDB ".
Try
{
M_pConnection - & gt; Open (_bstr_t (strConnection), ""," ", adModeUnknown);
}
But the generated exe run on a 32-bit system interface is larger, the following part was held up by the desktop, search for a moment to configure VS platform, but I'm not x86 options, only x64 and arm, this how to solve