Solved

same function, two different parameter sets for external dll?

Posted on 2006-10-19
10
191 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
 

Author Comment

by:rhaak
Comment Utility
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
Comment Utility
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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 

Author Comment

by:rhaak
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
No, misunderstanding on my side, sorry ;o)
0
 

Author Comment

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

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
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.

743 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now