|
Das deutsche QBasic- und FreeBASIC-Forum Für euch erreichbar unter qb-forum.de, fb-forum.de und freebasic-forum.de!
|
Vorheriges Thema anzeigen :: Nächstes Thema anzeigen |
Autor |
Nachricht |
psygate
Anmeldungsdatum: 05.04.2005 Beiträge: 304 Wohnort: Wien und der Computer
|
Verfasst am: 31.08.2005, 22:08 Titel: DLL benutzen |
|
|
Also, ich hab ein RIESEN problem meine dlls funzen ned, das programm liefert immer einen fehler zurück, dass die dll nicht gefunden wurde, kann mir jemand helfen? |
|
Nach oben |
|
|
Sebastian Administrator
Anmeldungsdatum: 10.09.2004 Beiträge: 5969 Wohnort: Deutschland
|
|
Nach oben |
|
|
Michael Frey
Anmeldungsdatum: 18.12.2004 Beiträge: 2577 Wohnort: Schweiz
|
Verfasst am: 01.09.2005, 17:59 Titel: |
|
|
Vielleicht Hilfst, ein Beispiel Programm wie man eine DLL lädt gibts im "examples", der einfachheit halber Poste ich direkt den Code:
Code: | ''
'' testload -- loads mydll at runtime, calls a mydll's function and prints the result
''
'' compile as: fbc testload.bas
''
'' note: requires the compiled mydll dynamic library to be available in current
'' directory; see mydll.bas for info on how to create this.
''
dim library as integer
dim addnumbers as function( byval operand1 as integer, byval operand2 as integer ) as integer
'' Note we specify just "mydll" as library file name; this is to ensure
'' compatibility between Windows and Linux, where a dynamic library
'' has different file name and extension.
''
library = dylibload( "mydll" )
if( library = 0 ) then
print "Cannot load the mydll dynamic library, aborting program..."
end 1
end if
addnumbers = dylibsymbol( library, "AddNumbers" )
if( addnumbers = 0 ) then
print "Cannot get AddNumbers function address from mydll library, aborting program..."
end 1
end if
randomize timer
x = rnd * 10
y = rnd * 10
print x; " +"; y; " ="; addnumbers( x, y )
'' Done with the library; the OS will automatically unload libraries loaded by a process
'' when it terminates, but we can also force unloading during our program execution to
'' save resources; this is what the next line does. Remember that once you unload a
'' previously loaded library, all the symbols you got from it via dylibsymbol will become
'' invalid, and accessing them will cause the application to crash.
''
dylibfree library |
Anderes konkretes Beispiel von mir:
Code: | dim library as integer
dim OUT32 as sub ( byval Adresse AS INTEGER, byval Wert AS INTEGER)
library = dylibload( "INPOUT32.dll" )
Out32 = dylibsymbol( library, "Out32" )
screen 12
if( library = 0 ) then
print "INPOUT32.dll nicht gefunden."
end 1
end if
do
input x
out32(888,x)
loop |
Andere Fehler möglichkeit:
Ist die DLL-Datei im selben Ordner wie das Programm?
Wenn nein schieb die DLL einfach mal in diesen Ordner, vielleichtshilfst. |
|
Nach oben |
|
|
psygate
Anmeldungsdatum: 05.04.2005 Beiträge: 304 Wohnort: Wien und der Computer
|
Verfasst am: 05.09.2005, 15:52 Titel: |
|
|
geht das ganze nciht auch mit Code: | #include "mylibrary.dll"?
Das geht bei mir einfach ned, selbst wenn sie im selben ordner ist....
PS: wie kann ich emine eiegene library schreiben? |
|
|
Nach oben |
|
|
Michael Frey
Anmeldungsdatum: 18.12.2004 Beiträge: 2577 Wohnort: Schweiz
|
Verfasst am: 05.09.2005, 17:03 Titel: |
|
|
Ob es mit "#include "mylibrary.dll"?" geht weis ich nicht.
Aber wegen dem selber eine DLL Schreiben:
Wie gesagt im Ordner "\FreeBASIC\examples\dll\" ist ein Beispiel,
trotzdem Poste ich mal den Code:
mydll.bas
Code: | ''
'' mydll -- simple dll test
''
'' compile as: fbc -dll mydll.bas (will create mydll.dll and libmydll.dll.a under Win32,
'' or libmydll.so under Linux)
''
'' note: libmydll.dll.a is an import library, it's only needed when creating
'' an executable that calls any of mydll's functions, only distribute
'' the DLL files with your apps, do not include the import libraries,
'' they are useless to end-users
''
#include once "mydll.bi"
''
'' note: do not add any executable code to the main module (ie: outside
'' any function), because that code will never be executed as only DllMain
'' is invoked by Windows at the initialization
''
''::::::
''
'' simple exported function, the full prototype is at mydll.bi (the EXPORT clause must be used here)
''
function AddNumbers ( byval operand1 as integer, byval operand2 as integer ) as integer export
function = operand1 + operand2
end function |
Code: |
''
'' all FB functions are by default STDCALL on Windows and also PUBLIC,
'' so nothing else has to be added (note that FBC will not include "mydll"
'' to linker's list when creating the DLL, only when using it on an .exe)
''
declare function AddNumbers lib "mydll" alias "AddNumbers" ( byval operand1 as integer, byval operand2 as integer ) as integer |
Kernaussage:
Eine DLL ist ein einfaches Basic Programm das nur aus Subroutinen/Funktion besteht und mit "fbc -dll mydll.bas" kompiliert wurde.
So einfach ist das Leben. |
|
Nach oben |
|
|
|
|
Du kannst keine Beiträge in dieses Forum schreiben. Du kannst auf Beiträge in diesem Forum nicht antworten. Du kannst deine Beiträge in diesem Forum nicht bearbeiten. Du kannst deine Beiträge in diesem Forum nicht löschen. Du kannst an Umfragen in diesem Forum nicht mitmachen.
|
|