Solved

Problems with dll - win98 and winXP

Posted on 2004-04-02
12
820 Views
Last Modified: 2010-08-05
hi,

I have a dll (Delphi 5) compiled in Win2k environment. If a copy in win98 machines - don't work. In a Win2k or WinXP machines - no problems.

The Handle returned after loadlibrary is 0 and error code is 0.


Tank's.
0
Comment
Question by:antenor
  • 6
  • 5
12 Comments
 
LVL 19

Expert Comment

by:Melih SARICA
ID: 10740126
Post the Source of ur dll calling code and Dll's initialize code

...
0
 

Author Comment

by:antenor
ID: 10740215

DLL code:
======

library Material;
...

procedure LibInit;
begin
     {Código de inicialização da Dll}
     F_PesquisaGlobal  := TF_PesquisaGlobal.Create(Application);
     F_PesquisaGlobal2 := TF_PesquisaGlobal2.Create(Application);
     F_Erro := TF_Erro.Create(Application);
     ShortDateFormat   := 'dd/mm/yyyy';
end;
...

BEGIN
     LibInit;
END.

Calling code:
========
var
   DLLHandle : hwnd;
   FullLibraryName : string;

begin
...

           FullLibraryName := DiretorioTMP+LibraryName;
           DLLHandle := LoadLibrary(Pchar(LowerCase(FullLibraryName)));

  ShowMessage('Handle: '+IntToStr(DLLHandle));
  ShowMessage('Error: '+IntToStr(GetLastError));

     end;
end;


0
 
LVL 26

Accepted Solution

by:
Russell Libby earned 500 total points
ID: 10740964
Try calling GetLastError before going further in your app, just to make sure the code is not being reset by another api (behind the scenes).

eg

var
   DLLHandle : hwnd;
   dwError: DWORD;
   FullLibraryName : string;

begin
...

          FullLibraryName := DiretorioTMP+LibraryName;
          DLLHandle := LoadLibrary(Pchar(LowerCase(FullLibraryName)));
         if (DLLHandle = 0) then
         begin
            dwError:=GetLastError;
            ShowMessage(SysErrorMessage(dwError));
         end
         else
            ShowMessage('Handle: '+IntToStr(DLLHandle));

---------------

I have never seen a case where LoadLibrary fails, and GetLastError returns 0. (Have never seen anything documented on this in the MSDN either). Let us know what the results are....

Regards,
Russell



0
 

Author Comment

by:antenor
ID: 10741100
my windows 98 language is brazilian portuguese, but message are:

"Espaço Insuficiente de armazenamento para processar este comando"

in english are

"Insuficient space for processing command"

0
 

Author Comment

by:antenor
ID: 10741144
ahhh....


The error code is "8"

0
 
LVL 26

Expert Comment

by:Russell Libby
ID: 10741166

Thats a help, but can you can tell me what dwError is set to as well?  This will help me narrow down the problem to the exact cause.

Thanks,
Russell
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 26

Expert Comment

by:Russell Libby
ID: 10741197
Ahh.....

that helps. From the msdn, there a few notations of why a dll may work on xp (NT core systems), and not on 95/98.

------------------

Size of In-Memory Resource Table Exceeds 64 KB

When a 32-bit DLL is loaded on a computer that is running Windows 95 or Windows 98, the operating system creates an in-memory resource table to index the various types of resources that are contained within the DLL. The maximum size for this table is 65,535 bytes. If the table size exceeds this limit, the LoadLibrary function call fails with error code 8 (ERROR_OUT_OF_MEMORY).

The in-memory table requires 16 bytes for each resource within the DLL. A named resource requires an additional number of bytes equal to the length of the string plus one. Finally, about 100 bytes is required for alignment and indexing within the table. Thus, a DLL has an upper limit of about 4089 resources on Windows 95 and Windows 98, assuming none are named.

The sample code in the "More Information" section of this article can be used to compile a utility that determines the required size of the in-memory resource table that is generated for a given DLL.

Name Offset Exceeds 64 KB

When a DLL is generated, the resource compiler stores the names of all named resources in a contiguous block of memory in the DLL. This block of memory makes up the resource Names Table. Another portion of the file is used to index all resources (both named and unnamed). This part of the file is the Resource Directory. For each named resource, the entry in the directory contains an offset value that points to the name of the resource in the Names Table. If any of these offset values exceed 65,535 bytes, the LoadLibrary function call fails with error code 8 (ERROR_OUT_OF_MEMORY).

The generation of this table is completely handled by the resource compiler and cannot be controlled by the developer. For this reason, it is best to avoid named resources.

The sample code in the "More Information" section of this article can be used to compile a utility that determines whether the name offsets within a given DLL are valid.


CAUSE
All of these limitations are necessary to support backward compatibility with 16-bit versions of Windows. They do not apply to Windows NT or Windows 2000. However, for compatibility across Windows platforms, it is best to ensure that all 32-bit DLLs conform to the constraints of Windows 95 and Windows 98.


0
 

Author Comment

by:antenor
ID: 10742514
ok,

But, a resource mencioned in article, are a export clausules ? or exists another soluction for this problem?

I delete some lines in the "exports" but... the error is showed.
0
 
LVL 26

Expert Comment

by:Russell Libby
ID: 10742734

Resources meaning resource strings, bitmaps, etc. Use a resource editor to take a look at the dll (you could also use the one in the {delphi}\demos\resxplor to view it) to determine how many resource names you have in there.

Because you are using a form in the dll, and carrying along the vcl baggage, you most likely have a quite a few resources in the dll. According to the msdn notes,

<quote>
The in-memory table requires 16 bytes for each resource within the DLL. A named resource requires an additional number of bytes equal to the length of the string plus one. Finally, about 100 bytes is required for alignment and indexing within the table. Thus, a DLL has an upper limit of about 4089 resources on Windows 95 and Windows 98, assuming none are named.
<end quote>

So 4089 is the max limit, and will be even less for those resources that have names.

---------

Russell

0
 

Author Comment

by:antenor
ID: 10744004
ok, tank you for help.

Do exists an application for a calculate the resource table size?  the "resxplor" don't give the total size, but amount of the resources.

0
 
LVL 26

Expert Comment

by:Russell Libby
ID: 10744046

I can't really say one way or the other, as I don't know. Sorry I can't help further.

Russell
0
 

Author Comment

by:antenor
ID: 10744185
ok, tank's.

Antenor
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Delphi cmd execution 6 42
Printing problem 2 73
Working with hours 3 31
Moving (cutting/pasting) controls in a TTabbedNotebook... 7 10
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
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…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

746 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

12 Experts available now in Live!

Get 1:1 Help Now