Sign in Join

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

Mailing lists / lazarus / 2008-11

LoadLibrary fails on WinCE

7 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

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

Pavel Řezníček

Hello everybody,

I'm an enthusiast in Lazarus and our company uses it for a database-related project for PDA (handheld computers).

However, I have a problem running a compiled application on WinCE. It's very strange.
I already reported this error here but it appears in the stable release too and I just find no solution and I want to ;-)
As from behind a mist I recall that version 0.9.24 had no such problem.

It goes to a general question: How do I load a library on WinCE? Is there something I'm doing wrong?

I use the latest official release of Lazarus (0.9.26).

Let's consider this general code:

program LibTest
uses postgres3dyn;
begin
    InitialisePostgres3;
    ReleasePostgres3;
end;
In the postgres3dyn.InitialisePostres3 procedure, you have this code:
    Postgres3LibraryHandle := loadlibrary(pqlib);

And that code fails for me - it means, Postgres3LibraryHandle then returns the nilhandle against what it is then tested on the nest line:

    if Postgres3LibraryHandle = nilhandle then
      begin
      RefCount := 0;
      Raise EInOutError.Create('Can not load PosgreSQL client. Is it
installed? ('+pqlib+')');
      end;

The pqlib constant reads 'libpq.dll'.

I have the library in the same directory as the executable. Should I place it (and its accompanying libraries) somewhere to the system directories?

I don't know if this would make a success because even when I try to rewrite the postgres3dyn unit to load the library from the program's folder (ExtractFilePath(Paramstr(0)) + pqlib), so with the full path, and recompile everything the right way, it still doesn't load.

Thank you for any clues and guidelines.

Pavel ?ezn??ek

Reply by email

Felipe Monteiro de Carvalho
to Pavel Řezníček

1 - make sure you are using loadlibrary from the windows unit and then call GetLastError to see why it failed.

Windows CE has some differences from desktop. I would try putting the library in the windows or windows/system directory or passing the full path to the library.

Felipe Monteiro de Carvalho

Reply by email

Pavel Řezníček
to Felipe Monteiro de Carvalho

Felipe Monteiro de Carvalho napsal(a):

Show quoted text 6 lines
1 - make sure you are using loadlibrary from the windows unit and then call GetLastError to see why it failed. Windows CE has some differences from desktop. I would try putting the library in the windows or windows/system directory or passing the full path to the library.

Thanks, Felipe, for your advise.

Passing the full path to the library is what I already tried. I much appreciate the tip to call the GetLastError function. Please stay tuned, I'll post what this function says and will also try to place the library (well, with its accompanying libraries) in the system directories. As soon as possible ;-)

Pavel

Reply by email

Pavel Řezníček
to Felipe Monteiro de Carvalho: 1 - make sure you are using loadlibrary from the windows unit and then call GetLastError…

Felipe Monteiro de Carvalho napsal(a):

Show quoted text 8 lines
1 - make sure you are using loadlibrary from the windows unit and then call GetLastError to see why it failed. Windows CE has some differences from desktop. I would try putting the library in the windows or windows/system directory or passing the full path to the library.

OK, I didn't manage to catch the error but have got a suspicion about what prevents the library to load instead.

Unfortunately, it seems to be the size (or complexity) of the compiled executable what decides if the library loads or not.

Is it possible that a 20.6 MB large executable program file prevents any additional libraries from loading into memory when run? Smaller programs (starting from 260 kB fpc-only test program and ending up with a 16 MB LCL application) execute well and load the library successfully. Despite that, the final full-job application won't load postgres , there has another bug appeared which prevents me from catching the exact error for now.
And I'm sorry, I switched back to 0.9.24 again (but can return to 26 or SVN for test purposes if really needed).

Is it possible that there's a bottleneck area in the memory, such as what I know to be called "system resources" on other OSes, such as Windows 9X & ME?

What leads me to this way of thinking is that I have set up 256 MB of RAM for the PocketPC emulator. That should suffice for that 20 MB application with even a huge load of some libraries or data.

Any CE specialists? :-)

Thanks in advance,

Pavel

Reply by email

Yury Sidorov
to Pavel Řezníček

From: "Pavel Rezn?cek"

Show quoted text 43 lines
Felipe Monteiro de Carvalho napsal(a): > 1 - make sure you are using loadlibrary from the windows unit and > then > call GetLastError to see why it failed. > > Windows CE has some differences from desktop. I would try putting > the > library in the windows or windows/system directory or passing the > full > path to the library. > > OK, I didn't manage to catch the error but have got a suspicion about what prevents the library to load instead. Unfortunately, it seems to be the size (or complexity) of the compiled executable what decides if the library loads or not. Is it possible that a 20.6 MB large executable program file prevents any additional libraries from loading into memory when run? Smaller programs (starting from 260 kB fpc-only test program and ending up with a 16 MB LCL application) execute well and load the library successfully. Despite that, the final full-job application won't load postgres libraries at all. Furthermore, there has another bug appeared which prevents me from catching the exact error for now. And I'm sorry, I switched back to 0.9.24 again (but can return to 26 or SVN for test purposes if really needed). Is it possible that there's a bottleneck area in the memory, such as what I know to be called "system resources" on other OSes, such as Windows 9X & ME? What leads me to this way of thinking is that I have set up 256 MB of RAM for the PocketPC emulator. That should suffice for that 20 MB application with even a huge load of some libraries or data.

Large .exe and many large .dlls can cause problems on Windows Movile 6 or earlier:

Read this:
http://bolingconsulting.com/blog/?p=4
and this:
http://msdn.microsoft.com/en-us/library/ms836325.aspx

Yury.

Reply by email

Pavel Řezníček
to Patrick Chevalley

Patrick Chevalley napsal(a):

Show quoted text 8 lines
Your program and dll should not be bigger than 3 or 4 MB if you remove debug symbol. There is a "arm-wince-strip.exe" installed with the crosscompiler. _______________________________________________ Lazarus mailing list http://www.lazarus.freepascal.org/mailman/listinfo/lazarus

Yes, exactly!
This utility is my friend from now on.
Thank you very much. I think that everything is clear for now.

Pavel

Reply by email