Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

delphi dll problems !

Posted on 2013-02-04
2
Medium Priority
?
585 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 28

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

Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

610 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