Potrzebuję użyć biblioteki 16-bitowej. Udało mi się uruchomić ją w VB 4.0.
Declare Function CalcSum Lib "C:\Calc.DLL" _
(ByVal in_x As Double, ByVal in_y As Double, _
ByVal in_type As Integer, ByRef err As Integer) As Double
Natomiast uruchomianie kodu:
#include <windows.h>
#include <stdio.h>
// DLL function signature
typedef double (*importFunction)(double, double, int, int &);
int main(int argc, char **argv)
{
importFunction addNumbers;
int err;
double result;
// Load DLL file
HINSTANCE hinstLib = LoadLibrary("C:\\Calc.dll");
if (hinstLib == NULL) {
printf("ERROR: unable to load DLL\n");
return 1;
}
// Get function pointer
addNumbers = (importFunction)GetProcAddress(hinstLib,"CalcSum");
if (addNumbers == NULL) {
printf("ERROR: unable to find DLL function\n");
FreeLibrary(hinstLib);
return 1;
}
// Call function.
result = addNumbers(1, 2, 1, err);
// Unload DLL file
FreeLibrary(hinstLib);
// Display result
printf("The result was: %f\n", result);
return 0;
}
w VC++ 1.52 powoduje:
TestDll caused a general protection fault
in module CALC.DLL at 0001:000000a1.
Registers:
EAX=4d0f0001 CS=4d0f EIP=000000a1 EFLGS=00000206
EBX=00000000 SS=36cf ESP=0000354a EBP=00003582
ECX=00003568 DS=36df ESI=000000f0 FS=0000
EDX=00003570 ES=0000 EDI=00003818 GS=0000
Bytes at CS:EIP:
26 89 07 8d 5e e6 90 36 dd 07 90 dc 16 ca 0a 90
Stack dump:
00f036cf fae53818 3dadcca9 e93f3f8c ebe93e93 0000406f 0000147f 00000000 00000000 00010000 cca9fae5 3f8c3dad 3e93e93f 406febe9 00a135b2 0000365f
Czy to jest problem przekazania parametrów?