Sign in Join

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

Mailing lists / fpc-pascal / 2012-06

Unit initialization in dll initialization for arm/WinCE

7 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

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

kyan

Hello all,

Does unit initialization in libraries (.dll files) work in arm/WinCE? Somehow it seems that even code placed in the library initialization begin end block isn't executed either. I found some bug reports (e.g.
0019404) suggesting that this didn't work for arm/Linux but it has been added to the trunk. But not for arm/WinCE?

If this is the case, is there a feasible workaround to call unit initialization sections manually? I am not statically linking the libraries by means of "external" clauses but I am using LoadLibrary() and GetProcAddress() to communicate with the dll from the exe, so I could create an exported function in the dll and call it manually from the exe after loading if I could somehow iterate in it the unit initialization sections and call them.

Thank you in advance.

Constantine.

Reply by email

Sven Barth
to kyan
kyan wrote
Does unit initialization in libraries (.dll files) work in arm/WinCE?

From the startup code of arm-wince I don't see why it should not work...

Somehow it seems that even code placed in the library initialization begin end block isn't executed either.

How did you test this?

I found some bug reports (e.g. 0019404) suggesting that this didn't work for arm/Linux but it has been added to the trunk. But not for arm/WinCE?

Linux and Windows have different schemes for library initialization, so even if it was the case that arm-wince did not work it would not help to apply the fix for arm-linux there as well.

Regards,
Sven

Reply by email

kyan
to Sven Barth

OK, I apologize. It seems that the problem lies elsewhere. The fact that library initialization seems to be deferred until you do a GetProcAddress() confused me. The problem is that function GetModuleName() is stubbed out in WinCE (and Linux):

unit SysUtils.inc;
function GetModuleName(Module: HMODULE): string;
begin
{$ifdef MSWINDOWS}
  SetLength(Result,MAX_PATH);
  SetLength(Result,GetModuleFileName(Module, Pchar(Result),Length(Result)));
{$ELSE}
  Result:='';
{$ENDIF}
end;

The function GetModuleFileName() exists (although it is unicode) in WinCE: http://msdn.microsoft.com/en-us/library/ms908441.aspx

And from what I've found in the web a Linux implementation is possible using dladdr().

Sven Barth wrote 29 lines
Am 11.06.2012 12:25, schrieb kyan: > Does unit initialization in libraries (.dll files) work in arm/WinCE? From the startup code of arm-wince I don't see why it should not work... > Somehow it seems that even code placed in the library initialization > begin end block isn't executed either. How did you test this? > I found some bug reports (e.g. > 0019404) suggesting that this didn't work for arm/Linux but it has > been added to the trunk. But not for arm/WinCE? Linux and Windows have different schemes for library initialization, so even if it was the case that arm-wince did not work it would not help to apply the fix for arm-linux there as well. Regards, Sven _______________________________________________ fpc-pascal maillist  -   http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply by email

Sven Barth
to kyan
"kyan" wrote
OK, I apologize. It seems that the problem lies elsewhere. The fact that library initialization seems to be deferred until you do a GetProcAddress() confused me.

It might't be that Windows (or CE only) initalizes a library only if you use GetProcAddress at least once... I have not tested that, but it might be an idea. If that is the case we can not influence that.

Show quoted text 10 lines
The problem is that function GetModuleName() is stubbed out in WinCE (and Linux): unit SysUtils.inc; function GetModuleName(Module: HMODULE): string; begin {$ifdef MSWINDOWS} SetLength(Result,MAX_PATH); SetLength(Result,GetModuleFileName(Module,
Pchar(Result),Length(Result)));
Show quoted text 10 lines
{$ELSE} Result:=''; {$ENDIF} end; The function GetModuleFileName() exists (although it is unicode) in WinCE: http://msdn.microsoft.com/en-us/library/ms908441.aspx And from what I've found in the web a Linux implementation is possible using dladdr().

If you want you can create a bug report. WinCE might likely be solved then, but I can't comment on Linux or other *nix systems.

Regards,
Sven

Reply by email

kyan
to Sven Barth

Thank you for your reply Sven.

It might't be that Windows (or CE only) initalizes a library only if you use GetProcAddress at least once... I have not tested that, but it might be an idea. If that is the case we can not influence that.

No need to, it really doesn't matter since one has to do a GetProcAddress() in order to be able to call anything inside a dll. Maybe it is an optimisation that has to do with resource dlls.

If you want you can create a bug report. WinCE might likely be solved then, but I can't comment on Linux or other *nix systems.

It's OK, I've wrapped GetModuleName() in a function of my own that works as expected in Delphi, Win32, Win64 and WinCE and will stick to that. Will report when I find some time.

Reply by email

Tomas Hajny
to Sven Barth: It might't be that Windows (or CE only) initalizes a library only if you use…
Sven Barth wrote
Am 12.06.2012 15:20 schrieb "kyan" :

.
.

Show quoted text 25 lines
> The problem is that function > GetModuleName() is stubbed out in WinCE (and Linux): > > unit SysUtils.inc; > > function GetModuleName(Module: HMODULE): string; > begin > {$ifdef MSWINDOWS} > SetLength(Result,MAX_PATH); > SetLength(Result,GetModuleFileName(Module, Pchar(Result),Length(Result))); > {$ELSE} > Result:=''; > {$ENDIF} > end; > > The function GetModuleFileName() exists (although it is unicode) in > WinCE: http://msdn.microsoft.com/en-us/library/ms908441.aspx > > And from what I've found in the web a Linux implementation is possible > using dladdr(). If you want you can create a bug report. WinCE might likely be solved then, but I can't comment on Linux or other *nix systems.

In any case, it's wrong that the implementation is placed in the platform independent include file instead of the respective sysutils.pp files. :-(

Tomas

Reply by email

Sven Barth
to Tomas Hajny
Tomas Hajny wrote 32 lines
On Tue, June 12, 2012 18:04, Sven Barth wrote: > Am 12.06.2012 15:20 schrieb "kyan": . . >> The problem is that function >> GetModuleName() is stubbed out in WinCE (and Linux): >> >> unit SysUtils.inc; >> >> function GetModuleName(Module: HMODULE): string; >> begin >> {$ifdef MSWINDOWS} >> SetLength(Result,MAX_PATH); >> SetLength(Result,GetModuleFileName(Module, > Pchar(Result),Length(Result))); >> {$ELSE} >> Result:=''; >> {$ENDIF} >> end; >> >> The function GetModuleFileName() exists (although it is unicode) in >> WinCE: http://msdn.microsoft.com/en-us/library/ms908441.aspx >> >> And from what I've found in the web a Linux implementation is possible >> using dladdr(). > > If you want you can create a bug report. WinCE might likely be solved > then, > but I can't comment on Linux or other *nix systems. In any case, it's wrong that the implementation is placed in the platform independent include file instead of the respective sysutils.pp files. :-(

That can be corrected as well when support for Windows CE is added :D

Regards,
Sven

Reply by email