The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 1,860 other subscribers

Archive for the ‘.NET’ Category

Windows applications: Icons and the Shell; names, sizes, etc.

Posted by jpluimers on 2015/12/23

When adding Icons to your Windows applications a few things matter.

Selecting the icon resource

The icon selected by the Windows Shell (for modern Windows versions usually Windows Explorer), is the one with the lowest ID. When there is no icon with an ID, it selects the icon with the lowest name.

Icons in Windows can have both IDs and names. Even though API calls like LoadIcon have an lpIconName parameter, you can convert the ID to a name using MAKEINTRESOURCE.

There is a difference between the format of an ICO file and the icon resource (technically two things: RT_GROUP_ICON resource directory and an RT_ICON resource for each image) contains a list of icon images.

The selection process is on the RT_GROUP_ICON, and then within the group on the ICON itself.

For the RT_GROUP_ICON process, modern Windows versions still use the algorithm used by Windows 95 (not that by Windows NT):

Windows NT simply chooses the first resource listed in the application’s RC script. On the other hand, Windows 95’s algorithm is to choose the alphabetically first named group icon if one exists. If one such group resource does not exist, Windows chooses the icon with the numerically lowest identifier.

For a Delphi application the icon shown must be named MAINICON, since the below source fragment has been in TApplication.Create(…) like forever:

FIcon.Handle := LoadIcon(MainInstance, 'MAINICON');

Which means that if you want the Windows Shell (usually Explorer) to select that one, all other icon resources in your executable must have names that sort after MAINICON.

Selecting the icon within a resource

For the individual icon, the process is more complex. Even the summary is. To summarise the summary to select an icon for the requested size:

  1. Prefer the image closest in size.
  2. When more images of that size are present, match on the best color depth for the display.
  3. When no color depth matches, prefer the image with the greatest color depth not exceeding the color depth of the display.
  4. When all exceed the color depth, prefer the lowest color depth.

For color depth, treat 8 or more bits per pixel as equal. So there is no advantage of including a 16×16 256-color image and a 16×16 16-color image in the same resource — the system will simply choose the first one it encounters. When the display is in 8-bpp mode, the system will choose a 16-color icon over a 256-color icon, and will display all icons using the system default palette.

I’m not completely confident how 32-bit precisely fits in this scheme. If someone knows, please let me know and I’ll include the information.

I usually take 32-bit color images here which are actually True Color 24-bit + alpha channel RGBA images.

What about requested size?

Actually there are a lot of sizes that Windows can request, and there are many articles about it, some of which contradict each other.

From what I assembled, these are the sizes you need to run on Windows XP / Server 2003 and up:

  • 16×16
  • 20×20
  • 24×24
  • 32×32
  • 40×40
  • 48×48
  • 64×64
  • 96×96
  • 128×128
  • 256×256 (for Windows XP / Server 2003: do not compress this size)

I might be wrong, so here are some links:

–jeroen

via:

Posted in .NET, Delphi, Development, Software Development, The Old New Thing, Windows Development | Leave a Comment »

.NET/C#: PasteText command line tool as reverse of Clip.exe

Posted by jpluimers on 2015/12/15

Quite a while ago I learned about the clip.exe tool.

clip.exe is a nifty tool that allows you to copy console text output to the clipboard. Though shipping with Windows Server 2003, it wasn’t part of Windows XP, but as of Windows Vista it shipped on desktop versions of Windows.

Digging a bit deeper, I found out it was already part of the Windows NT 4 Resource Kit.

So I wrote PasteText:

PasteText: the reverse of clip.exe; pastes Clipboard.GetText() or Clipboard.GetFileDropList() to the standard output.

The full source code is below and in my repository.

There are many examples on the internet about Clipboard.GetText, but there is very little about Clipboard.GetFileDropList. Read the rest of this entry »

Posted in .NET, .NET 3.0, .NET 3.5, .NET 4.0, .NET 4.5, C#, C# 3.0, C# 4.0, C# 5.0, Development, Software Development, The Old New Thing, Windows Development | Leave a Comment »

The coding love – When I read and refactor code of another developer

Posted by jpluimers on 2015/12/09

Thanks Stefan Glienke for this picture:

When I read and refactor code of another developer

When I read and refactor code of another developer

–jeroen

via: The coding love – When I read and refactor code of another developer.

Posted in .NET, About, Delphi, Development, Software Development | 1 Comment »

Wish more people named Peter Sollich for what he did in the Pascal world…

Posted by jpluimers on 2015/12/02

A small video reference to the work that Peter Sollich did for the Pascal world is at around 38:20 in this video: https://www.youtube.com/watch?v=btGj-PocjeU#t=2298

It is where Allen Bauer talks about his early years at Borland. He talks about a German guy there without naming him. It is Peter Sollich (he names them a few time in the newsgroups though).

Peter Sollich came from Germany where he had written a Turbo Pascal compatible compiler for the Atari ST (it used a m68k Motorola 68000 CPU which is a 32-bit processor on the internal side with a 16-bit wide data bus (transporting 16-bit words) on the outside using a 24-bit address (so it can address 16 mebibytes of memory) – hence ST for Sixteen/Thirtytwo).

Borland bought the source code which formed the base for the current 32-bit x86 compiler implementations of both Delphi and C++ Builder (they hired him as a contractor to do the port).

Rumour goes that Peter wrote many parts of the x86 code emitter on the flight from Europe to the USA.

