Re: [xwt-users]xwt vs mozilla xul + soap

Emiliano Heyns <[email protected]>
Newsgroups gmane.comp.java.xwt.users
Message-ID <[email protected]>
Adam Megacz wrote:

> Emiliano Heyns <[email protected]> writes:
> 
>>As adam pointed out, you can use the local engine to start apps. I have
>>on windows just associated .xwar with the engine and I can start
> 
> 
> Hey, do you have a snippet of C/C++ code that does this?

I did the file association by hand myself, but here goes. WARNING: 
UNTESTED CODE. I picked this together from MSDN. I have no compiler on 
windows. The CMD and APPPATH #defines would obviously need to be 
runtime-determined strings.

LONG res;
HKEY hk = NULL;
DWORD disposition;

#define EXTENSION ".xwar"
#define APPTYPE "xwar"
#define MIMETYPE "application/x-xwar"
#define DEFAULT ""
#define APPNAME "XWT Archive"
#define APPPATH "c:\\path\\to\\xwt.exe"
#define CMD "\"" APPPATH "\" \"%1\""

/************** IF YOU HAVE ROOT ACCESS *******************/

// extension -> apptype
res = RegCreateKeyEx(HKEY_CLASSES_ROOT, EXTENSION, 0, NULL, 
REG_OPTION_NON_VOLATILE, 0, NULL, &hk, &disposition);
if(res != ERROR_SUCCESS) { return; } //oops

res = RegSetValueEx(hk, DEFAULT, 0, REG_SZ, (BYTE*)APPTYPE, 
strlen(APPTYPE) + 1);
if(res != ERROR_SUCCESS) { return; } // oops

res = RegSetValueEx(hk, "Content Type", 0, REG_SZ, (BYTE*)MIMETYPE, 
strlen(MIMETYPE) + 1);
if(res != ERROR_SUCCESS) { return; } // oops

RegCloseKey(hk);

// apptype -> Name
res = RegCreateKeyEx(HKEY_CLASSES_ROOT, APPTYPE, 0, NULL, 
REG_OPTION_NON_VOLATILE, 0, NULL, &hk, &disposition);
if(res != ERROR_SUCCESS) { return; } //oops

res = RegSetValueEx(hk, DEFAULT, 0, REG_SZ, (BYTE*)APPNAME, 
strlen(APPNAME) + 1);
if(res != ERROR_SUCCESS) { return; } // oops

RegCloseKey(hk);

// shell command
res = RegCreateKeyEx(HKEY_CLASSES_ROOT, APPTYPE "\\shell", 0, NULL, 
REG_OPTION_NON_VOLATILE, 0, NULL, &hk, &disposition);
if(res != ERROR_SUCCESS) { return; } //oops

res = RegSetValueEx(hk, DEFAULT, 0, REG_SZ, (BYTE*)"open", 5);
if(res != ERROR_SUCCESS) { return; } // oops

RegCloseKey(hk);

// actual start command
res = RegCreateKeyEx(HKEY_CLASSES_ROOT, APPTYPE 
"\\shell\\open\\command", 0, NULL, REG_OPTION_NON_VOLATILE, 0, NULL, 
&hk, &disposition);
if(res != ERROR_SUCCESS) { return; } //oops

res = RegSetValueEx(hk, DEFAULT, 0, REG_SZ, (BYTE*)CMD, strlen(CMD) + 1);
if(res != ERROR_SUCCESS) { return; } // oops

RegCloseKey(hk);

// reverse map of mimetype
res = RegCreateKeyEx(HKEY_CLASSES_ROOT, "MIME\\Database\\Content Type\\" 
MIMETYPE, 0, NULL, REG_OPTION_NON_VOLATILE, 0, NULL, &hk, &disposition);
if(res != ERROR_SUCCESS) { return; } //oops

res = RegSetValueEx(hk, "Extension", 0, REG_SZ, (BYTE*)EXTENSION, 
strlen(EXTENSION) + 1);
if(res != ERROR_SUCCESS) { return; } // oops

RegCloseKey(hk);


/************************ in case you're not root, per user: **********/
res = RegCreateKeyEx(HKEY_CURRENT_USER, 
"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\FileExts\\" 
EXTENSION, 0, NULL, REG_OPTION_NON_VOLATILE, 0, NULL, &hk, &disposition);
if(res != ERROR_SUCCESS) { return; } //oops

res = RegSetValueEx(hk, "Application", 0, REG_SZ, (BYTE*)APPPATH, 
strlen(APPPATH) + 1);
if(res != ERROR_SUCCESS) { return; } // oops

RegCloseKey(hk);
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.