I need to register the file association for a certain file type – in fact, I just need to launch a certain Java program with certain arguments and a name of that file.
I got as far as the following:
// in fff-assoc.cmd file:
assoc .fff=SomeFile
ftype SomeFile=java -jar some.jar <arguments1> "%%1" <arguments2>
It works properly for ASCII file names. But when I try to double-click some file with non-ASCII symbols in name, the argument passed looks like “????” (int value of each char = 63).
How can I fix those associations?
If what bobince says is accurate and you cannot reliably get the data to java directly, one alternative solution would be to write a small “shim” program in another language (e.g. C, C++ or C#).
The idea is that the program grabs the input as UNICODE, encodes it so that it’s expressible using only ASCII characters (e.g. by using base64, or even something as simple as encoding every character as its numerical equivalent) and then assembles the command line argument to use and launches java itself using CreateProcess.
Your Java code could “undo” the encoding, reconstructing the UNICODE name and proceeding to use it. It’s a bit of a roundabout way and requires an extra component for your software, but it should work around the restriction detailed above, if indeed that is an actual restriction.
Update: This is the basic code for the shim program. It encodes input as a sequence of integers, separated by colons. It doesn’t do much in the way of error checking and you might want to improve it slightly, but it should at least get you started and going in the right direction.
You should grab Visual Studio Express (if you don’t already have Visual Studio) and create a new Visual C++ project, choose “Win32” and select “Win32 Project”. Choose “Win32 application”. After the project is created, replace everything in the .cpp file that is displayed with this code:
You should be able to figure the details on how to compile and so on fairly easily.