Page 1 of 1
Image not initialized
Posted: Mon Jul 09, 2012 2:35 pm
by Faildeath
Hello all,
I'm having a bit of a problem recently.
I'm coding on (mainly) 2 different computers one at home, one at work.
My home computer is running Windows 7, the other one is on XP.
My program is working normally on Seven and every XP I've tried, until
recently on my new work computer.
I now have the same error every time I try : "The image is not initialized".
Has anyone came across this problem and found the source or a solution?
I run PB and my file from a USB on all the computers w/o problems outside of
my XP at work. Also I'm a simple user with no special rights at work.
If you have any info please tell me.
Thanks
Re: Image not initialized
Posted: Mon Jul 09, 2012 2:43 pm
by ts-soft
Use a absolute path or like this:
Code: Select all
Define MyImage.s = GetPathPart(ProgramFilename()) + "myimage.bmp"
Re: Image not initialized
Posted: Mon Jul 09, 2012 4:30 pm
by IdeasVacuum
On your PCs, you are no doubt the PC Administrator User but perhaps at work you are not. Therefore, any files of any type to be loaded or moved by your app have to be where Windows thinks is an acceptable place. If they are not, Windows simply does not make them available. So, if your app is installed in the Program Files folder, it's probably best that images are not loaded from there, especially if the app User is going to provide files that will be loaded. If that is the case, create a folder for them in the My Documents folder of the specific User (or All Users). If the files to be loaded are only those supplied with your app and the User is not going to modify/save them outside of the app, then those files should be in the App Data folder (either specific to the one User or All Users, depending on what your install allowed).
Since different Windows versions actually use different paths for these folders (even Program Files), your app code needs to use generic paths rather than 'fixed full paths'. You can use a procedure that finds the System Paths ('special folders') on any Windows PC:
Code: Select all
Procedure.s GetSpecialFolder(iVal.i)
;-----------------------------------
#CSIDL_DESKTOP = $0 ;{desktop}
#CSIDL_INTERNET = $1 ;Internet Explorer (icon on desktop)
#CSIDL_PROGRAMS = $2 ;Start Menu\Programs
#CSIDL_CONTROLS = $3 ;My Computer\Control Panel
#CSIDL_PRINTERS = $4 ;My Computer\Printers
#CSIDL_PERSONAL = $5 ;My Documents
#CSIDL_FAVORITES = $6 ;{user}\Favourites
#CSIDL_STARTUP = $7 ;Start Menu\Programs\Startup
#CSIDL_RECENT = $8 ;{user}\Recent
#CSIDL_SENDTO = $9 ;{user}\SendTo
#CSIDL_BITBUCKET = $A ;{desktop}\Recycle Bin
#CSIDL_STARTMENU = $B ;{user}\Start Menu
#CSIDL_DESKTOPDIRECTORY = $10 ;{user}\Desktop
#CSIDL_DRIVES = $11 ;My Computer
#CSIDL_NETWORK = $12 ;Network Neighbourhood
#CSIDL_NETHOOD = $13 ;{user}\nethood
#CSIDL_FONTS = $14 ;windows\fonts
#CSIDL_TEMPLATES = $15
#CSIDL_COMMON_STARTMENU = $16 ;All Users\Start Menu
#CSIDL_COMMON_PROGRAMS = $17 ;All Users\Programs
#CSIDL_COMMON_STARTUP = $18 ;All Users\Startup
#CSIDL_COMMON_DESKTOPDIRECTORY = $19 ;All Users\Desktop
#CSIDL_APPDATA = $1A ;{user}\Application Data
#CSIDL_PRINTHOOD = $1B ;{user}\PrintHood
#CSIDL_LOCAL_APPDATA = $1C ;{user}\Local Settings\Application Data (non roaming)
#CSIDL_ALTSTARTUP = $1D ;non localized startup
#CSIDL_COMMON_ALTSTARTUP = $1E ;non localized common startup
#CSIDL_COMMON_FAVORITES = $1F
#CSIDL_INTERNET_CACHE = $20
#CSIDL_COOKIES = $21
#CSIDL_HISTORY = $22
#CSIDL_COMMON_APPDATA = $23 ;All Users\Application Data
#CSIDL_WINDOWS = $24 ;GetWindowsDirectory()
#CSIDL_SYSTEM = $25 ;GetSystemDirectory()
#CSIDL_PROGRAM_FILES = $26 ;C:\Program Files
#CSIDL_MYPICTURES = $27 ;C:\Program Files\My Pictures
#CSIDL_PROFILE = $28 ;USERPROFILE
#CSIDL_SYSTEMX86 = $29 ;x86 system directory on RISC
#CSIDL_PROGRAM_FILESX86 = $2A ;x86 C:\Program Files on RISC
#CSIDL_PROGRAM_FILES_COMMON = $2B ;C:\Program Files\Common
#CSIDL_PROGRAM_FILES_COMMONX86 = $2C ;x86 Program Files\Common on RISC
#CSIDL_COMMON_TEMPLATES = $2D ;All Users\Templates
#CSIDL_COMMON_DOCUMENTS = $2E ;All Users\Documents
#CSIDL_COMMON_ADMINTOOLS = $2F ;All Users\Start Menu\Programs\Administrative Tools
#CSIDL_ADMINTOOLS = $30 ;{user}\Start Menu\Programs\Administrative Tools
#CSIDL_FLAG_CREATE = $8000 ;combine with CSIDL_ value to force
;create on SHGetSpecialFolderLocation()
#CSIDL_FLAG_DONT_VERIFY = $4000 ;combine with CSIDL_ value to force
;create on SHGetSpecialFolderLocation()
#CSIDL_FLAG_MASK = $FF00 ;mask for all possible flag values
#SHGFP_TYPE_CURRENT = $0 ;current value for user, verify it exists
#SHGFP_TYPE_DEFAULT = $1
Protected iFolderID.i, sSpecialFolderLocation.s
If SHGetSpecialFolderLocation_(0, iVal, @iFolderID) = 0
sSpecialFolderLocation = Space(#MAX_PATH)
SHGetPathFromIDList_(iFolderID, @sSpecialFolderLocation)
If sSpecialFolderLocation
If Right(sSpecialFolderLocation, 1) <> "\"
sSpecialFolderLocation + "\"
EndIf
EndIf
CoTaskMemFree_(iFolderID)
EndIf
ProcedureReturn sSpecialFolderLocation
EndProcedure
So for example, your app may need to use a file from it's App Data folder.
If your App is Called 'MyApp' and it's data folder is given the same name (typically this is true), the path to the file 'MyFile.png' on Windows XP would be:
"C:\Documents and Settings\UserName\Application Data\MyApp\MyFile.png" Where your app typically does not know the 'UserName'.
So, to grab the folder path in your code using the Procedure above:
Code: Select all
sAppDataPath.s = GetSpecialFolder(#CSIDL_APPDATA)
sMyFilePath.s = sgAppDataPath + "MyApp\MyFile.png"
Re: Image not initialized
Posted: Mon Jul 09, 2012 4:47 pm
by Faildeath
As I am dumb I forgot to post the line which causes a problem to understand try to better :
Code: Select all
CatchImage(#RMenu_Delete_Img, ?SupprID) : SupprID = ImageID(#RMenu_Delete_Img)
...
DataSection ;{
SupprID : IncludeBinary "F:\PureBasic\_Datas\Suppr.ico"
EndDataSection
so to my understanding (quite possible) the problem doesn't come from a unrecognized path or unauthorized one.
I,ve also tried to copy PB on the D:\ drive to check if there was no issue with the USB but same result.
Thanks though for your help.
Re: Image not initialized
Posted: Mon Jul 09, 2012 5:35 pm
by ts-soft
The ICO corrupt? Please, check this:
Code: Select all
CatchImage(#RMenu_Delete_Img, ?SupprID, ?SupprID_End - ?SupprID) : SupprID = ImageID(#RMenu_Delete_Img)
...
DataSection ;{
SupprID : IncludeBinary "F:\PureBasic\_Datas\Suppr.ico" : SupprID_End:
EndDataSection
Re: Image not initialized
Posted: Mon Jul 09, 2012 7:09 pm
by Faildeath
Thanks ts-soft, I'll try tomorrow.
I also remember that when using the exe I've made from my home computer on my work one,
the Menu Ico where not displaying. At home 100% good but not at work.
Re: Image not initialized
Posted: Mon Jul 09, 2012 7:28 pm
by IdeasVacuum
...take care to ensure that the .ico files are the correct size and only contain one image.
Re: Image not initialized
Posted: Mon Jul 09, 2012 8:48 pm
by ts-soft
This can be a problem by some antivirus or window-defender and so on, blocking the imagecatch or you use a exe-packer?
You can add the icon as resource, this is more sure in this case!
Write a simple text and save as myres.rc:
myres.rc wrote:100 ICON "F:\PureBasic\_Datas\Suppr.ico"
and add it in the compileroptions.
Load the icon like this:
Code: Select all
SupprID = LoadIcon_(GetModuleHandle_(0), 100)
Re: Image not initialized
Posted: Tue Jul 10, 2012 11:03 am
by Faildeath
Tried the SupprID_End: solution but didn't worked, still the same pb, the
Code: Select all
Suppr_IMG_ID = ImageID(#RMenu_Delete_Img)
part doesn't seams to work.
I've tried to test the resource one but I don't know how to use it and it gives me errors.
So usualy this is how I do it :
Code: Select all
CatchImage(#RMenu_Delete_Img, ?SupprID) : Suppr_IMG_ID = ImageID(#RMenu_Delete_Img)
CatchImage(#RMenu_OpenPage_Img, ?OpenPageID) : OpenPage_IMG_ID = ImageID(#RMenu_OpenPage_Img)
MenuItem(#RMenu_Delete, "Delete from list"+Chr(9)+"Suppr", Suppr_IMG_ID)
MenuItem(#RMenu_OpenPage, "Open page", OpenPage_IMG_ID)
...
DataSection
SupprID : IncludeBinary "F:\PureBasic\_Datas\Suppr.ico" : SupprID_End:
OpenPageID : IncludeBinary "F:\PureBasic\_Datas\OpenPage.ico" : OpenPageID_End:
EndDataSection
And now I've created a resouce.rc file :
resouce.rc wrote:
100 ICON "F:\PureBasic\_Datas\Suppr.ico"
200 ICON "F:\PureBasic\_Datas\OpenPage.ico"
And I must use it like that ? :
Code: Select all
SupprID = LoadIcon_(GetModuleHandle_(0), 100)
OpenPageID= LoadIcon_(GetModuleHandle_(0), 200)
CatchImage(#RMenu_Delete_Img, ?SupprID) : Suppr_IMG_ID = ImageID(#RMenu_Delete_Img)
CatchImage(#RMenu_OpenPage_Img, ?OpenPageID) : OpenPage_IMG_ID = ImageID(#RMenu_OpenPage_Img)
MenuItem(#RMenu_Delete, "Delete from list"+Chr(9)+"Suppr", Suppr_IMG_ID)
MenuItem(#RMenu_OpenPage, "Open page", OpenPage_IMG_ID)
Or am I doing something wrong again?
About the antivirus possibility, I don't think so, I use the same code to add img / ico to all my
programs and everything works fine but this one.
Re: Image not initialized
Posted: Tue Jul 10, 2012 11:07 am
by Faildeath
After a bit more checking, I think
IdeasVacuum had it wright,
seems to be an error with the ico file, probably multiples ico in the same file but
can't check from work.
Still interested in the above problem's solution though

(the part about how to use the "resource.rc" file)
Re: Image not initialized
Posted: Tue Jul 10, 2012 11:07 am
by ts-soft
Faildeath wrote:
Or am I doing something wrong again?
Yes
Code: Select all
SupprID = LoadIcon_(GetModuleHandle_(0), 100)
OpenPageID= LoadIcon_(GetModuleHandle_(0), 200)
MenuItem(#RMenu_Delete, "Delete from list"+Chr(9)+"Suppr", SupprID)
MenuItem(#RMenu_OpenPage, "Open page", OpenPageID)
I hope at the end of the rc-file is a return!
>> (the part about how to use the "resource.rc" file)
Compiler options, the fifth tab, browse to your rc file and press the right button

Re: Image not initialized
Posted: Tue Jul 10, 2012 12:33 pm
by Faildeath
Thanks, so yes I was doing it quite a bit wrong...
About the .rc file, my exact file is what I wrote earlier.
So I need to add a return, but 'return' the command ?
Sorry for my noobism

Re: Image not initialized
Posted: Tue Jul 10, 2012 1:02 pm
by ts-soft
Put the cursor to the last char and press enter
In this case, you have a new empty line!