Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2007-11

NotifyIconData not flexible enougth

7 messages · 4 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Felipe Monteiro de Carvalho

Hello,

The _NOTIFYICONDATA structure and other similar ones on ShellAPI have different versions choosen based on IFDEFs:

       _NOTIFYICONDATAA         = record
                                   cbSize               : DWORD;
                                   hWnd                 : HWND;
                                   uID                  : UINT;
                                   uFlags               : UINT;
                                   uCallbackMessage     : UINT;
                                   hIcon                : HICON;
                                   {$ifdef IELower5}
                                    szTip               : array[0..63] of CHAR;
                                   {$else}
                                    szTip               : array[0..127] of CHAR;
                                   {$endif}
                                   {$ifdef IEhigherEqual5}
                                    dwState             : DWORD;
                                    dwStateMask         : DWORD;
                                    szInfo              : array[0..255] of CHAR;
                                    DUMMYUNIONNAME      : record
                                                           case longint of
                                                               0 : (
uTimeout : UINT );
                                                               1 : (
uVersion : UINT );
                                                              end;
                                    szInfoTitle : array[0..63] of CHAR;
                                    dwInfoFlags : DWORD;
                                   {$endif}
                                   {$ifdef IEHighEq6}
                                    guidItem : GUID;
                                   {$endif}
                                   end;

But this is a problem, because then we can't use new versions of the structure on Lazarus unless we rebuild this package with special options.

Also, the ifdefs talk about Internet Explorer versions. The MS Docs talk about simply structure versions:
http://msdn2.microsoft.com/en-us/library/bb773352.aspx

I would rather use the microsoft nomenclature so it's clear which structure versions we are dealing with.

One solution would be to split the structure in _NOTIFYICONDATAA, _NOTIFYICONDATAA_V5, _NOTIFYICONDATAA_V6, etc

But then we have a problem that the api that uses this structure is typed:

Function Shell_NotifyIconA( dwMessage: Dword;lpData:
PNOTIFYICONDATAA):Bool;external 'shell32.dll' name
'Shell_NotifyIconA';

One solution would be changing lpData type to untyped pointer, so one can use any structure with it.

Any other ideas about this problem, and solutions for it?

thanks,

Felipe Monteiro de Carvalho

Reply by email

Felipe Monteiro de Carvalho
to Felipe Monteiro de Carvalho

By the way, it's necessary to use many versions of the same structure at the same time to achieve a flexible software which can, for example, detect if the system supports version 5 of the structure. If yes, use it to show the BallonHint. If not, use older structure version, and use alternative method to show the BallonHint using a dialog.

I don't know what happens when we use a newer structure version on older windows. Some field sizes changed (szTip), so it would probably break things.

thanks,

Felipe Monteiro de Carvalho

Reply by email

Marco van de Voort
to Felipe Monteiro de Carvalho
Show quoted text 10 lines
By the way, it's necessary to use many versions of the same structure at the same time to achieve a flexible software which can, for example, detect if the system supports version 5 of the structure. If yes, use it to show the BallonHint. If not, use older structure version, and use alternative method to show the BallonHint using a dialog. I don't know what happens when we use a newer structure version on older windows. Some field sizes changed (szTip), so it would probably break things.

I did that translation, and didn't enable those defines for exactly that reason. So that has to be researched first, if any exisiting code can be broken by enabling this (e.g. if it passes sizeof(struct). Probably the winapi decides the version dependning on the size of the structure passed.

Btw, the defines are converted from the MS headers. So this is how MS does it in practice themselves.

Reply by email

Vincent Snijders
to Marco van de Voort
Marco van de Voort wrote
Btw, the defines are converted from the MS headers. So this is how MS does it in practice themselves.

They probably have a dll for each version, so that is not option for fpc, (unless you want to create several units).

Vincent

Reply by email

Marco van de Voort
to Vincent Snijders
Show quoted text 6 lines
Marco van de Voort schreef: > Btw, the defines are converted from the MS headers. So this is how MS does > it in practice themselves. They probably have a dll for each version, so that is not option for fpc, (unless you want to create several units).

Not entirely. It's not like mySQL which are simply incompat. Newer DLLs contain the old implementation and decide the version depending on the size of the record (which they get as separate parameter) which version to use.

The main problem is older code not using sizeof(rec.field) to access them, and a possible increase of minimal version.

Iirc the problem with these DLLs is that on win9x, IE versions also update core Windows DLLs like commctrls and shellapi. So not all win9x versions are homogenous. It is possible to update a win95 to almost win98 level with respect to windows api.

(maybe even IE7 does this on XP too btw, but not much people are interested in this functionality, though it could get important when Vista catches on).

Reply by email

Felipe Monteiro de Carvalho
to Marco van de Voort: I did that translation, and didn't enable those defines for exactly that reason. So that…
Marco van de Voort wrote
I did that translation, and didn't enable those defines for exactly that reason. So that has to be researched first, if any exisiting code can be broken by enabling this (e.g. if it passes sizeof(struct). Probably the winapi decides the version dependning on the size of the structure passed.

I don't want to enable the defines, but rather have many structures, like NOTIFYICONA_V5, NOTIFYICONA_V6, etc

Btw, the defines are converted from the MS headers. So this is how MS does it in practice themselves.

That solution aims at applications using the Windows API directly, not frameworks built on top of it.

To overcode that one can declare their own structure on their code.

Felipe Monteiro de Carvalho

Reply by email

Giulio Bernardi
to Felipe Monteiro de Carvalho

Declare the structure again (in lazarus IIRC there are already some windows types/records redefined) without ifdefs and make it compatible with the latest version. With some care you can use the same structure on all windows versions. In fact usually windows structures are the same "at the beginning" across versions for compatibility reasons. You only need to fill the structure with data you need, set cbSize according to the version supported on the system your software is running on and call the api. Note that fields added in later versions are ignored by windows api that read the structure/their values are meaningless if you asked a windows api to write to the structure.

In your case, you could do something like this:
  LoadLibrary('shell32');
  GetProcAddress(handle,'DllGetVersion');
  DllGetVersion(pversioninforecord);
  if pversioninforecord.dwMajorVersion<=4 then icondata.cbsize:=NOTIFYICONDATAA_V1_SIZE
  else icondata.cbsize:=NOTIFYICONDATAA_V2_SIZE;

Note that DllGetVersion doesn't exist in win95 without IE4, so if getprocaddress fails you know it's v1. Moreover, if it's v1, szTip will be truncated to 64 characters.

I'd like to see ifdefs removed from fpc translations of win32 structures, but as Marco van de Voort said, the problem here is that older code that simply does
icondata.cbsize:=sizeof(icondata)
won't work anymore on systems with libraries older than current versions.

bye,
Giulio
_________________________________________________________________ News, entertainment and everything you care it now! http://www.live.com/getstarted.aspx

Reply by email