By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,851 Members | 2,097 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,851 IT Pros & Developers. It's quick & easy.

Problem associating file types, that doesn't exist already, with my app

P: n/a
Hi
I'm having trouble associating file types with my app. Associating a
file type works as long as the file type is already associated with
another program but if the file type doesn't exist already, it isn't
associated. So my question is: how do I associate a file type that
isn't registered already? How can I register this new file type if
that's what I'll have to do before associating it.
I'm programming in Win32 using the Dev-Cpp compiler. Here's the code I
currently use to associate file types:

void associatefile (string filetype)
{
HKEY hKey;
string exepath=AppPath;
string key = "LibertyExpress";
string keyval = "LibertyExpress";

int reg = RegCreateKey( HKEY_CLASSES_ROOT, key.c_str(),&hKey);
if (reg == ERROR_SUCCESS) {reg=RegSetValue(hKey, "", REG_SZ,
keyval.c_str(), 0);}
else {return;}

if(reg == ERROR_SUCCESS)
{
key=filetype;
keyval="LibertyExpress";
reg=RegCreateKey(HKEY_CLASSES_ROOT, key.c_str(),
&hKey);
if(reg == ERROR_SUCCESS)
{
reg=RegSetValue(hKey, "", REG_SZ,
keyval.c_str(), 0);
if(reg == ERROR_SUCCESS)
{
key="LibertyExpress";
keyval=exepath+" %1";
reg=RegCreateKey(HKEY_CLASSES_ROOT,
key.c_str(), &hKey);
if(reg == ERROR_SUCCESS)
{reg=RegSetValue(hKey, "shell\\open\\command", REG_SZ, keyval.c_str(),
MAX_PATH);}
}
}
}
}

Feb 18 '07 #1
Share this Question
Share on Google+
1 Reply


P: n/a
as***********@yahoo.com wrote:
Hi
I'm having trouble associating file types with my app. Associating a
file type works as long as the file type is already associated with
another program but if the file type doesn't exist already, it isn't
associated. So my question is: how do I associate a file type that
isn't registered already? How can I register this new file type if
that's what I'll have to do before associating it.
I'm programming in Win32 using the Dev-Cpp compiler. Here's the code I
currently use to associate file types:

void associatefile (string filetype)
{
HKEY hKey;
string exepath=AppPath;
string key = "LibertyExpress";
string keyval = "LibertyExpress";

int reg = RegCreateKey( HKEY_CLASSES_ROOT, key.c_str(),&hKey);
if (reg == ERROR_SUCCESS) {reg=RegSetValue(hKey, "", REG_SZ,
keyval.c_str(), 0);}
else {return;}

if(reg == ERROR_SUCCESS)
{
key=filetype;
keyval="LibertyExpress";
reg=RegCreateKey(HKEY_CLASSES_ROOT, key.c_str(),
&hKey);
if(reg == ERROR_SUCCESS)
{
reg=RegSetValue(hKey, "", REG_SZ,
keyval.c_str(), 0);
if(reg == ERROR_SUCCESS)
{
key="LibertyExpress";
keyval=exepath+" %1";
reg=RegCreateKey(HKEY_CLASSES_ROOT,
key.c_str(), &hKey);
if(reg == ERROR_SUCCESS)
{reg=RegSetValue(hKey, "shell\\open\\command", REG_SZ, keyval.c_str(),
MAX_PATH);}
}
}
}
}
This is Windows API specific code; not C++ related.
Try a Microsoft Windows news group.

Feb 19 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.