...I know it is not required so long as the methods are tagged __declspec(dllexport). However, if the client code is a .Net C# app, I can only seem to recognize the methods' entry points if the DLL was built using a .def file. Can anyone confirm or refute the need for building a DLL with a .def file if the intended client will be unable to link to the import library Thanks in advance.
--Doug Hettinger

Is a .def File Required To Export Functions From DLL?...
ASharif
To see the exports of a DLL just load the DLL in the dependencies viewer (DEPENDS.EXE).
If using declspec export and the function belongs to a C++ namespace you have to take care about the name mangeling. May be you have to use extern "C".
Aspera
Yes you can! As you can use any of the system DLLs you can use custom written C++ DLL's too.
The problem with declspec(export) is that the function name still has a leading '_'!
Using the def file you can define your name without a _!
deadeye
When i tried to use that, I received the following error:
Unable to find an entry point named fnSampleDLL in DLL E:\DotNet\Test\SampleDLL\
Debug\SampleDLL.dll.
I was able to call this function, after defining a module definition file (.def).
Please help me,
Thanks in Advance.
Will McAfee
EddieR
I created a VS.NET 2003 VC++ Win32 DLL project with the Export Symbols option checked. The Wizard generated a sample .cpp / .h with a __declspec(dllexport) class and function.
In your previous reply, you told that dlls can be used in a C# application even functions are not explicitly exported using module definition (.def) file. I tried calling the created dll from C# console application with the DllImport attribute, It failed throwing the above error (see my previous reply).
But i was able to call the function when i defined that function name in the .def file. Which makes it true that If we can't to use function in the dll which has been exported using __declspec(dllexport) and not exported in the .def file.
So if we want to call a c++ dll function from a c# code, that function needs to be specified with __declspec(dllexport) and also need to mentioned in the .def file.
Code:
file.cpp
//...
__declspec(dllexport) int fnSampleDLL(void)
{
return 42;
}
//...
Please confirm my understanding. Thanks for your reply.
Thanks in Advance.