Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / November 2005

Tip: Looking for answers? Try searching our database.

Add a VC 6 library in a VC8 project

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
danip - 30 Nov 2005 07:52 GMT
Hi,
Is it possible to add a VC++ 6 library ot a VC++ 8 application ? if yes
how ? is it possible to link a DLL ? how ?

-- Dani
Jochen Kalmbach [MVP] - 30 Nov 2005 08:31 GMT
Hi danip!

> Is it possible to add a VC++ 6 library ot a VC++ 8 application ? if yes
> how ? is it possible to link a DLL ? how ?

In general you can say:
It is *only* possible if it only exports C functions (and has not a
shared CRT).

In all other cases it is almost impossible to use an older LIB with a
newer VC-Version.

Signature

Greetings
  Jochen

   My blog about Win32 and .NET
   http://blog.kalmbachnet.de/

Holger Grund - 30 Nov 2005 12:40 GMT
>> Is it possible to add a VC++ 6 library ot a VC++ 8 application ? if yes
>> how ? is it possible to link a DLL ? how ?
>
> In general you can say:
> It is *only* possible if it only exports C functions (and has not a shared
> CRT).

Um, why? Since all references from the VC6 code are resolved
when linking the full image, I don't see how it could work if you
use things like CString internally, but export C functions only.

What's wrong with the shared CRT?
> In all other cases it is almost impossible to use an older LIB with a
> newer VC-Version.

Elaborting on that, the ABI is supposed to be stable. I.e. the exact
same source code should be binary compatible. The real problem
is the runtime library.

The MFC, ATL, STL (CRT is safe in most cases) implementations
of different VC versions are not necessarily compatible at the binary
or object level.

So, as long as you don't use any of these (regardless of whether
it's in the interface or the implementation) you have good
chances that it just works.

Also note, that the defaults for some switches, which have an
impact on the ABI, have changed (e.g. /Zc:wchar_t).

Sometimes things can be greatly simplified by wrapping the lib
in a VC6 DLL. In that case all symbols in the .lib are resolved
against the VC6 libraries. You only have to make sure, that
your interface contract does not rely on any incompatible
types.

For example:
// OK; only fundamental types
class X { public:
void foo( const char* p );
private:
   int i;
};
CString bar(); // BAD: CString binary layout & mangled
// name different in VC6 & 8

-hg
Jochen Kalmbach [MVP] - 30 Nov 2005 13:09 GMT
Hi Holger!

>>>Is it possible to add a VC++ 6 library ot a VC++ 8 application ? if yes
>>>how ? is it possible to link a DLL ? how ?
[quoted text clipped - 8 lines]
>
> What's wrong with the shared CRT?

This signatures of some CRT-function has changed... so the linker will
not be able to find it in the VC8 CRT...

>>In all other cases it is almost impossible to use an older LIB with a
>>newer VC-Version.
>
> Elaborting on that, the ABI is supposed to be stable.

Do you mean "Win32-API"? The Win32-API does not use the CRT.

> I.e. the exact
> same source code should be binary compatible. The real problem
[quoted text clipped - 3 lines]
> of different VC versions are not necessarily compatible at the binary
> or object level.

If the CRT is safe in most cases, then it cannot be used. (it must be
safe in ALL cases to be used).

> So, as long as you don't use any of these (regardless of whether
> it's in the interface or the implementation) you have good
> chances that it just works.

Yes, but I do not want to check if a CRT-function is safe for VC6-8!
Therefor we have a LIB for every compiler-version!

> Also note, that the defaults for some switches, which have an
> impact on the ABI, have changed (e.g. /Zc:wchar_t).
[quoted text clipped - 4 lines]
> your interface contract does not rely on any incompatible
> types.

And you have to be sure that you do not reply on the shared-CRT.

Signature

Greetings
  Jochen

   My blog about Win32 and .NET
   http://blog.kalmbachnet.de/

Holger Grund - 30 Nov 2005 15:00 GMT
>> What's wrong with the shared CRT?
>
> This signatures of some CRT-function has changed... so the linker will not
> be able to find it in the VC8 CRT...

Ok, I see. I believe that's just one of the things I've mentioned below.
But what is different about the _shared_ CRT here? Wouldn't you
see the same issue for the static CRT?

>>>In all other cases it is almost impossible to use an older LIB with a
>>>newer VC-Version.
>>
>> Elaborting on that, the ABI is supposed to be stable.
>
> Do you mean "Win32-API"? The Win32-API does not use the CRT.

I'm actually talking about the "Application Binary Interface", which
amongst other things specifies calling conventions, binary layout
of non-POD types and name mangling.

> If the CRT is safe in most cases, then it cannot be used. (it must be safe
> in ALL cases to be used).

I'm fairly certain you can just give it try. If the linker doesn't complain,
everything's fine. Also, there are far reaching provisions in the C
Standard that effectively guruantee object-level symbol names.
Yes, I know it's not 100% safe.

>> So, as long as you don't use any of these (regardless of whether
>> it's in the interface or the implementation) you have good
>> chances that it just works.
>
> Yes, but I do not want to check if a CRT-function is safe for VC6-8!
Me neither.

> Therefor we have a LIB for every compiler-version!

Yes sure, ideally you'd rebuild the .libs with VC8.

>> Also note, that the defaults for some switches, which have an
>> impact on the ABI, have changed (e.g. /Zc:wchar_t).
[quoted text clipped - 6 lines]
>
> And you have to be sure that you do not reply on the shared-CRT.

Now, you lost me again. Since the DLL is fully (statically) linked and
remaining references are resolved against the VC6 CRT, I fail to see
any problem with the _shared_ CRT (oc, you need to respect the normal
rules such as, calling free from the same module as calling malloc etc.)

-hg

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.