Before the ST era there was already a CP/M Modula-2 compiler written by Peter Sollich and Martin Odersky which Borland bought even earlier and was turned into Turbo Modula-2.

For people interested, here are some links with ore details – where possible I saved them in the WayBack machine as sites tend to Ditch historically important information:

–jeroen

Posted in .NET, Borland Pascal, Delphi, Development, Pascal, Software Development, Turbo Pascal | 4 Comments »

C# Settings reminder

Posted by jpluimers on 2015/11/26

As a reminder to self: Settings are nice (too bad they advertise them as Windows Forms Application Settings, as they are just as useful for other assemblies), but be aware…

When using Settings.Default, it will get the values to the state of the app.config (or defaults if there is no app.config) of the assembly that defined the settings, not the app.config of the starting process.

This is unless your settings are merged into the app.config of the starting process.

–jeroen

Posted in .NET, .NET 1.x, .NET 2.0, .NET 3.0, .NET 3.5, .NET 4.0, .NET 4.5, Development, Software Development | Leave a Comment »

Raise specific exceptions like InvalidOperationException, not generic ones like ApplicationException.

Posted by jpluimers on 2015/11/25

Code Analysis in Visual Studio objects against using very generic exception types:

CA2201 Do not raise reserved exception types

‘BusinessClass<T>.StopProcessing()’ creates an exception of type ‘ApplicationException’, an exception type that is not sufficiently specific and should never be raised by user code. If this exception instance might be thrown, use a different exception type.

Company.Departement.Functionality BusinessClass.cs 157

Indeed ApplicationException and SystemException are bad (both mapping to also very generic COM HRESULT values COR_E_APPLICATION / -2146232832 / 0x80131600 and COR_E_SYSTEM / -2146233087 / 0x80131501).

Using InvalidOperationException is much nicer in this case. It still maps to a COM exception (in this case COR_E_INVALIDOPERATION / -2146233079 / 0x80131509).

–jeroen

Posted in .NET, .NET 3.0, .NET 3.5, .NET 4.0, .NET 4.5, C#, C# 3.0, C# 4.0, C# 5.0, C# 6 (Roslyn), Development, Software Development | Leave a Comment »

Ensure you know the state of an instance.

Posted by jpluimers on 2015/11/24

A while ago, I came across a class having (among other members) two methods named like this:

  • Start
  • Stop

Within one of the other members of the class, I had to (temporarily) Stop processing, then Start it again.

But I couldn’t, as neither Start, nor Stop would make a record of the state it left the instance in.

Always ensure you know the state of an instance.

So I added the state, and tests to ensure a Stop/Start change was indeed not breaking things.

–jeroen

Posted in .NET, .NET 1.x, .NET 2.0, .NET 3.0, .NET 3.5, .NET 4.0, .NET 4.5, C#, C# 1.0, C# 2.0, C# 3.0, C# 4.0, C# 5.0, C# 6 (Roslyn), Delphi, Delphi 10 Seattle, Delphi 2007, Delphi 2009, Delphi 2010, Delphi XE, Delphi XE2, Delphi XE3, Delphi XE4, Delphi XE5, Delphi XE6, Delphi XE7, Delphi XE8, Development, Software Development | 1 Comment »

Stack Exchange – Android Apps on Google Play

Posted by jpluimers on 2015/11/18

I missed when the StackExchange App for Android was finally launched, but I totally agree with Paul Lammertsma:

Exceeds expectations This was a long time coming, but it didn’t disappoint. It’s a great aid for a regular on Stack Overflow like me!

–jeroen

via Stack Exchange – Android Apps on Google Play.

Posted in .NET, Delphi, Development, Pingback, Power User, Software Development, Stackoverflow | Leave a Comment »

Universal Android ADB driver for Windows – koush/UniversalAdbDriver

Posted by jpluimers on 2015/11/17

If you ever need a universal Android ADB driver for Windows, then use this one: koush/UniversalAdbDriver.

I never noticed it was there until Koushik Dutta posted about a signing trick on Google+.

Windows drivers need to be signed, so what he does is generate a self signed certificate on the fly during installation, sign the driver install it, and drop the private key of the certificate.

Each installation has its own key, Microsoft is happy, and it is proven the driver signature mechanism in Windows has a hole.

If you want to do similar things, then this commit is what you are looking for: Use a self signed, self destructing signing cert. · e8b78fe · koush/UniversalAdbDriver.

It isn’t rocket science, but not trivial C# either, so this is a great example of something that works.

–jeroen

Posted in .NET, Android, C#, Development, Mobile Development, Software Development | Leave a Comment »

The Power of Open Source… Microsoft .NET and OpenShift: .Net on Linux

Posted by jpluimers on 2015/11/11

Really exiting times ahead: Microsoft .Net on Linux.

It’s not fully ready yet, but to get an idea to learn more about running OpenShift Enterprise 3 and a .NET application based on a Red Hat Enterprise Linux container, here are a few links to get started:

I wish that the demo repository at https://github.com/munchee13/snoopalicious.git and the rhosepaas.com domain were accessible (:

There are other alternatives too, but OpenShift (RedHat) and Microsoft working together is really exiting news to me.

If you’re on other distros, here are some more links:

And of course there has been Mono for a while, which is a different implementation of .NET:

Hopefully this will have search results soon: dnvm opensuse tumbleweed.

–jeroen

Posted in *nix, .NET, Development, Linux, OpenShift, openSuSE, Power User, RedHat, Software Development, SuSE Linux, Tumbleweed | Leave a Comment »