?
Solved

delphi dll problems !

Posted on 2013-02-04
2
Medium Priority
?
562 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 750 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 38

Assisted Solution

by:Geert Gruwez
Geert Gruwez earned 750 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

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses
Course of the Month8 days, 21 hours left to enroll

764 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