| | |
importance of dllexport location in program
Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: May 2008
Posts: 8
Reputation:
Solved Threads: 0
Hi,
(using MS VS2005) Recently I've found that in order for a function to be exported, dllexport *must* be placed in the same file of the function body. E.g. see the following case:
File a.cpp
File b.cpp
Now, a.cpp and b.cpp compile perfectly into a dll. However a() is not exported.
From what I understand from MSDN, dllexport is supposed to substitute the export section in the .DEF file - seems that it doesn't. Is this an MS bug?
Thanks,
Gil.
(using MS VS2005) Recently I've found that in order for a function to be exported, dllexport *must* be placed in the same file of the function body. E.g. see the following case:
File a.cpp
C++ Syntax (Toggle Plain Text)
void dllexport a(); a();
File b.cpp
C++ Syntax (Toggle Plain Text)
void a() { // function body }
Now, a.cpp and b.cpp compile perfectly into a dll. However a() is not exported.
From what I understand from MSDN, dllexport is supposed to substitute the export section in the .DEF file - seems that it doesn't. Is this an MS bug?
Thanks,
Gil.
Here is an explaination of how I use it. I always use it with __declspec and don't have a problem. It does not affect the .DEF file -- actually the DEF file is not even needed when dllexport is used.
Last edited by Ancient Dragon; May 9th, 2008 at 6:04 pm.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Is b.cpp the application program that is calling the exported function in a.cpp, which is in a dll ?
In b.cpp you need to declare the function as _dllimport.
In b.cpp you need to declare the function as _dllimport.
C++ Syntax (Toggle Plain Text)
// b.cpp is the application program // _delspec(_dllimport) void a(); void foo() { a(); }
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
>>From what I understand from MSDN, dllexport is supposed to substitute the export section in the .DEF file -
Your understanding is incorrect. What MSDN means is that you can export the function in one of two ways:
The compiler does not make any entries into the .DEF file for you -- you have to do that yourself if you want them there.
Prototyping the function as you did in a.cpp is not sufficient. You have to add dllexport in the function itself
You can also export an entire c++ class
Your understanding is incorrect. What MSDN means is that you can export the function in one of two ways:
- use the __dllspec( __dllexport ) tags
- add an entry into the .DEF file
The compiler does not make any entries into the .DEF file for you -- you have to do that yourself if you want them there.
Prototyping the function as you did in a.cpp is not sufficient. You have to add dllexport in the function itself
C++ Syntax (Toggle Plain Text)
a.cpp __dllspec( __dllexport ) void a() { // blabla }
You can also export an entire c++ class
C++ Syntax (Toggle Plain Text)
__dllspec( __dllexport) class MyClass { // blabla }
Last edited by Ancient Dragon; May 10th, 2008 at 10:15 am.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
![]() |
Other Threads in the C++ Forum
- Previous Thread: Help me with txt!!!
- Next Thread: End Of File (ifstream)
Views: 1339 | Replies: 6
| Thread Tools | Search this Thread |
Tag cloud for C++
6 add api array arrays beginner binary bitmap c++ c/c++ calculator char class classes code compile compiler console conversion convert count data delete desktop directshow dll encryption error file forms fstream function functions game getline givemetehcodez google graph homeworkhelper iamthwee ifstream input int integer java lazy lib linkedlist linux loop looping loops map math matrix memory microsoft newbie news node number output parameter pointer problem program programming project proxy python random read recursion recursive reference return sort string strings struct studio system template templates test text tree unix url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






