Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can not use CString parameter (which was built in VC6.0) at VC2019

Tags:

dll

c-strings

mfc

I have an old DLL which was built in VC6.0.

And I want to use this DLL at VC2019 project.

This DLL file is a MFC DLL, and contains a lot of classes and functions.

There is no problem for using classes and functions except these three functions (which contains CString parameter).

The exported DLL functions (class functions) are like below:

class CColorListCtrl : public CListCtrl
{
    ...

public:
    int AddColumn(CString szHeaderStr, int nColWidth);
    int AddItem(CString szItem);
    bool SetItemTip(int nRow, int nCol, CString szTip);

    ...
}

And the link errors are like below:

error LNK2001: unresolved external symbol "public: int __thiscall CColorListCtrl::AddColumn(class ATL::CStringT<char,class StrTraitMFC<char,class ATL::ChTraitsCRT<char> > >,int,int)" (?AddColumn@CColorListCtrl@@QAEHV?$CStringT@DV?$StrTraitMFC@DV?$ChTraitsCRT@D@ATL@@@@@ATL@@HH@Z)

error LNK2001: unresolved external symbol "public: int __thiscall CColorListCtrl::AddItem(class ATL::CStringT<char,class StrTraitMFC<char,class ATL::ChTraitsCRT<char> > >)" (?AddItem@CColorListCtrl@@QAEHV?$CStringT@DV?$StrTraitMFC@DV?$ChTraitsCRT@D@ATL@@@@@ATL@@@Z)

error LNK2001: unresolved external symbol "public: bool __thiscall CColorListCtrl::SetItemTip(int,int,class ATL::CStringT<char,class StrTraitMFC<char,class ATL::ChTraitsCRT<char> > >)" (?SetItemTip@CColorListCtrl@@QAE_NHHV?$CStringT@DV?$StrTraitMFC@DV?$ChTraitsCRT@D@ATL@@@@@ATL@@@Z)

The DLL exported functions are like below:

?AddColumn@CColorListCtrl@@QAEHVCString@@HH@Z
?AddItem@CColorListCtrl@@QAEHVCString@@@Z
?SetItemTip@CColorListCtrl@@QAE_NHHVCString@@@Z

For fix this problem, I changed Project Character Set (Project Setting -> General -> Character Set) as "Use Multi-Byte Character Set", but the problem is not solved.

I noticed that CString class was changed, so the CString classes at VC6 and VC2019 are different.

I have no idea to resolve this prblem. Also I can not change DLL, because I removed the project for this DLL.

Please help me.

Thank you.

like image 261
MasterStar Avatar asked Nov 29 '25 12:11

MasterStar


2 Answers

CString in VC++ 6 and VC++ 2019 are not compatible with each other because there is a difference.

That is, if you use CString as a parameter for the export function in VC6 dll, you cannot directly call VC6 dll in VS2019.

I suggest one solution:

  1. First, create a dll that acts as a repeater in vc6. The export function of this dll uses, for example, LPCTSTR as a parameter. Let this dll be A.dll and the original dll be B.dll.
  2. Inside the A.dll, the export function of the B.dll is called and the result is converted to LPCTSTR and returned.

VS2019 calls the export function of A.dll. LPCTSTR is compatible between VS2019 and VS6, so you can solve your problem in this way.

like image 167
secuman Avatar answered Dec 01 '25 06:12

secuman


There is some notes in this article (CStringT Class) where it states:

If your code contains the workaround for linker errors that is described in Exporting String Classes Using CStringT, you should remove that code. It is no longer needed.

I notice that the subsequent article that it refers to does state:

In the past, MFC developers have derived from CString to specialize their own string classes. In Microsoft Visual C++.NET (MFC 8.0), the CString class was superseded by a template class called CStringT.

It provides an explanation of what you can do to resolve linker issues.

like image 27
Andrew Truckle Avatar answered Dec 01 '25 05:12

Andrew Truckle



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!