Solved

Problem with LoadLibrary

Posted on 2000-04-25
15
2,248 Views
Last Modified: 2012-08-14
Has anyone had problems loading a DLL dynamically in Delphi 5?

It works fine on my machine but if I copy it to another, it fails to load.  LoadLibrary returns 0, and if I check GetLastError, that returns 0 too!

There are no exceptions raised.

This is really puzzling me.

Is it that I've got some run-time component that the other machine hasn't?  I would have thought that would raise some kind of error.  If that is likely, what's the best strategy for finding out which one.

I doubt it though, because the main .exe has been compiled by me and that runs fine.  It's just the .dll that won't load.

Thanks.
0
Comment
Question by:mhoughton
15 Comments
 
LVL 3

Expert Comment

by:f15iaf
Comment Utility
check if a dll file exists on other computer and located in "c:\windows\system" directory.
0
 
LVL 10

Expert Comment

by:Lischke
Comment Utility
Well, there can be several reasons. First if of course to check if the DLL exists. Then you need to specify the extension all the time (LoadLibrary('MyDll.DLL');). Don't rely on automatisms. Additionally, if the DLL is not in one of the search pathes (%windir%, %windir%\system, %windir%\system32 etc. or the folder from where the application started) then you need to specify the full path to the DLL too.

Do you run your application on different OSs (say Win98 and WinNT)? If yes on which does it not work?

Ciao, Mike
0
 
LVL 1

Expert Comment

by:mscatena
Comment Utility
There are differences between Win95/98 and WinNT/2000 regarding the file extension. In one of them you may no supply the extension, in the other you must.

Always specify the file extension, even if it's  ".DLL".
0
 

Author Comment

by:mhoughton
Comment Utility
It's in the same directory as the EXE and I've tried it with and without the .dll extension.

I've even tried forcing the full path and copying it to windows\system.

My development machine is Win98 v2 and the test machine is Win98 v1.

I'm very puzzled.

Is there any way to get windows to give up what the problem is?  As I said, GetLastError tells me nothing.
0
 

Expert Comment

by:mike_shay
Comment Utility
I had the same problem with Delphi 4.
Then I tried in DLL to open some connection to database through ODBC. The application was terminated without raising any exception.
You can try to debug the DLL separately, as an EXE, to find a problem.

Sincerely Yours, Michael Shaikevich.
0
 

Author Comment

by:mhoughton
Comment Utility
It's in the same directory as the EXE and I've tried it with and without the .dll extension.

I've even tried forcing the full path and copying it to windows\system.

My development machine is Win98 v2 and the test machine is Win98 v1.

I'm very puzzled.

Is there any way to get windows to give up what the problem is?  As I said, GetLastError tells me nothing.
0
 
LVL 10

Expert Comment

by:Lischke
Comment Utility
Mmmh, in this case I can only guess. Maybe the DLL initialization fails on one machine? In this case Windows (GetLastError) returns an error code set by the DLL (if I recall correctly). If this error code is not set then 0 is returned.

Another idea: you haven't accidently used a Word variable for the result of LoadLibrary? Quite unlikely, I know, but in the lack of better ideas...

Ciao, Mike
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 10

Expert Comment

by:Lischke
Comment Utility
mike_shay,

your behaviour is very unpolite! You proposed an answer (which isn't really one) although you see that we already discussing the problem. Please use comments if you aren't the first one in a discussion.

mhoughton,

don't use your browser's refresh, otherwise your formular data will be resend. There's a link on each page (upper right corner) labeled "Reload Question".

Ciao, Mike
0
 

Author Comment

by:mhoughton
Comment Utility
I'll reject the answer for now, because I'm pretty sure it isn't right.

The DLL just isn't loading.  No code is called because the library handle returned is 0.

If I'm wrong, then I'll eat my words and get you to repost.

A lot of the answers so far would cause problems generally, but as I said it works fine on the development machine.  I may be able to test it on another machine later.

As for hitting refresh, yes I realised that about a milisecond after doing it. DOH!
0
 

Author Comment

by:mhoughton
Comment Utility
I've just written a little test app with a listbox and a button...

procedure TForm1.Button1Click(Sender: TObject);
var
  LibHandle : LongWord;
begin
  ListBox1.Items.Add('Loading...');

  LibHandle := LoadLibrary('EPRINT_WINDOWS.DLL');

  ListBox1.Items.Add('Handle: '+IntToStr(LibHandle));
  ListBox1.Items.Add('Error: '+IntToStr(GetLastError));

  if LibHandle <> 0 then
  begin
    ListBox1.Items.Add('Freeing...');
    FreeLibrary(LibHandle);
    ListBox1.Items.Add('Done');
  end;
end;

I've put the two files in isolation on a shared drive and run them on each PC.

On my PC it produces:

Loading...
Handle: 20905984
Error: 0
Freeing...
Done

On the other PC it produces:

Loading...
Handle: 0
Error: 1157
Freeing...
Done

So at least I've got it to produce an error code.

1157 is ERROR_DLL_NOT_FOUND.  So I guess that the DLL is statically linking another DLL which it can't find.
0
 
LVL 10

Expert Comment

by:Lischke
Comment Utility
Mmmh, this sounds like a good reason. You can check the import table of the DLL with tdump.exe in the Delphi5\Bin folder.

Ciao, Mike
0
 

Author Comment

by:mhoughton
Comment Utility
Hurray!  Got it.

It was the dreaded Borland Memory Manager, borlndmm.dll.

I had it (obviously), the other PC didn't.

You'd have thought it would have been a bit more forthcoming with error messages.  Oh well.

Thanks for all the help everyone, particularly Lischke.

Now, how do I distribute these points?
0
 
LVL 10

Accepted Solution

by:
Lischke earned 200 total points
Comment Utility
You can only accept a comment in this question and open a dummy question for the other guy or you delete this question and open two dummy questions.

I'd prefer the first, although it will cost you more points, because this will save the discussion from this question.

BTW: Who will you award additional points? I think I'm the only one/first one who gave useful information. The missing DLL extension was mentioned first by me and Michael's contribution was ... mmh ... a bit too general.

Ciao, Mike
0
 
LVL 27

Expert Comment

by:kretzschmar
Comment Utility
hmm, mhoughton,
at least you've solved it mostly byself,
grade the expert which does mostly helped you in this q. not me, of course :-)
meikl ;-)
0
 

Author Comment

by:mhoughton
Comment Utility
I think you have been by far the most helpful.

The DLL extension and location were red herrings - although useful information none the less.

But the most useful comment was pointing me towards tdump.  I always forget about this utility.

Anyway, thanks very much everyone, but Lischke gets it.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now