Win32 DLL def file question

K

Kid

Hi

How can we export Win32 dll functions for dynamically LoadLibrary and
GetProceeAddress ?

I see VS MFC DLL project has a def file but Win32 DLL does not have one,
should we add a def file to VS Win32 DLL project , how can I do that ?

Thank you .
 
B

Ben Voigt [C++ MVP]

Cholo said:
There is another method to export functions apart from def file:
keyword __declspec(dllexport)

But if you want control over the exported names (no mangling) then you must
use a .def file.

Simply specify the file you create under Project Properties -> Linker ->
Input -> Module Definition File
 
D

David Connet

But if you want control over the exported names (no mangling) then you
must use a .def file.

Not necessarily. Inside my dll cpp file, I have:
extern "C" __declspec(dllexport) IMyInterface* GetMyInterface()
{
return new MyInterfaceImpl();
}

No def file in sight. (Well, actually there is - but there are no exports
in it - I think I just forgot to remove it after using the wizard to
create the project)

To get the interface:
GETMYINTERFACE func = reinterpret_cast<GETMYINTERFACE>(GetProcAddress
(m_hDllInst, "GetMyInterface"));

where GETMYINTERFACE (defined in the header with IMyInterface) is:
typedef IMyInterface* (*GETMYINTERFACE)();

Now, if you want to specifically export a function at a set ordinal (is
that still possible, or am I just having win16 flashbacks?), you need a
def file.

Dave Connet
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top