A few questions about dlls
1) Can you create an object within a dll for use outside of the dll? (and if so, how/where do you declair it?)
2) Ok, I''m sorry, that only one question, but it''s the biggest on my mind right now
You might be able to do it with an exported function from the DLL that will return a pointer to the object.
Like this:
It should work since both the DLL and the main application are running under the same process. There's a probably an easier (and more logical) way of doing this, but... this will work
[EDIT] Forgot, you will need to put the object in the DLL in a shared data segment, like so:
#pragma data_seg("Shared") // Shared data segment
MYOBJECT *hello = NULL; // always init it
#pragma data_seg() // end of shared data segment
And now the function will be:
extern "C" void __declspec(dllexport) somefunc(MYOBJECT *outMO)
{
hello = new MYOBJECT;
// do stuff to the object
outMO = hello;
}
- Goblineye Entertainment
The road to success is always under construction
Edited by - Tornado on October 3, 2001 10:27:27 AM
Like this:
// this is the dllextern "C" void __declspec(dllexport) somefunc(MYOBJECT *outMO){ MYOBJECT *hello = new MYOBJECT; outMO = hello;}// this is the applicationMYOBJECT *getobject;somefunc(getobject);
It should work since both the DLL and the main application are running under the same process. There's a probably an easier (and more logical) way of doing this, but... this will work
[EDIT] Forgot, you will need to put the object in the DLL in a shared data segment, like so:
#pragma data_seg("Shared") // Shared data segment
MYOBJECT *hello = NULL; // always init it
#pragma data_seg() // end of shared data segment
And now the function will be:
extern "C" void __declspec(dllexport) somefunc(MYOBJECT *outMO)
{
hello = new MYOBJECT;
// do stuff to the object
outMO = hello;
}
- Goblineye Entertainment
The road to success is always under construction
Edited by - Tornado on October 3, 2001 10:27:27 AM
In MSVC++ you can simply declare a class with __declspec(dllexport) in the dll code, and declare the same class with __declspec(dllimport) in the module that uses the dll.
Your code won''t be portable though.
Your code won''t be portable though.
Thanks again! But I must ask, why would that code not be portable? I could simply make a header with all those imports in it, call it from my main dll and put a definition statment to make sure it isn''t done while compilling the dll.
In any case, I beleive I will be designing the dll with a few access functions for the app to use, and have most of the processes hidden.
What would be the advantages and disavantages of hidding most of the functions in a dll anyway?
In any case, I beleive I will be designing the dll with a few access functions for the app to use, and have most of the processes hidden.
What would be the advantages and disavantages of hidding most of the functions in a dll anyway?
It''s not portable because __declspec() is not a part of the C++ standard. It''s a Microsoft extension.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement