Solved

same function, two different parameter sets for external dll?

Posted on 2006-10-19
10
194 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
  • 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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
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 learn how to clear a vector as well as how to detect empty vectors in C++.

790 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