You are here:

C++/using DLL


I writes C program, How can I call functions of dynamic- link- library (in format .EXE)

Oddly this is not a C++ or even a C question! It is a platform specific question. In this case I presume you are using a Microsoft operating system as you talk of DLLs and EXEs.

First, functions that can be called from a dynamic link library have to be exported from the called library and imported to the module (DLL or EXE).

Second, usually a .EXE file represents an application executable module and not a shared library - and so has no exported functions.

Assuming you are using a Microsoft compiler, you use special Microsoft extensions to C and C++ to export and import dll functions - and you link your module (DLL or EXE) against the dll's import library - a static library file with the extension .LIB that allows you to link against the exported functions you wish to call but will redirect the call to the real function in the dll at run time. They are generated by the Microsoft linker. The special syntax specifics are:

       __declspec( dllimport ) <declarator>
       __declspec( dllexport ) <declarator>

where <declarator> represents a C or C++ expression declaring the entity (function or data) to be exported or imported. This syntax is the current syntax for the Visual C++ .NET compiler editions. Previous versions used the __export keyword instead of the dllexport syntax.


       __declspec( dllexport ) void MyFunction(); // In called code
       __declspec( dllimport ) void MyFunction(); // in calling code

The other way to specify exported functions is to use a linker .DEF file.

Note that the above information relates only to Microsoft compilers and linkers. Other products may do things differently or not support these extended features at all.

The other way to call functions in a DLL is to do it totally dynamically at runtime. You do this using the Win32 API functions to locate and load a DLL and bind functions to function pointers such as LoadLibrary/LoadLibraryEx, GetProcAddress, GetModuleFileName/GetModuleFileNameEx etc...

Full information on all these topics can be found in the MSDN library, which (if you do not have a local copy) can be found online at Library is an option on the rollover bar at the top of the page. As the information is quite detailed I shall not go into it here further.  


All Answers

Answers by Expert:

Ask Experts


Ralph McArdell


I am a software developer with more than 15 years C++ experience and over 25 years experience developing a wide variety of applications for Windows NT/2000/XP, UNIX, Linux and other platforms. I can help with basic to advanced C++, C (although I do not write just-C much if at all these days so maybe ask in the C section about purely C matters), software development and many platform specific and system development problems.


My career started in the mid 1980s working as a batch process operator for the now defunct Inner London Education Authority, working on Prime mini computers. I then moved into the role of Programmer / Analyst, also on the Primes, then into technical support and finally into the micro computing section, using a variety of 16 and 8 bit machines. Following the demise of the ILEA I worked for a small company, now gone, called Hodos. I worked on a part task train simulator using C and the Intel DVI (Digital Video Interactive) - the hardware based predecessor to Indeo. Other projects included a CGI based train simulator (different goals to the first), and various other projects in C and Visual Basic (er, version 1 that is). When Hodos went into receivership I went freelance and finally managed to start working in C++. I initially had contracts working on train simulators (surprise) and multimedia - I worked on many of the Dorling Kindersley CD-ROM titles and wrote the screensaver games for the Wallace and Gromit Cracking Animator CD. My more recent contracts have been more traditionally IT based, working predominately in C++ on MS Windows NT, 2000. XP, Linux and UN*X. These projects have had wide ranging additional skill sets including system analysis and design, databases and SQL in various guises, C#, client server and remoting, cross porting applications between platforms and various client development processes. I have an interest in the development of the C++ core language and libraries and try to keep up with at least some of the papers on the ISO C++ Standard Committee site at


©2017 All rights reserved.