Jump to content
  • Advertisement
Sign in to follow this  
Ohmy

I need help FAST!!!

This topic is 5414 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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
};


Share this post


Link to post
Share on other sites
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...

Share this post


Link to post
Share on other sites
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...

Share this post


Link to post
Share on other sites
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();

Share this post


Link to post
Share on other sites
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; }

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!