dotgnu-general
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [DotGNU]PInvoke question...


From: Rhys Weatherley
Subject: Re: [DotGNU]PInvoke question...
Date: Thu, 10 Jul 2003 09:44:19 +1000
User-agent: KMail/1.4.3

On Thursday 10 July 2003 09:41 am, Mark Easton wrote:

> I've been looking at the IsWin32 member and it seems to be responsible
> for catching the MissingMethodException.  Wouldn't it be better to throw
> the exception and be damned, or is that what you were insinuating in
> your mail?

It depends on the situation.  I chose in this case to pretend that the API 
worked.  I generally try to lean towards "it works more or less the same on 
all platforms" rather than "it will blow up in your face on some".

> For me it seems that the exception has to be thrown, otherwise there
> will have no sensible way to know that the registry code is not
> functioning.

It's a choice.  Some people will want to know that the registry isn't "real", 
and others want it to "just work".  I can't do it both ways. :-)

> Once again, I'm not sure if you were saying you would
> change it to throw the exception, or rather change it not to printf the
> current message

I've stopped it printing the debug message.  No exception will be thrown.

> My questions are all academic and I'm not considering using the registry
> (which I've hated with a passion since Win95), but rather I'm just
> working on some training material for Windows developers.

You can use Environment.OSVersion to determine if the platform is really Win32 
if you really have to.  Mono and pnet have a PlatformID.Unix value that 
indicates "not Win32".  MS doesn't have this value, but you can do this:

    if(Environment.OSVersion.Platform != (PlatformID)128)
    {
        Win32 code
    }
    else
    {
        non-Win32 code
    }

However, this is usually a bad idea.  Someone may implement the registry under 
Unix in the future, using flat files or something.  Detecting the OS will 
bypass the fact that the API will then work properly.

If you actually have a need for the registry to work, then perhaps you might 
like to look into implementing a "FileKeyProvider" class for pnet, using 
"FileStream"'s and flat files?

Cheers,

Rhys.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]