Discussion:
Problem using CString with MFC and ATL
(too old to reply)
Marc-Andre Michel
2004-02-16 16:24:32 UTC
Permalink
Hi,

The application I'm working on uses only portable libs like ACE, stl,
etc... but must use a 3rd party DLL which has a function of this kind:

bool MyFunction(CString s);

Basically CString is part of MFC, so I built a DLL with an stl
interface which wraps the other, so my main application doesn't have
to link with MFC.
The corresponding wrapper looks like:

bool MyWrapperFunction(std::string s) {
return MyFunction(s.c_str());
}

The compilation of my wrapper DLL is fine, but I have an error when
linking:

error LNK2001: unresolved external symbol "__declspec(dllimport) bool
__cdecl MyFunction(class CString)"
(__imp_?MyFunction@@YA_NVCString@@@Z)

If I check the 3rd part DLL with for example DEPENDS.EXE, I can see
the function signature is a bit different:

?MyFunction@@YA_NV?$***@DV?$***@DV?$***@D@ATL@@@ATL@@@ATL@@@Z

It seems the 3rd party DLL was compiled with CString derived from ATL,
while I'm using CString from MFC. (?) In addition, the 3rd party DLL
was compiled with Visual Studio 7 and I'm using VS6.

Does anybody has experienced a similar situation ? How do I have to
set my DLL in order to link and call MyFunction ?

many thanks

Marc-Andre Michel
Brian Muth
2004-02-16 16:57:42 UTC
Permalink
Obviously, you can't mix up the MFC CString with the ATL7 CString. Your
wrapper is going to have to use the ATL7 CString, and for that, you will
have to use Visual Studio 7.

Brian
Eric Hirst
2004-02-16 17:27:38 UTC
Permalink
If the 3rd party library works with a LPCTSTR argument (try "foo" and
L"foo"), do that. I'm not sure if it will work or not, but it's easy to try.

If not, can you get the 3rd party vendor to give you a version which does
take LPCTSTR? It's a trivial change on their part that will make their
library usable by far more clients without breaking existing clients.
Requiring concrete classes like CString (version 6.0, 7.0, 7.1, or whatever)
on a published interface is pretty bad form.
--
Eric Hirst, SSE

Sorry, I don't want to test my company's spam filters.
Please follow up to newsgroup, or send mail to the
following address, which I check occasionally:

s-p-a-r-k-y-d-o-o-d-l-e-d-o-o
y-a-h-o-o
c-o-m
Post by Marc-Andre Michel
Hi,
The application I'm working on uses only portable libs like ACE, stl,
bool MyFunction(CString s);
Basically CString is part of MFC, so I built a DLL with an stl
interface which wraps the other, so my main application doesn't have
to link with MFC.
bool MyWrapperFunction(std::string s) {
return MyFunction(s.c_str());
}
The compilation of my wrapper DLL is fine, but I have an error when
error LNK2001: unresolved external symbol "__declspec(dllimport) bool
__cdecl MyFunction(class CString)"
If I check the 3rd part DLL with for example DEPENDS.EXE, I can see
It seems the 3rd party DLL was compiled with CString derived from ATL,
while I'm using CString from MFC. (?) In addition, the 3rd party DLL
was compiled with Visual Studio 7 and I'm using VS6.
Does anybody has experienced a similar situation ? How do I have to
set my DLL in order to link and call MyFunction ?
many thanks
Marc-Andre Michel
Mark
2004-02-17 15:21:13 UTC
Permalink
To my knowledge, it doesn't matter what version of VC you're using, the CString class is the same. What matters is what MFC dll's that are on the machine. It makes sence that you get a linker error because the function signatures don't match.
Just statically link to MFC and pass a CString, what's the problem
Mark

Loading...