using UnitSync.dll in 0.6b1

using UnitSync.dll in 0.6b1

Discuss the source code and development of Spring Engine in general from a technical point of view. Patches go here too.

Moderator: Moderators

Post Reply
Betalord
Former Engine Dev
Posts: 543
Joined: 29 Jun 2005, 09:31

using UnitSync.dll in 0.6b1

Post by Betalord »

I am having some problems using new UnitSync.dll since there is so little (or no) documentation (the code is sparsely commented too). For a start I'd like to get all map names. I do it like this (delphi code):

Code: Select all

procedure TForm1.Button1Click(Sender: TObject);
var
  pc: PChar;
begin

  try
    if Init(True, 0) <> 1 then
    begin
      MessageDlg('Failed to initialize unit syncer!', mtError, [mbOK], 0);
      Exit;
    end
    else RichEdit1.Lines.Add('Unit syncer initialized');

    InitArchiveScanner;
    RichEdit1.Lines.Add('Number of maps: ' + IntToStr(GetMapCount));
    pc := GetMapName(0);
    RichEdit1.Lines.Add('First map''s name: ' + pc);
    UnInit;

  except
    RichEdit1.Lines.Add('Failed!');
    Exit;
  end;
end;
It always crashes at GetMapName(0), GetMapCount returns correct value. What am I doing wrong? Here are function interfaces that I translated to Delphi:

Code: Select all

type
  Float = Single;

  PMapInfo = ^TMapInfo;
  TMapInfo =
  record
    description: PChar;
    tidalStrength: Integer;
    gravity: Integer;
    maxMetal: Float;
    extractorRadius: Integer;
    minWind: Integer;
    maxWind: Integer;
  end;

function Init(isServer: Boolean; id: Integer): Integer; stdcall; external 'UnitSync.dll' name 'Init';
procedure UnInit; stdcall; external 'UnitSync.dll' name 'UnInit';
function ProcessUnits: Integer; external 'UnitSync.dll' name 'ProcessUnits';
function GetCurrentList: PChar; stdcall; external 'UnitSync.dll' name 'GetCurrentList';
procedure AddClient(id: Integer; unitList: PChar); external 'UnitSync.dll' name 'AddClient';
procedure RemoveClient(id: Integer); external 'UnitSync.dll' name 'RemoveClient';
function GetClientDiff(id: Integer): PChar; external 'UnitSync.dll' name 'GetClientDiff';
procedure InstallClientDiff(diff: PChar); external 'UnitSync.dll' name 'InstallClientDiff';
function GetUnitCount: Integer; external 'UnitSync.dll' name 'GetUnitCount';
function GetUnitName(unit_: Integer): PChar; external 'UnitSync.dll' name 'GetUnitName';
function GetFullUnitName(unit_: Integer): PChar; external 'UnitSync.dll' name 'GetFullUnitName';
function IsUnitDisabled(unit_: Integer): Integer; external 'UnitSync.dll' name 'IsUnitDisabled';
function IsUnitDisabledByClient(unit_: Integer; clientId: Integer): Integer; external 'UnitSync.dll' name 'IsUnitDisabledByClient';
function InitArchiveScanner: Integer; stdcall; external 'UnitSync.dll' name 'InitArchiveScanner';
procedure AddArchive(name: PChar); stdcall; external 'UnitSync.dll' name 'AddArchive';
procedure AddAllArchives(root: PChar); stdcall; external 'UnitSync.dll' name 'AddAllArchives';
function GetMapCount: Integer; external 'UnitSync.dll' name 'GetMapCount';
function GetMapName(index: Integer): PChar; external 'UnitSync.dll' name 'GetMapName';
function GetMapInfo(name: PChar; outInfo: PMapInfo): Integer; external 'UnitSync.dll' name 'GetMapInfo';
// GetMinimap returns void*, I cast it as PByte though
function GetMinimap(filename: PChar; miplevel: Integer): PByte; external 'UnitSync.dll' name 'GetMinimap';
function GetPrimaryModCount: Integer; external 'UnitSync.dll' name 'GetPrimaryModCount';
function GetPrimaryModName(index: Integer): PChar; external 'UnitSync.dll' name 'GetPrimaryModName';
function GetPrimaryModIndex(name: PChar): Integer; external 'UnitSync.dll' name 'GetPrimaryModIndex';
Betalord
Former Engine Dev
Posts: 543
Joined: 29 Jun 2005, 09:31

Post by Betalord »

Ah, I forgot to put "stdcall" at some function interfaces. It works now.
User avatar
dinamik
Posts: 94
Joined: 26 Jul 2005, 11:52

Post by dinamik »

Betalord wrote:Ah, I forgot to put "stdcall" at some function interfaces. It works now.
Please Betalord, can you explane:
What program can compile "TA Spring" open source,
"Delphi"(what version ?) or "Visual C++ 6" ?
Betalord
Former Engine Dev
Posts: 543
Joined: 29 Jun 2005, 09:31

Post by Betalord »

Spring was compiled with Visual C++ 7.1 (VS.NET 2003), I am using Delphi just to access some functions in unitsync.dll.
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Post by AF »

VC++ 6 doesnt have the necessary template support to build spring. And GCC at the moment doesnt support the code due to its stricter syntax rules, though it will compile with the linux port.
Post Reply

Return to “Engine”