After testing a few your dll file with a basic C program (using only the Windows APIs), I've got a few troubles with the cdecl calling convention.
So, I suggest you to declare your functions with the (Windows usual) stdcall convention. No more problems with it, at least for me.
Modification of your dll source code (add the stdall convention to each of your functions):
Library minmax;
uses crt,
windows;
function min(x,y: integer):integer; stdcall;
begin
if x < y then Min:= x else min := y;
end;
function max(x,y: integer): integer; stdcall;
begin
if x > y then max:= x else max:= y;
end;
procedure beep; stdcall;
begin
sound(220);
delay(200);
nosound;
end;
exports
min index 1,
max index 2,
beep index 3;
begin
end.
And attached the very simple C program to test your dll (I've included the exe file -32 bits version-, in case you can't compile the C source code).
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <Windows.h>
typedef long int (__stdcall * FUNC_MIN) (long int, long int);
typedef long int (__stdcall * FUNC_MAX) (long int, long int);
typedef void (__stdcall * FUNC_BEEP) ();
void main()
{
HMODULE DllHandle;
FUNC_MIN FuncMin;
FUNC_MAX FuncMax;
FUNC_BEEP FuncBeep;
// Dll Loading
DllHandle = LoadLibrary("MINMAX.DLL");
printf("\r\n");
if (DllHandle == NULL)
printf("** ERROR ** Can't load MINMAX.DLL. Error = %d \r\n", GetLastError());
else
{
printf("Dll loaded. \r\n");
// Getting Functions Addresses
FuncMin = (FUNC_MIN) GetProcAddress(DllHandle, "min");
if (FuncMin == NULL)
printf("** ERROR ** Can't find min function. Error = %d \r\n", GetLastError());
else
printf(" min function found. \r\n");
FuncMax = (FUNC_MAX) GetProcAddress(DllHandle, "max");
if (FuncMax == NULL)
printf("** ERROR ** Can't find max function. Error = %d \r\n", GetLastError());
else
printf(" max function found. \r\n");
FuncBeep = (FUNC_BEEP) GetProcAddress(DllHandle, "beep");
if (FuncBeep == NULL)
printf("** ERROR ** Can't find beep function. Error = %d \r\n", GetLastError());
else
printf(" beep function found. \r\n");
// Testing functions
printf("\r\n");
if (FuncMin)
printf(" min of 29 and 54 = %ld \r\n", FuncMin(29 ,54));
if (FuncMax)
printf(" max of 12 and 109 = %ld \r\n", FuncMax(12 ,109));
if (FuncBeep)
{
printf(" beep");
FuncBeep();
}
printf("\r\n");
// Dll Closing
FreeLibrary(DllHandle);
}
}