Search notes:

Creating a DLL with a .def file

The following files try to be a minimal example on how to create a DLL with the Visual C compiler and a .def file.

dll.def

The def file (dll.def) lists the exported functions. We only have one exported function (add).
LIBRARY the
EXPORTS
  add
Github repository about-cl, path: /dll/def/dll.def

dll.c

dll.c is the c source file for the dll with the exported function add. Note how the function is declared with the __stdcall calling convention.
#include "dll.h"

int __stdcall add(int a, int b) {
  return a+b;
}
Github repository about-cl, path: /dll/def/dll.c

dll.h

dll.h is the header file which is needed for the executables that use the DLL.
int __stdcall add(int, int);
Github repository about-cl, path: /dll/def/dll.h

main.c

main.c is used to create the executable that uses the dll.
#include <stdio.h>
#include "dll.h"

int main() {

  printf("18+24 = %d\n", add(18, 24));

}
Github repository about-cl, path: /dll/def/main.c

Makefile

This make file (to be invoked with nmake) creates the dll and the executable that uses the dll.
all: the.dll main.exe

main.exe: main.c
	@cl /nologo main.c the.lib

the.dll: dll.obj
	@link /nologo /dll dll.obj /def:dll.def /out:the.dll

dll.obj: dll.c
	@cl /nologo /c dll.c /Fodll.obj

clean:
	@if exist *.obj del *.obj
	@if exist *.dll del *.dll
	@if exist *.exe del *.exe
	@if exist *.exp del *.exp
	@if exist *.lib del *.lib
Github repository about-cl, path: /dll/def/Makefile

Index

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/Windows/...', 1737183646, '18.226.150.171', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/Windows/development/Portable-Executable/DLL/export-table/def-file/create-dll(110): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78