?
Solved

same function, two different parameter sets for external dll?

Posted on 2006-10-19
10
Medium Priority
?
198 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 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
Technology Partners: 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 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

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
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.
Suggested Courses
Course of the Month10 days, 12 hours left to enroll

765 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