Solved

same function, two different parameter sets for external dll?

Posted on 2006-10-19
10
195 Views
Last Modified: 2010-04-01
We have a dll written in C++ that is used in several external applications.  The external functions work fine, but there is a serious compatibility issue and I'm trying to figure out a way around it.  Here's the current situation (please ignore pseudo-syntax because it's not the issue here):

dllinterface.h:
Version A:
extern myFunction (parameter1, parameter2, parameter3)

Version B:
extern myFunction (parameter2, parameter2, parameter2a, parameter3)

Parameters 1, 2, and 3 are identical, but Version B has an extra parameter stuck in the middle.  Is there any way I can come up with a Version C that supports both versions of myFunction?  In other words, can I have two function definitions for the same function, and depending on how many parameters there are, decide which definition I should use???  Changing the names of one of the functions is not an option.  Right now we're just supporting both versions of the dll but that is becoming next to impossible due to the number of applications that are using this dll.


0
Comment
Question by:rhaak
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
  • 2
10 Comments
 
LVL 48

Assisted Solution

by:AlexFM
AlexFM earned 250 total points
ID: 17765030
Such problem can be solved using overloaded functions.

void myFunction (parameter1, parameter2, parameter3);

Now you need to write Dll with new version which contains 4 parameters:

void myFunction (parameter1, parameter2, parameter3)
{
    MyFunction(parameter1, parameter2, default value of parameter2a, parameter3);
}

void myFunction (parameter1, parameter2, parameter2a, parameter3)
{
    // implementation
}

In new Dll version, actual implementation is moved to new version of function. Library still supports old function, and allows to call new function.
0
 

Author Comment

by:rhaak
ID: 17765175
Excellent!!!  I really didn't think there was an easy way around this.  Should the .h file contain both function definitions?  We have two .h files that specify the function definition, the first specifically for this dll and the second that contains the external definitions for several dlls.  The compilier didn't complain about the two definitions for the first .h file I mentioned, but I received the following error from the second .h file: "second C linkage of overloaded function not allowed"
0
 
LVL 48

Expert Comment

by:AlexFM
ID: 17765355
Yes, unfortunately this doesn't work for C functions. This works for class members and for functions exported from Dll without extern "C". Wait for some other suggestions.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:rhaak
ID: 17767550
AlexFM, thanks for the post - it got me on the right track.  I've tried several things and will ask the question in a different way...

************
Is it possible to export overloaded functions to a dll for use in VB?
************

I've removed the 'extern "C"' so that the functions have unique decorated names, but when I attempt to list those in the EXPORTS section of the def file I get a warning that the function is defined twice and it will always use the first definition.  I'm not even sure that what I'm trying to do is possible.
0
 
LVL 86

Accepted Solution

by:
jkr earned 250 total points
ID: 17770660
Unfortunately, you cannot. Each exported functin is a DLL needs an unique name (that's where C++ name decoration kicks in) But, if you can live with decorated export names, why not using 'myFunction1' and/or 'myFunction2'?
0
 

Author Comment

by:rhaak
ID: 17770934
I may be using the wrong terms, but I meant that they have unique decorated names within C++.  I want to use the basic function name from VB.  Two different function names aren't possible, so it looks like I'm going to have to live with the existing compatibility issues.
0
 
LVL 86

Expert Comment

by:jkr
ID: 17770989
Well, if they have unique decorated names, they have the same parameter list (that's what name decration is for). Something might have gone wrong then...
0
 

Author Comment

by:rhaak
ID: 17772875
By unique decorated names I mean that they have different decorated names - the parameter lists are different.  I guess I don't understand the comment???
0
 
LVL 86

Expert Comment

by:jkr
ID: 17775706
No, misunderstanding on my side, sorry ;o)
0
 

Author Comment

by:rhaak
ID: 17787933
I accepted the answers because I found out for certain that this isn't possible.  Thanks for the help!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question