Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / desktop / MFC

Mangling issues - VC 6.0 and VC 8.0

1.78/5 (3 votes)
24 Jun 2007CPOL2 min read 1  
How mangling changes in VC++ 6.0 and VC 8.0 can cause problems in your existing application and how to solve it.

Introduction

We all know that mangling or name decoration is compiler specific. And the new VC 8.0 is no different. They have come up with a new mangling scheme which created problems in one of our recent projects. The issue was because of the difference in mangling scheme these compilers have. Well, I won't get into the details of the VC 8.0 mangling scheme here. But what if there is a situation wherein you have to use an MFC extension DLL built using VC 8.0, in a VC 6.0 project?

Problem Description

We have an MFC extension DLL (a DLL from which you can export a class) built using VC 8.0, and we want to use that DLL in a VC 6.0 project. Now, if I want to use that extension DLL in my VC 6.0 project, all that I need to do is to add the header file in which we have the class and its member declaration and the lib file that will be used during linking time.

We expect everything to go well, but when you build the VC 6.0 application, you will get an error saying unable to link to a class member function which we are calling from our VC 6.0 application. The problem here is VC 6.0 will create a mangled version of the class member function which we have specified in the header file and it will try to match with the one in the lib file. Unfortunately, the decorated version of your lib and the one which is generated by VC 6.0 do not match.

How do we solve this? In the MSDN article titled 'Old-Style Name Mangling for Exported Template Instantiations', Microsoft suggests a way to include both mangling schemes in the linker command line option. In-order to do that, we have to identify the mangled version of the class member function from the lib, by dumping the exports or opening it in Notepad and the VC 6.0 generated mangled version (which you will get as a linker error when you build your VC 6.0 application ;-) ). Include this along with the VC 8.0 generated mangled version of the member function which you are trying to call.

For example:

/export: <VC 6.0 decorated version>=<VC 8.0 decorated version>

Image 1

Save it and build the application. Now your lib will generate two decorated versions for the same class member function, one based on the VC 6.0 mangling scheme (which we got as a linker error) and the other based on the VC 8.0 mangling scheme (which we identified by checking the lib). Now use this lib and build the VC 6.0 application. You should be able to successfully link the application.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)