On Thursday 06 May 2004 19:46, Mark K. Kim wrote:
>Probably the best thing to do under Windows is to use the registry, which
>requires registry key access.  Currently, there's no way to access the
>keys using only SDL, and MingW doesn't allow registry access either (not
>without extra libraries), so the only other option left is Visual C/C++,
>which I think is the cleanest option without the clunky extra libraries.
>

This sounds right to me. Not sure what registry keys to use for all users, 
though.

>So assuming Visual C/C++ is the way, I'm not sure if this can be done with
>the free compiler on Microsoft's website, and whether the license allows
>for open source software to use it (I tried reading it and it's ambiguous
>enough for me to avoid using it).  If anyone has information on those
>topics, please share!
>

The registry is accessed using Win32 functions.

Here is some code I have used in the past to create an application directory 
in a location that should exist, and be writable, on all versions of Windows 
(95/98/ME/2K/XP)

HRESULT ReadRegistry( const char *key, const char *option, char *value, int 
size )
{
    LONG        res;
    HKEY        hKey = NULL;

    res = RegOpenKeyEx( HKEY_CURRENT_USER, key, 0, KEY_READ, &hKey );
    if ( res != ERROR_SUCCESS )
        goto err_exit;

    res = RegQueryValueEx( hKey, option, NULL, NULL, (LPBYTE)value, 
                           (LPDWORD)&size );

err_exit:
    if ( hKey ) RegCloseKey( hKey );
    return HRESULT_FROM_WIN32(res);
}

Used like this:

HRESULT GetAppDir( const char *app_prefix, char *app_dir )
{
    char    path[MAX_PATH];
    char   *key = 
"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders";
    char   *option = "AppData";
    HRESULT hr = S_OK;

    if ( SUCCEEDED(hr = ReadRegistry( key, option, path, sizeof(path) )) )
    {
        EnsureSlash(path);
        if ( !BuildDirChain( path, app_prefix ) )
        {
            strcpy( app_dir, path );
            strcat( app_dir, app_prefix );
            EnsureSlash(app_dir);
            return hr;
        }
    }
    return hr;
}

Which might be used like this:

char dataPath[MAX_PATH];

if ( FAILED(GetAppDir( "tuxpaint", dataPath)) )
{
    getcwd(dataPath, sizeof(dataPath));
    EnsureSlash(dataPath);
}

The functions EnsureSlash() and BuildDirChain() are just a couple of simple 
functions knocking about my toolbox. They are probably already in Tux Paint 
somewhere.

dataPath ends up set to the current working directory or something like:

"C:\Windows\Profiles\jfp\Application Data\tuxpaint\" on 98 and
"C:\Documents and Settings\jfp\Application Data\tuxpaint\" on XP

Not very convenient or aesthetically pleasing, but it works regardless of the  
permissions of the currently logged in user,

cheers,
John.


>As for the Mac, it's a matter of knowing the conventions and having a test
>platform.  I don't know the former and I don't have the latter. =(
>
>-Mark
>
>On Thu, 6 May 2004, Bill Kendrick wrote:
>> On Thu, May 06, 2004 at 11:23:42AM -0700, Mark K. Kim wrote:
>> > 0.9.15! =)
>>
>> Heh, you offering to work on it? ;) ;)
>>
>> -bill!
>> (Linux-less, other than a yet-to-be-constructed work server, my ISP shell,
>> and my Zaurus)
>> _______________________________________________
>> Tuxpaint-dev mailing list
>> [EMAIL PROTECTED]
>> http://tux4kids.net/mailman/listinfo/tuxpaint-dev
_______________________________________________
Tuxpaint-dev mailing list
[EMAIL PROTECTED]
http://tux4kids.net/mailman/listinfo/tuxpaint-dev

Reply via email to