Guys,
Thanks everyone for the help. I managed to partially solve my problem in the following way:
I created the following BAS file, with code in FreeBasic (that I found on the Internet)
1 2 3 4 5
|
DECLARE SUB TestInteger lib "DLL_test" alias "TestInteger" (byval myData AS Integer)
SUB TestInteger (byval myData AS Integer) EXPORT
print "In FreeBasic your integer = " , myData
END SUB
|
The C++ code is similar to the one I have already posted here...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
|
#include <windows.h>
#include <stdio.h>
#include <iostream>
typedef VOID (CALLBACK* LPFNDLLFUNC1)(UINT);
using namespace std;
int main()
{
HINSTANCE hDLL; // Handle to DLL
LPFNDLLFUNC1 lpfnDllFunc1; // Function pointer
UINT uParam1;
uParam1 = 32;
hDLL = LoadLibrary("DLL_test.dll");
if (hDLL != NULL)
{
lpfnDllFunc1 = (LPFNDLLFUNC1)GetProcAddress(hDLL, "TestInteger@4");
if (!lpfnDllFunc1)
{
// handle the error
FreeLibrary(hDLL);
cout << "Error code: " << GetLastError() << "\n";
system("PAUSE");
return -1;
}
else
{
// call the function
lpfnDllFunc1(uParam1);
system("PAUSE");
}
}
FreeLibrary(hDLL);
return 0;
}
|
I downloaded and installed the FreeBasic compiler (
http://www.freebasic.net/index.php) and created a DLL from the Basic code using the following command
fbc -dll "c:\documents and settings\DLL_test.bas" |
The dll was successfully created and I could sucessfully run my code in C++, giving me the output I wanted.
However, like I said, it didn't solve my problem entirely because the code I have to use in my C++ code is QBasic, not FreeBasic.
So, I converted the code in FreeBasic to QBasic, having as a result the following...
1 2 3 4 5
|
DECLARE SUB TestIntegerQB lib "DLL_test_QB" alias "TestIntegerQB" (myData%)
SUB TestIntegerQB (myData%)
print "In QuickBasic your integer = " , myData%
END SUB
|
I also changed what I needed in the C++ code (changed the name of the DLL to be loaded and the name of the function appropriately). I tried to generate the DLL with the QB code with the following command:
fbc -lang qb -dll "c:\documents and settings\DLL_test_QB.bas" |
and got the following error
dlltool.exe: Syntax error in def file: C:\Documents and Settings\DLL_test_QB.def:0
|
The 'def' file is shown bellow:
1 2 3
|
LIBRARY DLL_test_QB
EXPORTS
TestIntegerQB @1
|
Does anyone know why I received this error message?
Thanks in advance,
Leonel