Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3236876
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T17:40:21+00:00 2026-05-17T17:40:21+00:00

i have given a chance to my software user to select dll from openfile

  • 0

i have given a chance to my software user to select dll from openfile dialog.(so my user can download dlls form my website and use it with the main project ). everything is working fine and it can even find that dlls is provided by me or selected an invalid dll.but the problem raises if the user selects a renamed file(eg : apple.txt file renamed to apple.dll ). i typed the code like this

try
dllHandle := LoadLibrary( pwidechar(openfiledialog1.filename)) ;

catch
{ showmessage if it is not a dll (but it can be any dll, it checks this is my dll or 3rd party later )}

end;

error message shown by delphi is ‘bad library image selected’

but try catch is not working if the user selects invalid dll it is showing its own error message and struck up.

can anyone help me,i am using delphi 2009

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T17:40:22+00:00Added an answer on May 17, 2026 at 5:40 pm

    There’s no exception to catch because an exception is not raised when LoadLibrary fails; it just returns ‘0’.

    You should check if ‘dllHandle’ is 0 or not, if it is, show the error information to the user by using GetLastError as documented. Alternatively you can use the Win32Check function in the RTL which will raise an exception with the appropriate error message:

    (edit: Documentation of ‘LoadLibrary’ states that: To enable or disable error messages displayed by the loader during DLL loads, use the SetErrorMode function. So if you don’t want the OS to show an additional dialog you’d set the error mode before calling LoadLibrary.)

    var
      dllHandle: HMODULE;
      ErrorMode: UINT;
    begin
      if OpenDialog1.Execute then begin
        ErrorMode := SetErrorMode(SEM_FAILCRITICALERRORS); // disable OS error messages
        try
          dllHandle := LoadLibrary(PChar(OpenDialog1.FileName));
        finally
          SetErrorMode(ErrorMode);
        end;
        if Win32Check(Bool(dllHandle)) then begin  // exception raised if false
          // use the libary
    
          end;
      end;
    end;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been given a DLL (InfoLookup.dll) that internally allocates structures and returns pointers
I have a page upon which a user can choose up to many different
I have given a location defined by latitude and longitude. Now i want to
I have a <table/> in a ViewUserControl that I have given the tag a
I have been given a requirement where I need to support multiple databases in
I have been given two different Microsoft Word document that my virus scanner has
Say I have this given XML file: <root> <node>x</node> <node>y</node> <node>a</node> </root> And I
I am given a problem where I have been given N nodes in a
Have recently been given a project to complete which uses XML quite extensively.Am looking
I have the HTML given below: <ul id=thumbsPhotos> <li src=/images/1alvaston-hall-relaxing-lg.jpg onclick=updatePhoto (this.title)><img src=/images/1alvaston-hall-relaxing-sl.jpg width=56

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.