You can save some leg work by getting AssocQueryString to search the registry for you.
Code:
#include <windows.h>
#include <shlwapi.h>
#include <stdio.h>
#if defined (_MSC_VER)
#pragma comment(lib, "shlwapi.lib")
#elif defined (__LCC__)
#pragma lib<shlwapi.lib>
#endif
#define ARRAY_SIZE(arr) (sizeof(arr)/sizeof((arr)[0]))
int main(void)
{
HRESULT hr;
TCHAR szExe[MAX_PATH + 100];
DWORD cchExe = ARRAY_SIZE(szExe);
if (SUCCEEDED(hr = AssocQueryString(0, ASSOCSTR_EXECUTABLE,
TEXT("http"), TEXT("open"), szExe, &cchExe)))
{
printf("Path to default browser is '%s'.\n", szExe);
}
else
{
printf("Failed with error 0x%08.8x.", hr);
}
getchar();
return 0;
}
Note: In my version of Dev-C++/Mingw, there is an error in shlwapi.h that will cause this code to give incorrect results. Lines 60-63 are:
Code:
typedef enum {
ASSOCSTR_COMMAND,
ASSOCSTR_EXECUTABLE,
ASSOCSTR_FRIENDLYDOCNAME,
instead of:
Code:
typedef enum {
ASSOCSTR_COMMAND = 1,
ASSOCSTR_EXECUTABLE,
ASSOCSTR_FRIENDLYDOCNAME,