Advertisement

Help me with dll-s please!

Started by January 23, 2002 02:01 PM
4 comments, last by tSG 23 years, 1 month ago
Hey, I am in a rather strange situation. After the start my program has to get a dll from a package file, write it to the winchester and load it as a dll and work from it. How could I do that efficiently? It would be great if I didn''t have to write a def file for each of my classes and functions(a few hundreds... And it would be also good if I didn''t have to call GetProcAddress to every functions (the same reason) However if there aren''t any good methods I have to make it. In this case how can I import the classes and their functions? So far I have always used __declspec(dllexport) - VisualC - and everthing was OK without any initializations, so I don''t know too much about dll-s. Thanks in advance -- tSG --
-- tSG --
I''m sorry but I think you have to do alot of GetProcAddress
I don''t know a better method.

__declspec(dllexport) has to be done _inside_ the dll.
from outside the dll, eg the program that will use that library, you need to have __declspec(dllimport) instead.

For instance, imagine that your dll defines a function which is "void my_func(void)" :
Inside the dll workspace, this must be declared :
__declspec(dllexport) void my_func(void);
And outside the dll workspace (eg in workspaces that uses this library), the function must be seen as is :
__declspec(dllimport) void my_func(void);
Advertisement
quote:
Original post by vincoof
I''m sorry but I think you have to do alot of GetProcAddress
I don''t know a better method.

For instance, imagine that your dll defines a function which is "void my_func(void)" :
Inside the dll workspace, this must be declared :
__declspec(dllexport) void my_func(void);
And outside the dll workspace (eg in workspaces that uses this library), the function must be seen as is :
__declspec(dllimport) void my_func(void);


Yeah, that''s what I knew But that doesn''t work with GetProcAddress. How can I "rebuild" a class (its functions) with GetProcAddress? I say "rebuild", because it seems me that I have to get the addresses of the functions of the classes...


-- tSG --
-- tSG --
Winchester - I remember those! I''m obviously too old

-
"I do not approve of anything that tampers with natural ignorance. Ignorance is like a delicate exotic fruit. Touch it and the bloom is gone."
Lady Bracknell in "The Importance of being Earnest" by Oscar Wilde
The usual way of doing this is to use an abstract class that your class is derived from. Then you create an allocation function that is the only thing you need to use GetProcAddress on from the DLL. ie

in the calling program:
class AbstractTest {
public:
virtual int MyFunc() = NULL;
};

in the DLL:
class Test : public AbstractTest {
public:
virtual int MyFunc() { return 0; }
};

export only:

AbstractTest *CreateTest();

which is define as:

AbstractTest *CreateTest()
{
return new Test;
}

Hope that helps

-
"I do not approve of anything that tampers with natural ignorance. Ignorance is like a delicate exotic fruit. Touch it and the bloom is gone."
Lady Bracknell in "The Importance of being Earnest" by Oscar Wilde
You shouldn''t have to use GetProcAddress on the member functions of your class. One thing that you can do, is to have a function that creates an instance of the class and returns a pointer to it. Then you should be able to access all of the members of that class like normal.
If most of your code is not in classes, then you will most likely be stuck using GetProcAddress for every function.

j.w.

This topic is closed to new replies.

Advertisement