* * *

Author Topic: Cannot try... loadlibrary() except.. on windows mobile?  (Read 3883 times)

JohnvdWaeter

  • Full Member
  • ***
  • Posts: 168
    • http://www.jvdw.nl
Cannot try... loadlibrary() except.. on windows mobile?
« on: February 07, 2008, 10:21:26 am »
Hi all,

 I use:

Code: [Select]

try
 AHandle:=Loadlibrary(libname)
except
 AHandle:=0
end;


In WM 5 and 6 I have no problem, because the library exists. In Windows Mobile 4 this library does not exist. Therefore I want to prevent errormessages by using Try/Except.

However, if I use an arbitrary name for the lib (that certainly does not exist), all WM4, 5 and 6 throw an exception that "some of the elements could not be found".

I hoped the try.. except.. construction would prevent such  an error. Is there another way to check the existance of the library without throwing an error?

tia!
John


[/code]

Marc

  • Administrator
  • Hero Member
  • *
  • Posts: 2484
RE: Cannot try... loadlibrary() except.. on windows mobile?
« Reply #1 on: February 07, 2008, 11:54:56 am »
LoadLibrary is a winapi function. Winapi functions never throw an exception.

According to MSDN:
Return values:
  A handle to the module indicates success.
  NULL indicates failure.
  To get extended error information, call GetLastError.


So when AHandle = 0 then LoadLibrary failed. The MSDN doesn't meantion anything on showing dialogs.

The dialog you describe I only get when I statically reference to some library.
//--
{$I stdsig.inc}
//-I still can't read someones mind
//-Bugs reported here will be forgotten. Use the bug tracker

JohnvdWaeter

  • Full Member
  • ***
  • Posts: 168
    • http://www.jvdw.nl
RE: Cannot try... loadlibrary() except.. on windows mobile?
« Reply #2 on: February 07, 2008, 12:13:10 pm »
Hi Marc,

OK... I guess I'm missing the point where it comes to statically and dynamically referencing the library...

If I have a line in code that looks like:

 function getMydata(...) external external_lib name GetMydata ;

that is a static reference, right?

Thanks for clarification!

John

Marc

  • Administrator
  • Hero Member
  • *
  • Posts: 2484
RE: Cannot try... loadlibrary() except.. on windows mobile?
« Reply #3 on: February 07, 2008, 12:16:50 pm »
Yes that is a static reference. These references are resolved by the windows image loader, the moment an executable image is loaded.
//--
{$I stdsig.inc}
//-I still can't read someones mind
//-Bugs reported here will be forgotten. Use the bug tracker

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus