View Single Post
Old Aug 25th, 2004, 8:42 PM   #1
vbtoosharp
Newbie
 
Join Date: Aug 2004
Posts: 5
Rep Power: 0 vbtoosharp is on a distinguished road
The DLL I have created uses a TTimer to update some variables. when I make a call to the DLL it returns the correct values only the first time its called after the first call it returns the same values. reason for them being the same values is that the TTimer is not refreshing the values. now this problem occures when i use the Delphi DLL with a C++ applcation. (for reason unknown this problem does not occure with VB.NET)

this is a problem i have had for a while know and still have no answer for. the link below is one to another fourm that shows some bikering between me and another person about this problem.

feel free to pitch in with some help.

example code, not the actual code I am having the problem with:


  library DelphiDLL;

  uses Windows, extctrls, SysUtils, Classes;

  //------------------------------------------------------------------------------

  type TTicker = class(TTimer)
  public
   Value: Integer;
   procedure Tick(Sender: TObject);
  end;

  procedure TTicker.Tick (Sender: TObject);
  begin
   Value := Value + 1;
  end;

  //------------------------------------------------------------------------------

  var g_ticker: TTicker;

  function GetClockValue(): Integer; export; stdcall;
  begin
   Result := g_ticker.Value;
  end;

  exports GetClockValue;

  begin
   g_ticker := TTicker.Create(nil);
   g_ticker.OnTimer := g_ticker.Tick;
   g_ticker.Value := 1;
   g_ticker.Interval := 100;
   g_ticker.Enabled := True;
  end.



c++ code


#include <windows.h>
#include <stdio.h>

 int main()
 {
  HINSTANCE lib = LoadLibrary("DelphiDLL\\DelphiDLL.dll");

  if (lib)
  {
   typedef int (__stdcall * ClockProc)();

   ClockProc GetClockValue = (ClockProc) GetProcAddress(lib, "GetClockValue");

   if (GetClockValue)
   {
    int time;
    do {
     time = GetClockValue();
     printf("%d\n", time);
    } while (time < 100);
   }

   FreeLibrary(lib);
  }

  return 0;
 }
vbtoosharp is offline   Reply With Quote