Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

same function, two different parameter sets for external dll?

Posted on 2006-10-19
10
Medium Priority
?
200 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 1000 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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 1000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
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 tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

824 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