c++ - DAO code for Microsoft access works in Visual Studio 2008 but not in Visual Studio 2012 -


i have following line of code in example project downloaded , opened in visual studio 2008

_bstr_t bstrconnect = "path mdb file";  int _tmain(int argc, _tchar* argv[]){ hresult hr = coinitialize(null); if (failed(hr)) {     cout<<dam<<": failed coinitialize() com."<<endl;     return hr; }  dao::_dbengine* pengine = null;  hr = cocreateinstance(     __uuidof(dao::dbengine),     null,     clsctx_all,     iid_idispatch,     (lpvoid*)&pengine); if (succeeded(hr) && pengine) {     try     {         dao::databaseptr pdbptr = null;         pdbptr = pengine->opendatabase(bstrconnect); 

this code works. put similar code in visual studio 2012 project

_bstr_t bstrconnect = "path mdb file";  int _tmain(int argc, _tchar* argv[]) { hresult hr = coinitializeex(null, coinit_multithreaded); if (failed(hr)) {     cout<<"failed coinitialize() com."<<endl;     cout << _com_error(hr).errormessage() << endl;     return hr; }  dao::_dbengine* pengine = null;  hr = cocreateinstance(     __uuidof(dao::dbengine),     null,     clsctx_all,     iid_idispatch,     (lpvoid*)&pengine);  if (succeeded(hr) && pengine) {     try     {         dao::databaseptr pdbptr = null;         pdbptr = pengine->opendatabase(bstrconnect); 

in 2012 version system.accessviolationexception when call pengine->opendatabase. there need change in 2012 code? had coinitialize in 2012 version kept returning error until switched coinitializeex.


Comments

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -