Home > Back-end >  MFC calls common DLL error
MFC calls common DLL error

Time:12-31

I have a MFC and a common DLL, not MFC DLL, in the use of MFC DLL function called some functions can be called successful, some is not successful,
MFC in the call statement:
StrSQL. The Format (" update wageinfo set wage=% lf, date='% s' where id=' % s' ", m_nWage, strDate, m_strID);
Int RVSQL=dboperafunc (strSQL);
If (RVSQL!=0)
DBOPERA_ERROR;

Definition of dboperafunc functions in the DLL:
DBOPERADLL_API int dboperafunc (const CString& SQL)
{
Try {
_ConnectionPtr pConnection;
Retrieves the hr=pConnection. CreateInstance (" ADODB. Connection ");//create a Connection object
If (SUCCEEDED (hr))
Hr=pConnection - & gt; Open (" driver={SQL Server}; Server=(local); The DATABASE=HMSys;" , ""," ", adModeUnknown);
//_ConnectionPtr m_pConnection=openDb ();
PConnection - & gt; Execute (SQL (_bstr_t), NULL, adCmdText);
return 0;
}
Catch _com_error (e)
{
Cstrings strComError;
StrComError. Format (" wrong number: 08 lx \ % n error message: % s \ n error source: % s \ n error description: % s ",
E.E rror (),//error Numbers
E.E rrorMessage (),//the error information
(LPCSTR) e.S ource (),//error source
(LPCSTR) e.D escription ());//error description

: : MessageBox (NULL, strComError, "error", MB_ICONEXCLAMATION);
Return e.E rror ();
}
}

DLL can be compiled, there is. Lib and. DLL files, MFC attributes have the correct link to the DLL generated. Lib files, but at the time of compilation of MFC will prompt the following error:
Error LNK2019 cannot resolve the external symbol "__declspec (dllimport) int __cdecl dboperafunc (class ATL: : CStringT> Const & amp;) "(__imp_? Dboperafunc @ @ YAHABV? $CStringT @ DV? $StrTraitMFC_DLL @ DV? @ $ChTraitsCRT @ D ATL @ @ @ @ @ ATL @ @ @ Z), the symbol in the function __catch $? The save @ CWageManageDlg @ @ IAEXXZ quoted in $0

The man tips do something wrong??????? Thank you


CodePudding user response:

1. In C/C + + DLL corresponding directory contains header files, libraries directory contains the DLL file
2. The DLL is added in the linker - "input option corresponding lib file
3. Generate DLL character set and call DLL exe unified character set?

CodePudding user response:

 
CoInitialize(NULL);
//...
CoUninitialize ();

?

CodePudding user response:

reference 1st floor qq_33487700 response:
1. In C/C + + DLL corresponding directory contains header files, libraries directory contains the DLL file
2. The DLL is added in the linker - "input option corresponding lib file
3. Generate DLL character set and call DLL exe unified character set?

Unity, are more bytes

CodePudding user response:

refer to the second floor 4 teacher zhao response:
 
CoInitialize(NULL);
//...
CoUninitialize ();

?

This is where to add? Can you elaborate? thank you

CodePudding user response:

refer to the second floor 4 teacher zhao response:
 
CoInitialize(NULL);
//...
CoUninitialize ();

?

Feeling is not the problem, try the same fault

CodePudding user response:

https://bbs.csdn.net/topics/200039885

CodePudding user response:

https://www.baidu.com/s? Wd=MFC % 20 ado % 20 coinitialize % 20 coinitializeex

CodePudding user response:

The reference of the
https://bbs.csdn.net/topics/398268320

As a common DLL cstrings there will be a problem in the use of MFC, finally changed to char *,
Turn cstrings char * refer to this:
https://blog.csdn.net/maodewen11/article/details/107070267/

Thank you for your bosses
  • Related