PDA

View Full Version : Can not declare functions in FreeImage.DLL



Michael Hartlef
13-11-2009, 18:25
Hi folks,

thinBasic doesn't recognize my declares of FreeImage functions at all. What am I doing wrong here?
I always get an error code 30, Variable not defined or misspelled Keyword.




Uses "TBGL" , "UI"

Declare Function FreeImage_GetFileType Lib "FreeImage.dll" Alias "FreeImage_GetFileType" (ByVal fnam As String, ByVal lSize As Long) As Long
Declare Function FreeImage_Load Lib "FreeImage.dll" Alias "FreeImage_Load" (ByVal FREE_IMAGE_FORMAT As Long, ByVal fnam As ASCIIZ) As Long
Declare Function FreeImage_ConvertTo24Bits Lib "FreeImage.dll" Alias "FreeImage_ConvertTo24Bits" (ByVal FIBITMAP As Long) As Long
Declare Function FreeImage_GetWidth Lib "FreeImage.dll" Alias "FreeImage_GetWidth" (ByVal FIBITMAP As Long) As Long
Declare Function FreeImage_GetHeight Lib "FreeImage.dll" Alias "FreeImage_GetHeight" (ByVal FIBITMAP As Long) As Long
Declare Function FreeImage_GetBits Lib "FreeImage.dll" Alias "FreeImage_GetBits" (ByVal FIBITMAP As Long) As Long
Declare Sub FreeImage_Unload Lib "FreeImage.dll" Alias "FreeImage_Unload" (ByVal FIBITMAP As Long)


Dim bitm As Long
Dim fn As String
Dim typ As Long
Dim dirTextures As String = "Textures\"

fn = APP_SourcePath + dirTextures + "fire.jpg"
typ = FreeImage_GetFileType (fn,0)
bitm = FreeImage_Load(typ,fn)
FreeImage_Unload(bitm)

MsgBox(0,"type:"&Str$(typ))



I attached the files too so you can try yourself.

Charles Pegge
13-11-2009, 19:32
Hi Michael,

This DLL uses decorated names. Below is a list of the all the exported symbols.

Charles

Petr Schreiber
13-11-2009, 20:20
You are right Charles,

so the example above becomes:


' -- Declares
Declare Function FreeImage_GetFileType Lib "FreeImage.dll" Alias "_FreeImage_GetFileType@8" (ByVal fnam As String, ByVal lSize As Long) As Long
Declare Function FreeImage_Load Lib "FreeImage.dll" Alias "_FreeImage_Load@12" (ByVal FREE_IMAGE_FORMAT As Long, ByVal fnam As ASCIIZ) As Long
Declare Function FreeImage_ConvertTo24Bits Lib "FreeImage.dll" Alias "_FreeImage_ConvertTo24Bits@4" (ByVal FIBITMAP As Long) As Long
Declare Function FreeImage_GetWidth Lib "FreeImage.dll" Alias "_FreeImage_GetWidth@4" (ByVal FIBITMAP As Long) As Long
Declare Function FreeImage_GetHeight Lib "FreeImage.dll" Alias "_FreeImage_GetHeight@4" (ByVal FIBITMAP As Long) As Long
Declare Function FreeImage_GetBits Lib "FreeImage.dll" Alias "_FreeImage_GetBits@4" (ByVal FIBITMAP As Long) As Long
Declare Sub FreeImage_Unload Lib "FreeImage.dll" Alias "_FreeImage_Unload@4" (ByVal FIBITMAP As Long)


Dim hBitmap As Long
Dim fileName As String
Dim iType As Long
Dim width, height, bits As Long
Dim dirTextures As String = "Textures\"

fileName = APP_SourcePath + dirTextures + "fire.jpg"
iType = FreeImage_GetFileType(fileName,0)
hBitmap = FreeImage_Load(iType,fileName)

width = FreeImage_GetWidth(hBitmap)
height = FreeImage_GetHeight(hBitmap)

FreeImage_Unload(hBitmap)

MsgBox (0,"type:" & Str$(iType) & $CRLF & _
"width:" & Str$(width) & $CRLF & _
"height:" & Str$(height) & $CRLF & _
)


The list of FreeImage exports can be retrieved using following code as well:


uses "EXE"
MsgBox 0, EXE_PE_GetExportList("FreeImage.dll", $CRLF)

Michael Hartlef
14-11-2009, 01:27
Thanks guys. :eusaclap: I forgot all about these mangles export names.

José Roca
14-11-2009, 03:58
See: http://www.jose.it-berater.org/smfforum/index.php?topic=3363.0