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

A

asger_gronnow

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);}
}
}
}
}
 
L

Larry Smith

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top