Der Aufruf von C -Funktionen von VBA aus
Definition in C
long _stdcall testlib(long const x) { return x << 1; }
TESTDLL.C
#include <stdio.h>
int _stdcall LibMain(void *hinstDll,unsigned long dwReason,void *reserved)
{ return(1); }
long _stdcall testlib(long const x)
{ return x << 1;
/* fprintf(stdout,"In dll: argument=%d\n",arg); */ }
Eintrag in .def-Datei
TESTDLL.DEF
LIBRARY testdll
EXPORTS
testlib
TestEnv
Make-Fragmente
Makefile für lccwin32
MAKEFILE
test.exe:⇥test.obj testdll.lib makefile
⇥lcclnk test.obj testdll.lib
test.obj:⇥test.c
⇥lcc -O -g2 test.c
testdll.lib:⇥testdll.dll testdll.def
⇥implib testdll.dll
testdll.dll:⇥testdll.obj testdll.def
⇥lcclnk.exe -dll testdll.obj testdll.def
⇥copy testdll.dll C:\WINDOWS
⇥implib testdll.dll
testdll.obj:⇥testdll.c
⇥lcc $(COMPILERFLAGS) testdll.c
Deklaration in VBA
Private Declare Function testlib Lib "C:\testdll.dll" Alias "_testlib@4" (ByVal intN As Long) As Long
Falls die DLL im Windows-Ordner liegt, geht hinter Lib auch »"testdll"«.
Die Zahl in "_testlib@4" ist (oft?) die Zahl der Argumente multipliziert mit 4.
Aufruf in VBA
r = testlib(x)