[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

phrosty@gmail.com

2/24/2007 2:57:00 PM

Hey folks,

I'm trying to DllImport the SendMessage and SetWindowTheme APIs, but
maintain backward compatibility with Win2k and stay cross-platform
with Mono. So I need a way to import these APIs if they are there but
fail gracefully if they aren't. Any ideas?

3 Answers

(Mattias Sjögren)

2/24/2007 4:08:00 PM

0

>I'm trying to DllImport the SendMessage and SetWindowTheme APIs, but
>maintain backward compatibility with Win2k and stay cross-platform
>with Mono. So I need a way to import these APIs if they are there but
>fail gracefully if they aren't. Any ideas?

Use System.Environment.OSVersion to check which OS you're running on.

SendMessage should be available on any Windows client OS that .NET
apps run on.

SetWindowTheme is available in Windows XP (i.e. version 5.1) and
later.


Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.n... | http://www.dotneti...
Please reply only to the newsgroup.

phrosty@gmail.com

2/24/2007 4:32:00 PM

0

On Feb 24, 8:07 am, Mattias Sjögren <mattias.dont.want.s...@mvps.org>
wrote:
> >I'm trying to DllImport the SendMessage and SetWindowTheme APIs, but
> >maintain backward compatibility with Win2k and stay cross-platform
> >with Mono. So I need a way to import these APIs if they are there but
> >fail gracefully if they aren't. Any ideas?
>
> Use System.Environment.OSVersion to check which OS you're running on.
>
> SendMessage should be available on any Windows client OS that .NET
> apps run on.
>
> SetWindowTheme is available in Windows XP (i.e. version 5.1) and
> later.
>
> Mattias
>

That doesn't help.

I need to support Win2K, but use SetWindowTheme when available.
I also need to support Mono, but use SendMessage when it is available.

Preferably without resorting to compiling different versions of the
assembly.

The problem with using DllImport is that it causes the assembly to
fail loading if it can't find the .dll or export.

(Mattias Sjögren)

2/25/2007 9:24:00 AM

0


>The problem with using DllImport is that it causes the assembly to
>fail loading if it can't find the .dll or export.

That's not what I'm seeing. DllImports are resolved the first time
they are called. If you never call a function, it doesn't matter if it
exists or not. At least that's the behavior of the CLR, I don't know
if Mono behaves in a different way.


Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.n... | http://www.dotneti...
Please reply only to the newsgroup.