473,396 Members | 1,724 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Link Error 2028 2029 when using CString in C++/CLI

Hello Newsgroup,

I have a link error that I did not manage to fix.

I basically consume a VC 8.0 C++ dll that exports a class with a
method containing CString declaration as follows:

class WarnErr
{
//...
CString WarnErr::getReadableCode (long nCode)
{
//...
}

When using the method in another project (C++/CLI) to write a RTCW,
the linker fails with the following error:

Error 2 error LNK2028: unresolved token (0A00000F) "public: static
class ATL::CStringT<char,class StrTraitMFC_DLL<char,class
ATL::ChTraitsCRT<char __cdecl
lala_McsOOP::WarnErr::getReadableCode(long)" (?
getReadableCode@WarnErr@lala_McsOOP@@$$FSA?AV?$CSt ringT@DV?
$StrTraitMFC_DLL@DV?$ChTraitsCRT@D@ATL@@@@@ATL@@J@ Z) referenced in
function "public: class System::String ^ __clrcall
lala::Spectrometer::RTCW::SpectrometerException::T oString(void)" (?
ToString@SpectrometerException@RTCW@Spectrometer@l ala@@$$FQ$AAMP
$AAVString@System@@XZ) SpectrometerException.obj
Does anybody know how to fix this issue. Or is there any other good
practice passing strings from unmanaged libs tto managed libs?

Thanks for your help!

Jun 1 '07 #1
4 5587
When using the method in another project (C++/CLI) to write a RTCW,
the linker fails with the following error:

Error 2 error LNK2028: unresolved token (0A00000F) "public: static
class ATL::CStringT<char,class StrTraitMFC_DLL<char,class
ATL::ChTraitsCRT<char __cdecl
lala_McsOOP::WarnErr::getReadableCode(long)" (?
getReadableCode@WarnErr@lala_McsOOP@@$$FSA?AV?$CSt ringT@DV?
$StrTraitMFC_DLL@DV?$ChTraitsCRT@D@ATL@@@@@ATL@@J@ Z) referenced in
function "public: class System::String ^ __clrcall
lala::Spectrometer::RTCW::SpectrometerException::T oString(void)" (?
ToString@SpectrometerException@RTCW@Spectrometer@l ala@@$$FQ$AAMP
$AAVString@System@@XZ) SpectrometerException.obj
Does anybody know how to fix this issue. Or is there any other good
practice passing strings from unmanaged libs tto managed libs?
I suggest that the only things you should pass across module boundaries are:
(1) blocks of raw data (pointer and length)
(2) interface pointers
DCOM shows that by following these two rules you can have very powerful yet
stable interaction between all kinds of different components. Decoupling in
this way is also good for encapsulation, testability, and stability.

Trying to share class objects between unmanaged modules usually fails due to
ODR violations.
>
Thanks for your help!

Jun 1 '07 #2
On Jun 1, 9:14 pm, "Ben Voigt [C++ MVP]" <r...@nospam.nospamwrote:
When using the method in another project (C++/CLI) to write a RTCW,
the linker fails with the following error:
Error 2 error LNK2028: unresolved token (0A00000F) "public: static
class ATL::CStringT<char,class StrTraitMFC_DLL<char,class
ATL::ChTraitsCRT<char __cdecl
lala_McsOOP::WarnErr::getReadableCode(long)" (?
getReadableCode@WarnErr@lala_McsOOP@@$$FSA?AV?$CSt ringT@DV?
$StrTraitMFC_DLL@DV?$ChTraitsCRT@D@ATL@@@@@ATL@@J@ Z) referenced in
function "public: class System::String ^ __clrcall
lala::Spectrometer::RTCW::SpectrometerException::T oString(void)" (?
ToString@SpectrometerException@RTCW@Spectrometer@l ala@@$$FQ$AAMP
$AAVString@System@@XZ) SpectrometerException.obj
Does anybody know how to fix this issue. Or is there any other good
practice passing strings from unmanaged libs tto managed libs?

I suggest that the only things you should pass across module boundaries are:
(1) blocks of raw data (pointer and length)
(2) interface pointers
DCOM shows that by following these two rules you can have very powerful yet
stable interaction between all kinds of different components. Decoupling in
this way is also good for encapsulation, testability, and stability.

Trying to share class objects between unmanaged modules usually fails due to
ODR violations.
Thanks for your help!
Hello Ben,

thanks for your comment on this issue. I generally agree with your
opinion as it is good practice.
However, there a couple of good reasons for CString as well and I was
under the opinion that passing basic types like strings isn't a big
deal anymore.
Let us consider the lib I'm trying to incorporate with is sort of fix
and will only get subject for changes if any other approach fails.

Can you point me to pretty good practices of passing strings of
individual length's from unmanaged code to C++/CLI code?

Thanks again,

Sebastian Dau

Jun 4 '07 #3
Does anybody know how to fix this issue. Or is there any other good
practice passing strings from unmanaged libs tto managed libs?

I suggest that the only things you should pass across module boundaries
are:
(1) blocks of raw data (pointer and length)
(2) interface pointers
DCOM shows that by following these two rules you can have very powerful
yet
stable interaction between all kinds of different components. Decoupling
in
this way is also good for encapsulation, testability, and stability.

