Solved

delphi dll problems !

Posted on 2013-02-04
2
552 Views
Last Modified: 2013-02-19
Dear Experts,
I have a problem with a Delphi written DLL. At initialization, the DLL starts by opening a file of records. Within a loop, it should read each record and put its values into an array. It reads the first record without a problem. When it goes round the loop to read the next record, it gets the wrong values from the record.
When the program runs as a normal Delphi program the problem does not occur. However, when the same program is written as a DLL, the problem occurs.
Are there special rules for DLLs about reading files?
Here is the code where the problem occurs.

try
    AssignFile(FHash, DefaultHashFile);
    Reset(FHash);
    While not eof(FHash) do
   begin
         Read(FHash,ECell);
         //Convert Ecell WideChar array to a unicode string  /
        CharCount:= 1; S:= '';
        repeat
            S:= S+ ECell.Str[CharCount];
            Inc(CharCount);
        until  (ECell.Str[CharCount] =#0 ) or (CharCount >= 30);
          N:= Ecell.Location;
          NameIndex[N].Str:=  S;
        CharCount:= 1; S:= '';
        repeat
            S:= S+ ECell.Phono[CharCount];
            Inc(CharCount);
        until  (ECell.Phono[CharCount] =#0 ) or (CharCount >= 30);
         NameIndex[N].Phono:=  S;
         NameIndex[N].DiskStart:=  ECell.ArrayStart;
         NameIndex[N].DiskDivider:= ECell.ArrayMiddle;
         NameIndex[N].DiskTail:=  ECell.ArrayEnd;
         NameIndex[N].Eastern:= ECell.Eastern;
         NameIndex[N].AltMarked:= -1;
   end;
    Closefile(FHash);
  except
      DisplayMessage('error reading Main Index table contents');
      Closefile(FHash);
      Exit;
  end;
0
Comment
Question by:YousefEisa
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 27

Accepted Solution

by:
Sinisa Vuk earned 250 total points
ID: 38854076
Did you get any exception here? You can debug dll too. Just run dll project with Host application set in Run/Options menu item.

Try to dll source like this:

...

procedure LibraryProc(Reason: Integer);
begin
  case Reason of
    DLL_PROCESS_ATTACH:
      begin
        //your init function goes here
      end;

    DLL_PROCESS_DETACH:
      begin
        //
      end;
  end;
end;

exports
//exports goes here

begin
  DisableThreadLibraryCalls(hInstance);
  DllProc := @LibraryProc;
  LibraryProc(DLL_PROCESS_ATTACH);
end.

Open in new window

0
 
LVL 37

Assisted Solution

by:Geert Gruwez
Geert Gruwez earned 250 total points
ID: 38854127
there isn't (or shouldn't be) a difference when running this code from dll or normal app
in principal > all code is in a unit, the only difference is how the call is started
what is called is essentially the same

behavior of what is called could depend on parameters
but i don't see parameters in your code

what delphi version are you using ?

are you processing the same file ?
> alter the unit and add a message for testing:

AssignFile(FHash, DefaultHashFile);
DisplayMessage('Processing file ' + DefaultHashFile);
...
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Working with hours 3 74
Moving (cutting/pasting) controls in a TTabbedNotebook... 7 48
Sending files from  idTcpServer Socket to idTcpClient 2 52
MS Access from Delphi 31 81
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

733 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