unit CULLibu;{ Unit included to chromulan Delphi package CULLib to run when the package is loaded }
{
  (C) 2000 - 2002 Jindrich Jindrich, Pavel Pisa, PiKRON Ltd.

  Originators of the CHROMuLAN project:

  Jindrich Jindrich - http://www.jindrich.com
                      http://orgchem.natur.cuni.cz/Chromulan/
                      software developer, project coordinator
  Pavel Pisa        - http://cmp.felk.cvut.cz/~pisa
                      embeded software developer
  PiKRON Ltd.       - http://www.pikron.com
                      project initiator, sponsor, instrument developer

  The CHROMuLAN project is distributed under the GNU General Public Licence.
  See file COPYING for details.

  Originators reserve the right to use and publish sources
  under different conditions too. If third party contributors
  do not accept this condition, they can delete this statement
  and only GNU license will apply.
}

interface
uses
  SysUtils, Windows, DLLUtl;

implementation
var
  origdir: string;

type
  TProc = function(AParam:pointer):integer;

const
  WHandle: integer = 0;
  WResult: integer = -1;
  Proc: TProc = nil;
var
  p:pointer;
  s: shortstring;

initialization

  {$I-}
  GetDir(0, origdir);
  try
    ChDir('D:\ULAN\');
    if IOResult <> 0 then
     ChDir(ExtractFilePath(Paramstr(0)));

    {$I+}
    {v0.30}
    WHandle := LoadLibrary('wld');
    if WHandle = 0 then
      exit;
    p := GetProcAddress(WHandle, 'w');
    if p = nil then
      exit;
    Proc := p;
    s := 'b ulanlib';
    WResult := Proc(@s);

    {/v0.30
    WinExec('wl b', SW_HIDE);}
  finally
    ChDir(origdir);
  end;

finalization
  {$I-}
  GetDir(0, origdir);
  try
    ChDir('D:\ULAN\');
    if IOResult <> 0 then
      ChDir(ExtractFilePath(Paramstr(0)));
    {$I+}
    {v0.30}
    if WResult = 0 then begin
      s := 'e ulanlib';
      Proc(@s);
    end;
    if WHandle <> 0 then
      FreeLibrary(WHandle);
    {/v0.30
    WinExec('wl e', SW_HIDE);}
  finally
    ChDir(origdir);
  end;
end.
