I have been increasingly getting problems with end-users importing .bmp files into my applications getting a 'corrupted' image (a bit of a squiggle and the file name below it).
In the past I've been able to resolve this with an 'assoc' command on the command line - but recently this has ceased to work on some machines. I've ended up fixing the problem remotely and sending back the data. Not ideal, looks naff too.
So research has been done and the problem lies in a registry key entry:
HKEY_LOCAL_MACHINE\SOFTWARE\CLASSES\.bmp
It needs to 'point' to Paint.Picture and sometimes doesn't.
So, in the code that does the import and APPEND GENERAL I now use this:
The important bit is the SETKEYVALUE bit, which returns the original setting of the spacified key. I use this to set the key value (remembering the old one) then do the APPEND GENERAL immediately afterwards and then restore the setting to the earlier one - in case that matters to some other piece of software I know nothing about.
In my main procedures file I have this function (you can put the #defines at the top of the procedure file if you like):
And it seems to work.
Please excuse a) the scruffy coding and b) anyone who recognises their plagurised code!
B-)
Regards
Griff
Keep [Smile]ing
In the past I've been able to resolve this with an 'assoc' command on the command line - but recently this has ceased to work on some machines. I've ended up fixing the problem remotely and sending back the data. Not ideal, looks naff too.
So research has been done and the problem lies in a registry key entry:
HKEY_LOCAL_MACHINE\SOFTWARE\CLASSES\.bmp
It needs to 'point' to Paint.Picture and sometimes doesn't.
So, in the code that does the import and APPEND GENERAL I now use this:
Code:
#DEFINE HKEY_LOCAL_MACHINE -2147483646 && BITSET(0,31)+2
PRIVATE m.LOGO
PRIVATE m.OLDVALUE
M.LOGO = GETPICT("BMP","Select Logo file","OK")
SELECT POPPJ
IF !EMPTY(m.LOGO)
IF MYFILE(m.LOGO)
M.OLDVALUE = SETKEYVALUE(HKEY_LOCAL_MACHINE,"SOFTWARE\classes\.bmp","",'Paint.Picture')
APPEND GENERAL LOGO FROM (m.LOGO) CLASS PAINT.PICTURE
SETKEYVALUE(HKEY_LOCAL_MACHINE,"SOFTWARE\classes\.bmp","",m.OLDVALUE)
ENDIF
ENDIF
The important bit is the SETKEYVALUE bit, which returns the original setting of the spacified key. I use this to set the key value (remembering the old one) then do the APPEND GENERAL immediately afterwards and then restore the setting to the earlier one - in case that matters to some other piece of software I know nothing about.
In my main procedures file I have this function (you can put the #defines at the top of the procedure file if you like):
Code:
#DEFINE HKEY_CLASSES_ROOT -2147483648 && BITSET(0,31)
#DEFINE HKEY_CURRENT_USER -2147483647 && BITSET(0,31)+1
#DEFINE HKEY_LOCAL_MACHINE -2147483646 && BITSET(0,31)+2
#DEFINE HKEY_USERS -2147483645 && BITSET(0,31)+3
#DEFINE REG_SZ 1 && Data string
FUNCTION SETKEYVALUE
* This routine sets a key value
* Note: this routine only handles data strings (REG_SZ)
LPARAMETER m.NREGKEY,m.CLOOKUPKEY,CVALUENAME,CVALUE
LOCAL NVALUESIZE,NERRCODE,NSUBKEY,REGTYPE
LOCAL m.OLDVALUE,NOLDVALUESIZE
NSUBKEY = 0
* Make sure we null terminate the value
CVALUE = m.CVALUE+CHR(0)
NVALUESIZE = LEN(m.CVALUE)
REGTYPE = REG_SZ
M.OLDVALUE = ""
DECLARE INTEGER RegSetValueEx IN Win32API ;
INTEGER hKey, STRING lpszValueName, INTEGER dwReserved,;
INTEGER fdwType, STRING lpbData, INTEGER cbData
DECLARE INTEGER RegOpenKey IN Win32API ;
INTEGER nHKey, STRING @cSubKey, INTEGER @nResult
DECLARE INTEGER RegQueryValueEx IN Win32API ;
INTEGER nHKey, STRING lpszValueName, INTEGER dwReserved,;
INTEGER @lpdwType, STRING @lpbData, INTEGER @lpcbData
REGOPENKEY(m.NREGKEY,m.CLOOKUPKEY,@NSUBKEY)
IF NSUBKEY <> 0
NOLDVALUESIZE = 1
* Get the size of the data in the value
REGQUERYVALUEEX(NSUBKEY, CVALUENAME, 0, @REGTYPE, @m.OLDVALUE, @NOLDVALUESIZE)
* Make the buffer big enough
M.OLDVALUE = SPACE(NOLDVALUESIZE)
REGQUERYVALUEEX(NSUBKEY, CVALUENAME, 0, @REGTYPE, @m.OLDVALUE, @NOLDVALUESIZE)
* Set the key value here
M.NERRCODE = REGSETVALUEEX(NSUBKEY,m.CVALUENAME,0,REG_SZ,m.CVALUE,m.NVALUESIZE)
ENDIF
CLEAR DLLS REGQUERYVALUEEX
CLEAR DLLS REGSETVALUEEX
CLEAR DLLS REGOPENKEY
RETURN(m.OLDVALUE)
And it seems to work.
Please excuse a) the scruffy coding and b) anyone who recognises their plagurised code!
B-)
Regards
Griff
Keep [Smile]ing