Link to home
Start Free TrialLog in
Avatar of Kantaro
Kantaro

asked on

(VC++6)how to call two functions having the same name and prototype but different in code each one is in a spirit dll ?

hi dears,
i want to link my win32 application (non-mfc) to two dlls so i did that:

1)i went to project->settings->link->object/library modules: and added the 1stDll.lib and 2stDll.lib.

2)in this two dlls there is a function each one has the same name and prtotype let's say (void func()) but they are different in code (do different jobs)

3)in my main source file (app.cpp) i imported the two functions that i want to call by writting this code:
__declspec(dllimport) void __stdcall func(); //this is the 1stDll's function
__declspec(dllimport) void __stdcall func(); //this is the 2stDll's function

but the second declreation will make an error while compiling and linking the program so i can not write it ... now how i can call these two functions from my (one .cpp source file) application even if they having the same name and prototype ? is not there any way to alias thier names ? and i can not change the dlls code or names or anything into them becouse they are allready compiled and programmed by another programmer and i do not have thier code LOL... PLZZ help
Avatar of andrewjb
andrewjb
Flag of United Kingdom of Great Britain and Northern Ireland image

You'll probably have to load them manually, via LoadLibrary and so on. Then you'll be storing pointers to the functions, and be able to call them individually.
Avatar of Kantaro
Kantaro

ASKER

guys... i can not use the LoadLibrary becouse of a perpose in my boss mind LOL .. so i just can load them from the linker and dllimport ....... PLZZ HELP
???

If your boss told you you weren't allowed to use the 'w' key on your keyboard, would you agree? If it ain't going to work without, you've no choice.

:-)
Does the functions have parameters?
Avatar of Kantaro

ASKER

may be and may be not lol ... depend on the implementation but this is a general talk .. okey leave this alone and tell me what is the c/c++ calling conv. ? is it __cdecl ? __stdcall ? and if not __stdcall tell me why in the C++/C project options there is the /Gz comiler option which is the forcing for making functions __stdcall if there is not calling conv. spec. ?
ASKER CERTIFIED SOLUTION
Avatar of GloomyFriar
GloomyFriar

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
To answer your original quest:

To the best of my knowledge this is illegal in C++, functions cannot have the same name regardless of where they are loaded from, if theyre in the same project and have the same function signiture (paramater list). Logically, this is pointless, if 2 functions had the same name, how would the program know what to call? The excetion to this however is if the function is in a class, then you could call the functions with the same name. An ex would be:

class C1
{
   void Func()
   {
      // DO this
   }
};

class C2
{
   void Func()
   {
      // DO something diff
   }
};

Then you would need to put these in the 2 different libs and then declare a variable of each class:
C1 var1;
C2 var2;

Then call them in the program:
var1.Func();
var2.Func();

**I know you asked something else as well, but I went ahead and submitted this for anyone else who had the same ques and didnt understand
-Drew
No comment has been added lately, so it's time to clean up this TA.
I will leave the following recommendation for this question in the Cleanup topic area:

Accept: GloomyFriar {http:#9753936}

Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

Tinchos
EE Cleanup Volunteer