News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Default extension handler

Started by ecube, November 11, 2006, 09:38:41 PM

Previous topic - Next topic

ecube

The code below makes RadAsm the default handler of .asm and .inc files the only problem is RadAsm says it can't open the file for some reason, i have no idea why. Also I had to close registry keys after I created them then reopen because for some reason the returned handles weren't working even though I used offset since addr cannot handle forward references. Any help would be much appreciated.


.486
.model flat, stdcall
option casemap:none


include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
include \masm32\include\masm32.inc
include \masm32\include\user32.inc
include \masm32\include\advapi32.inc
include \masm32\include\shell32.inc

includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\masm32.lib
includelib \masm32\lib\user32.lib
includelib \masm32\lib\advapi32.lib
includelib \masm32\lib\shell32.lib
Associate_File proto :DWORD,:DWORD,:DWORD

     CTEXT MACRO text:VARARG
            LOCAL TxtName
              .data
               TxtName BYTE text,0
              .code
            EXITM <ADDR TxtName>
     ENDM


.data?
szBuff             db 256 dup(?)
RegKey             dd ?
CreatedKey         dd ?
CreatedKey2        dd ?
tempvalue          dd ?


.code
start:
invoke Associate_File,CTEXT(".asm"),CTEXT("asm_auto_file"), CTEXT("C:\Program Files\RadAsm\RadASM.exe")
invoke Associate_File,CTEXT(".inc"),CTEXT("inc_auto_file"), CTEXT("C:\Program Files\RadAsm\RadASM.exe")

invoke ExitProcess,0

;this associates the specified file extensions to the created classname that points to the Exeprogram for opening
Associate_File proc Extension:DWORD,ClassName:DWORD,ExeProgram:DWORD
;create a value for this key that contains the classname
invoke RegCreateKeyEx,HKEY_CLASSES_ROOT,Extension,0,0,0,0,0,offset CreatedKey,offset tempvalue
invoke RegCloseKey,CreatedKey
;reopen, since direct creation handle wasn't working
invoke RegOpenKey,HKEY_CLASSES_ROOT,Extension,offset CreatedKey
invoke lstrlen,ClassName
mov ecx,eax
invoke RegSetValueEx, CreatedKey, NULL, 0, REG_SZ, ClassName,ecx

; create a new key for the Class name
invoke wsprintf,addr szBuff,CTEXT("%s\Shell\Open\Command"),ClassName
invoke RegCreateKeyEx,HKEY_CLASSES_ROOT,addr szBuff,0,0,0,0,0,offset CreatedKey2,offset tempvalue
invoke RegCloseKey,CreatedKey2

;reopen, since direct creation handle wasn't working
invoke RegOpenKey,HKEY_CLASSES_ROOT,addr szBuff,offset CreatedKey2
;set its value to the command line
invoke wsprintf,addr szBuff,CTEXT('"%s"'),ExeProgram
invoke lstrcat,addr szBuff,CTEXT(' "%1"')
invoke RegSetValueEx, CreatedKey2, NULL, 0, REG_SZ,addr szBuff,sizeof szBuff
invoke RegCloseKey,CreatedKey
invoke RegCloseKey,CreatedKey2

;notify Windows that file associations have changed
invoke SHChangeNotify,SHCNE_ASSOCCHANGED, SHCNF_IDLIST, 0, 0
ret
Associate_File endp

end start