Trying to share class objects between unmanaged modules usually fails due
to
ODR violations.
Thanks for your help!

Hello Ben,

thanks for your comment on this issue. I generally agree with your
opinion as it is good practice.
However, there a couple of good reasons for CString as well and I was
under the opinion that passing basic types like strings isn't a big
deal anymore.
Let us consider the lib I'm trying to incorporate with is sort of fix
and will only get subject for changes if any other approach fails.

Can you point me to pretty good practices of passing strings of
individual length's from unmanaged code to C++/CLI code?
First up, you must compile all code using the unmanaged DLL's classes
without /clr and with the same compiler version used by the DLL. Otherwise
the ODR is violated. This is not a recommendation, it is an absolute
requirement to get any sort of reasonable behavior.

Next, you should use fundamental types such as wchar_t* or char* to pass
data between those files compiled without /clr and the ones compiled with.
The definition of those types aren't changed by /clr or the compiler
version. These convert to and from the std::string and CString variants in
the usual way.

Then, use the following functions to get the data to/from .NET
System::String:

PtrToStringChars
System::Runtime::InteropServices::Marshal::PtrToSt ring{Ansi|Auto|BSTR|Uni}

If you do that, everything should link and run without problems. If the DLL
was compiled using an earlier version of the compiler, then the static lib
wrappers described in "First up" should use extern "C" functions. You
should probably do that anyway.
>
Thanks again,

Sebastian Dau

Jun 4 '07 #4
On Jun 4, 3:30 pm, "Ben Voigt [C++ MVP]" <r...@nospam.nospamwrote:
Does anybody know how to fix this issue. Or is there any other good
practice passing strings from unmanaged libs tto managed libs?
I suggest that the only things you should pass across module boundaries
are:
(1) blocks of raw data (pointer and length)
(2) interface pointers
DCOM shows that by following these two rules you can have very powerful
yet
stable interaction between all kinds of different components. Decoupling
in
this way is also good for encapsulation, testability, and stability.
Trying to share class objects between unmanaged modules usually fails due
to
ODR violations.
Thanks for your help!
Hello Ben,
thanks for your comment on this issue. I generally agree with your
opinion as it is good practice.
However, there a couple of good reasons for CString as well and I was
under the opinion that passing basic types like strings isn't a big
deal anymore.
Let us consider the lib I'm trying to incorporate with is sort of fix
and will only get subject for changes if any other approach fails.
Can you point me to pretty good practices of passing strings of
individual length's from unmanaged code to C++/CLI code?

First up, you must compile all code using the unmanaged DLL's classes
without /clr and with the same compiler version used by the DLL. Otherwise
the ODR is violated. This is not a recommendation, it is an absolute
requirement to get any sort of reasonable behavior.

Next, you should use fundamental types such as wchar_t* or char* to pass
data between those files compiled without /clr and the ones compiled with.
The definition of those types aren't changed by /clr or the compiler
version. These convert to and from the std::string and CString variants in
the usual way.

Then, use the following functions to get the data to/from .NET
System::String:

PtrToStringChars
System::Runtime::InteropServices::Marshal::PtrToSt ring{Ansi|Auto|BSTR|Uni}

If you do that, everything should link and run without problems. If the DLL
was compiled using an earlier version of the compiler, then the static lib
wrappers described in "First up" should use extern "C" functions. You
should probably do that anyway.
Thanks again,
Sebastian Dau
Thanks, Ben I'll give that a try and see how it works.

Jun 4 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Andy | last post by:
I'm trying to make a Config-class that has only one instance, as the code below states. However, when I try to use the instance with CConfig::GetInstance() in another .cpp-file I get a link error:...
0
by: vsaraog | last post by:
Hi y'all, I am using a Created Global Temporary Table in DB2 OS/390 version 7.1.2. I am inserting some data in it and then updating the table using ODBC but while I try to update it, I am...
3
by: Leith Bade | last post by:
I have been trying to use the new Visual C++ Toolkit 2003 with the VC6 IDE I set up the executable, inlcude, and library directories to point to the new compilers I had to fix a few errors in the...
19
by: ashmangat | last post by:
Hi! now on the chapter "string-class" My assignment is below Word Counter: Write a function that accepts a pointer to a C-String as an argument and returns the number of words contained in the...
0
by: Bernie Hunt | last post by:
I'm not sure where to ask this question so I'll start here. I have an app with an installer program that has been delivered before. The user wanted a change, so I made it and rebuilt the installer....
2
by: flyingxu | last post by:
Hi, I run into a cstring related link problem in VC7. My solution has 3 projects, one MFC exe, two MFC extersion DLL. the two MFC extersion DLL export functions which use CString as parameters....
2
by: adsci | last post by:
Hello! Im posting this to c.l.c++ AND win32 because i dont know if this is a MS Compiler Issue or not. here we go: <code> class MyCString
0
by: =?Utf-8?B?REx1ZWNr?= | last post by:
I am getting a debug assertion error that reads: Debug Assertion Failed! program E:\program files\internet explorer\iexplore,exe File: dbgheap.c Line: 1252 Expression:...
4
by: beauwlf | last post by:
Hi Group I am testing out Visual Studio 2008 Eval.. i tried to recompile my MFC C++ Visual Studio 6.0 EXE project . I get these link errors. I can say these errors are linked to EXE function...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.