Solved

delphi dll problems !

Posted on 2013-02-04
2
553 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …

695 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