I need help FAST!!!

Started by
9 comments, last by joanusdmentia 19 years, 7 months ago
Guys seriously i need help... I need to port a class from a .DLL I repeat a .DLL file not a .Lib file into my App. How do i accomplish this? I tried by making a function in the DLL that returns a pointer to a new created class which also works but the problem is not the pointer that is returned but rather the pointers that are associated with the classes integrated functions get it? So here i have a Class pointer but no pointer to the classes functions cause the linker can't find it...so what do i do? AnyOne Plz... Do i have to manually make function pointers to each individual class function process address? If anyone can find a tutorial that explains this...cause i'm having trouble finding one...
Advertisement
Since you can access the function in the DLL I presume you know about the __declspec(dllexport) specifier. Just apply that to your class as well. For example,
#ifdef MYDLL_EXPORTS#   define MYDLL_API __declspec(dllexport)#else#   define MYDLL_API __declspec(dllimport)#endif//.....class MYDLL_API MyExportedClass{    // as normal};
"Voilà! In view, a humble vaudevillian veteran, cast vicariously as both victim and villain by the vicissitudes of Fate. This visage, no mere veneer of vanity, is a vestige of the vox populi, now vacant, vanished. However, this valorous visitation of a bygone vexation stands vivified, and has vowed to vanquish these venal and virulent vermin vanguarding vice and vouchsafing the violently vicious and voracious violation of volition. The only verdict is vengeance; a vendetta held as a votive, not in vain, for the value and veracity of such shall one day vindicate the vigilant and the virtuous. Verily, this vichyssoise of verbiage veers most verbose, so let me simply add that it's my very good honor to meet you and you may call me V.".....V
No...that not what i meant...

I made a function in the dll that returns a new created classes pointer to my App.

The thing is.... although this pointer is a pointer to that class...that doesn't mean i can call the functions in that class..but in this state the functions in the class are not pointing to any address... So basically...

You could say that i can do the following :

#ifdef MYDLL_EXPORTS#   define MYDLL_API __declspec(dllexport)#else#   define MYDLL_API __declspec(dllimport)#endif//.....MYDLL_API MyExportedClass* CALLBACK GetClass();class MYDLL_API MyExportedClass{    void executethis();    // as normal};MYDLL_API MyExportedClass* CALLBACK GetClass(){   MyExportedClass *ThisClass = new MyExportedClass;   return &ThisClass}----------------------Later in my client app with added header file...GetClassEx = (GetClass)GetprocessAdress("My.dll","GetClass")MyExportedClass *thisone = GetClassEx();// now here is were the LINK error comes :MyExportedClass->Executethis();


So basically speaking...i have a pointer to the class but i canont accees the function beacuse....the function executethis is in the dll but is not pointed to get it?

The function executethis is not initialized...
Ok...well basically speaking...you can easily use the .lib file to do the trick but...for what i'm doing now it will require me to use a Dll...
OK..guys i may have found the solution to the problem...bt it's overkill in my own opnion :

#ifdef MYDLL_EXPORTS#   define MYDLL_API __declspec(dllexport)#else#   define MYDLL_API __declspec(dllimport)#endif//.....class MYDLL_API MyExportedClass{    void executethis();    // as normal};MYDLL_API MyExportedClass* CALLBACK GetClass(MyExportedClass *ThisClass);MYDLL_API MyExportedClass* CALLBACK GetClass(MyExportedClass *ThisClass){  ThisClass = new MyExportedClass;   return &ThisClass}----------------------Later in my client app with added header file...GetClassEx = (GetClass)GetprocessAdress("My.dll","GetClass")MyExportedClass *thisone = GetClassEx(thisone);MyExportedClass->Executethis();



OR :

#ifdef MYDLL_EXPORTS#   define MYDLL_API __declspec(dllexport)#else#   define MYDLL_API __declspec(dllimport)#endif//.....class MYDLL_API MyExportedClass{    void executethis();    // as normal};MYDLL_API MyExportedClass* CALLBACK GetClass(MyExportedClass *ThisClass);MYDLL_API MyExportedClass* CALLBACK GetClass(MyExportedClass *ThisClass){  ThisClass = new MyExportedClass;  // retrieve function pointer(haven't tried this one yet..)  ThisClass->Executethis() = MyExportedClass::Executethis();   return &ThisClass}----------------------Later in my client app with added header file...GetClassEx = (GetClass)GetprocessAdress("My.dll","GetClass")MyExportedClass *thisone = GetClassEx(thisone);MyExportedClass->Executethis();
Conversely, you can declare a base abstract class and implement the class in your DLL, and upon request return a pointer of type BaseClass* which points to an instance of your derived class.

For example,
// In your main project.class SomeBaseClass{   public:         virtual void ExecuteThis() = 0;};// In your DLL.class SomeBaseClassDLL : public SomeBaseClass{    public:      virtual void ExecuteThis() { /* implementation */ }};// And of course you'd export some function from your DLL.SomeBaseClass *CreateClass() { return new SomeBaseClassDLL; }
Hmm...that sounds interesting...now if i can just look into that...
:)
LOOL...it works.. :D thx....although it's odd to ask these kind of questions no?
Quote:Original post by Ohmy
LOOL...it works.. :D thx....although it's odd to ask these kind of questions no?


Odd? I don't see why it's odd. This is the Beginner's forum, so a question like this isn't all that bad. It's much better (as in, it's an actual programming issue) than a "hwo do i mkae a mmorpg game?!!111" thread.
I think the only problem was that your ExecuteThis function was declared private instead of public.

This topic is closed to new replies.

Advertisement