You don't need the registry for this. You need to use GetProcAddress on OpenAs_RunDLLA
in Shell32.dll. I can't find any documentation for it, but I have Delphi code that defines it as
SHOpenWithProc = procedure(HWND: THandle; HInstance; THandle;
CmdLine: PChar; CmdShow: Integer);
The HWND, HInstance, and CmdShow should be fairly familiar. PChar in Delphi corresponds (ANSI version - see below) to a pointer to a null terminated (C-style) string, and in the Unicode version to a null terminated WSTR. procedure
in Delphi corresponds to C's void someproc();
. The CmdLine
should point to a fully-qualified filename, so Windows knows what to offer in the "Open With" dialog.
I'm not sure how you would use GetProcAddress
(and the preceeding LoadLibrary
call) in Java, but this may get you started.
Note that the function being loaded is the ANSI version; for WideChar (Unicode), you'd want to load the OpenAs_RunDLLW
version instead, and adjust the CmdLine parameter accordingly (I think - I haven't tried the code on the wide version).
NOTE: This may help too. It's a MSDN article on using OpenAs_RunDLL via the API's ShellExecute function.