Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Interop / February 2007

Tip: Looking for answers? Try searching our database.

Dynamic DllImport

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
phrosty@gmail.com - 24 Feb 2007 14:57 GMT
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?
Mattias Sjögren - 24 Feb 2007 16:07 GMT
>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

Signature

Mattias Sjögren [C# MVP]  mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.

phrosty@gmail.com - 24 Feb 2007 16:32 GMT
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
[quoted text clipped - 10 lines]
>
> 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 - 25 Feb 2007 09:24 GMT
>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

Signature

Mattias Sjögren [C# MVP]  mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.


Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.