Solved

delphi dll problems !

Posted on 2013-02-04
2
543 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
2 Comments
 
LVL 25

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 36

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

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…
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…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

760 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

21 Experts available now in Live!

Get 1:1 Help Now