May 09, 2024, 03:38:55 AM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


DLL creation and calling

Started by Barney, July 05, 2007, 08:04:06 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Barney

July 05, 2007, 08:04:06 PM Last Edit: July 05, 2007, 08:09:43 PM by Barney
I am working on a larger project where I want to keep a bunch of related functions in one or more DLL's. All of the functions are now finished and when they reside in a large include file everything is working as expected. I have created a DLL file containing all the functions I need and I also created the necessary LIB file and INC file with all the relevant declarations. Everything has been done with the latest (1.59) version of EBasic.

Unfortunately when I try to create my main application the process stops during the linking phase when I get the "Unable to detect format of ...." error by the linker. Oddly enough when I try to use the same DLL (created by EBasic) in Aurora everything works perfectly. I've tried to reinstall EBasic, then I've tried using LIB files created by Aurora just to find out they are the same as those created by EBasic, and finally I even try to use Aurora's linker in place of EBasic's linker. Nothing helped and I am now stuck. Yes. I know I can rewrite everything in Aurora but that is something I am not (yet) prepared to do.

So... I created some example files and tested again, only to get the same errors, which leads me to believe that either I am doing something completely wrong or there's a bug somewhere in EBasic. Here are my test files.

This file (MyDLL2.eba) is used to create DLL:

EXPORT iFun1
EXPORT iFun2

SUB iFun1(INT iVar1, INT iVar2),INT
RETURN iVar1+iVar2
ENDSUB

SUB iFun2(INT iVar1),STRING
RETURN STR$(iVar1)
ENDSUB


and this one (MyDLL2.eba) is used to create the DLL where CDECL type of call is used:

EXPORT iFun1
EXPORT iFun2
DECLARE CDECL iFun1(INT iVar1, INT iVar2),INT
DECLARE CDECL iFun2(INT iVar1),STRING

SUB iFun1(INT iVar1, INT iVar2),INT
RETURN iVar1+iVar2
ENDSUB

SUB iFun2(INT iVar1),STRING
RETURN STR$(iVar1)
ENDSUB


Main file that uses the "MyDLL1.DLL"

$USE "MyDLL1.LIB"
DECLARE IMPORT, iFun1(INT iVar1,INT iVar2),INT
DECLARE IMPORT, iFun2(INT iVar1),STRING

OPENCONSOLE
PRINT "iFun1: ",STR$(iFun1(3,4))
PRINT "iFun2: ",iFun2(555)

PRINT "Press any key to quit"
DO: UNTIL INKEY$ <> ""
CLOSECONSOLE
END


and main file that uses the "MyDLL2.DLL":

$USE "MyDLL2.LIB"
DECLARE CDECL IMPORT, iFun1 ALIAS iFun1(INT iVar1,INT iVar2),INT
DECLARE CDECL IMPORT, iFun2 ALIAS iFun2(INT iVar1),STRING

OPENCONSOLE
PRINT "iFun1: ",STR$(iFun1(3,4))
PRINT "iFun2: ",iFun2(555)

PRINT "Press any key to quit"
DO: UNTIL INKEY$ <> ""
CLOSECONSOLE
END


and finally this is the main Aurora file that uses the "MyDLL2.DLL" created by the EBasic:

#use "MojDLL2.lib"

declare cdecl import, iFun1(int iVar1,int iVar2),int;
declare cdecl import, iFun2(int iVar1),string;

global sub main()
{
print("iFun1: "+NumToStr(iFun1(3,4),10));
print("\niFun2: "+iFun2(555));
print("\n\npress any key to close");
While GetKey() = "";
}


I'd be very happy if someone can shed some light on this.
Just don't tell me that it works without problems with your setup as I am going to kill my self in that case. ;)

Barney

Ionic Wind Support Team

Delete the .lib files (in the libs directory) and try again.

The DLL's have to be in the same path as your executable.

Finally if you plan on using both DLL's at once you'll need to make sure to pick different load addresses.

Paul.
Ionic Wind Support Team

Barney

Quote from: Paul Turley on July 05, 2007, 08:58:18 PM
Delete the .lib files (in the libs directory) and try again.

I have done it numerous times. No luck.

QuoteThe DLL's have to be in the same path as your executable.

Yes, they are in the same directory.

QuoteFinally if you plan on using both DLL's at once you'll need to make sure to pick different load addresses.

Yes. I know that. It is stated clearly in the docs anyway. Two DLL's are here just because I wanted to test it with and without CDECL calling type and it is quite obvious calling format is not the problem.

I remember having that particular linker problem a couple of times before but it was always "fixed" by reinstalling EBasic. This time, however, it persists and won't go away. I'll try it on another computer and if everything else fails I'll try it with IBasic Pro. Perhaps that will help.

Barney

Barney

I've just tested it with freshly installed IBasic Pro (first time on this machine) and got the same error. Here's what the build window says...

Compiling...
MyDLL.iba
No Errors

Linking...
IBasic Linker v1.0 Copyright 2003-2005 Pyxia Development
Unresolved external __imp_iFun1
Error: Unable to detect format of C:\Program Files\IBDev\Libs\MyDLL1.LIB
Error: Unresolved extern __imp_iFun1
Error: Unresolved extern __imp_Fun2
Error(s) in linking c:\Barney\IBasic\TestDLL\MyDLL.exe

When I use EBasic the error messages are exactly the same.

Aurora works without problems.

Barney

sapero

Barney, just change the extension in "MyDLL1.LIB" to lower case, i know this problem too :) The linker does not know what is 'LIB', but know what is 'lib' :/
So, $USE "MyDLL1.lib" will work.

pistol350

Yep! Sapero is right!
It works perfectly now!
Regards,

Peter B.

Barney

Thank you, thank you, thank you...  ;D

I would probably stumble on this solution sometime in the next thousand years.

Sapero, if you ever decide to visit Croatia let me know. Dinner's on me.  8)

Barney