Image decoding fails when in DLL
- NoahPhense
- Addict

- Posts: 1999
- Joined: Thu Oct 16, 2003 8:30 pm
- Location: North Florida
Wouldn't you think that is because the exe when ran from the IDE isShannara wrote:Thanks for replying. Please note the code works perfectly when the application is compiled, as noted by myself and NoahPhense. It does not work when debugging the application.
actually inside the Compiler directory?
- np
Wait .... say that again? Actually I do not know if that would make much of a difference, only because I usually put the full path of the library + library file name, when calling the library and same for the image.
And it returns a non-zero number which means it should be valid, but it cannot be used. hrm.
And it returns a non-zero number which means it should be valid, but it cannot be used. hrm.
- NoahPhense
- Addict

- Posts: 1999
- Joined: Thu Oct 16, 2003 8:30 pm
- Location: North Florida
Wierd because mine works from inside the IDE. I'm pointing to the dllShannara wrote:Wait .... say that again? Actually I do not know if that would make much of a difference, only because I usually put the full path of the library + library file name, when calling the library and same for the image.
And it returns a non-zero number which means it should be valid, but it cannot be used. hrm.
fully and my include..
Code: Select all
Declare ChangeImage(pngFilename.s)
Declare.s GetFile()
IncludeFile "C:\source\purebasic\Projects\imageDLL.Example\include.pb"
#dll = 1
Toggle = 0
Global ff_PNG.l ; The address in memory of the function from the library.
; (for CallFunctionFast)
; // letsgotothelibrary // ------------------------------------------ //
If OpenLibrary(#dll, "C:\source\purebasic\Projects\imageDLL.Example\ImageProcessing.dll")
; lets see if its a real function
ff_PNG.l = IsFunction(#dll, "LoadPNG")
Else
MessageBox_(0, "could not locate dll", "DLL ERROR", #MB_SYSTEMMODAL)
End
EndIf*edit*
Also I noticed that catchimage would be ok, if you images were
included binaries as shown in the manual. But it is not needed at
all when loading from disk. LoadImage, which is in the dll is
doing a fine job of assigning a new ImageID ..
Code: Select all
ProcedureDLL.l LoadPNG(Filename.s)
UsePNGImageDecoder()
result = LoadImage(#PB_Any, Filename)
ResizeImage(result, 240,200) ; make it fit
ProcedureReturn result
EndProcedureHmm, here is what I have where catchimage shows 0.
ImageLib.pb (compile into dll)
Test.pb (run w/ Debugger)
Will need to change the paths to match your system
The files are zipped up and linked below for your viewing pleasure
Included is the png image 
http://www.teenyhost.com/ImageLib.zip
(added): I see what you mean concerning CatchImage. However, the manual state any memory address. For some reason I thought the return was that and/or the handle .. heh. I think that may explain the 0 result there, but ...
How would I go about copying that image handle into a new image? That way, I can close out the library and not worry about the image disappearing?
ImageLib.pb (compile into dll)
Code: Select all
ProcedureDLL.l LoadPicture(FileName.s)
;This will load a PNG picture and soon do manipulation
UseJPEGImageDecoder()
UseTIFFImageDecoder()
UseTGAImageDecoder()
UsePNGImageDecoder()
GM = LoadImage(#PB_Any,FileName)
ProcedureReturn GM
EndProcedure
Code: Select all
Global ff_Picture.l
Global myLIB.l
Global rt1.l
Global bgMenu.l
myLIB = OpenLibrary(#PB_Any, "C:\Projects\ImageLib\ImageLib.dll")
ff_Picture = IsFunction(myLIB, "LoadPicture")
rt1 = CallFunctionFast(ff_Picture, "C:\Projects\ImageLib\bgMenu.png")
Debug "rt1: " + Str(rt1) ; <-- This should be higher then 0, and it is!
bgMenu = CatchImage(#PB_Any, rt1)
Debug "bgMenu: " + Str(bgMenu) ; <-- This should be higher then 0, but it is not!
CloseLibrary(myLIB)
End
http://www.teenyhost.com/ImageLib.zip
(added): I see what you mean concerning CatchImage. However, the manual state any memory address. For some reason I thought the return was that and/or the handle .. heh. I think that may explain the 0 result there, but ...
How would I go about copying that image handle into a new image? That way, I can close out the library and not worry about the image disappearing?
- NoahPhense
- Addict

- Posts: 1999
- Joined: Thu Oct 16, 2003 8:30 pm
- Location: North Florida
It says in the manual that catchimage is useful for embedded images.
LoadImage .. which is what you are using in your DLL is already handling
the image.
there is nothing to catch, as it is not REALLY in memory after being LoadImaged ..
My example shows an embedded image, which when the exe is launched,
puts the image(s) into memory, where I will then "catch" it..
If I was loading a file from disk, with LoadImage, then I am mearly
grabbing the handle. That is why you see nothing in the manual about
free'ing memory under LoadImage, only CatchImage...
So I then have to say that you are using CatchImage in the wrong
context.
Please note in my example, there is no LoadImage.. why, because im
not grabbing files from the disk.. but from memory.
image.sound.rar
- np
ps - ive included the mutex lib.. if you dont want/need it.. just remove the
two mutex lines from the code..
LoadImage .. which is what you are using in your DLL is already handling
the image.
there is nothing to catch, as it is not REALLY in memory after being LoadImaged ..
My example shows an embedded image, which when the exe is launched,
puts the image(s) into memory, where I will then "catch" it..
If I was loading a file from disk, with LoadImage, then I am mearly
grabbing the handle. That is why you see nothing in the manual about
free'ing memory under LoadImage, only CatchImage...
So I then have to say that you are using CatchImage in the wrong
context.
Please note in my example, there is no LoadImage.. why, because im
not grabbing files from the disk.. but from memory.
image.sound.rar
- np
ps - ive included the mutex lib.. if you dont want/need it.. just remove the
two mutex lines from the code..
- tinman
- PureBasic Expert

- Posts: 1102
- Joined: Sat Apr 26, 2003 4:56 pm
- Location: Level 5 of Robot Hell
- Contact:
Have you tried:Shannara wrote:How would I go about copying that image handle into a new image? That way, I can close out the library and not worry about the image disappearing?
bgMenu = CatchImage(#PB_Any, UseImage(rt1))
Or is it ImageID() that gets the image handle? I can't remember.
If you paint your butt blue and glue the hole shut you just themed your ass but lost the functionality.
(WinXPhSP3 PB5.20b14)
(WinXPhSP3 PB5.20b14)
- NoahPhense
- Addict

- Posts: 1999
- Joined: Thu Oct 16, 2003 8:30 pm
- Location: North Florida
You already have the new image ID returned
from the dll and stored it in, rt1.. now all that
is needed is:
- np
from the dll and stored it in, rt1.. now all that
is needed is:
Code: Select all
bgMenu = rt1