Results 1 to 18 of 18

Thread: .dll and types?

  1. #1
    Join Date
    Oct 2011
    Posts
    805
    Mentioned
    21 Post(s)
    Quoted
    152 Post(s)

    Default .dll and types?

    Simba doesn't see my dll plugin ,since I used custom type (TIntegerArray). How to fix that ?

    This is my dll file:

    SCAR Code:
    library Mylib;


    uses
      FastShareMem,
      SysUtils,
      Classes,
      Windows,
      Graphics;

    {$R *.res}


    Function MiddleBox(X1, Y1, X2, Y2 : Integer): TPoint; stdcall;
    Begin
      Result.X := (X1 + X2) Shr 1;
      Result.Y := (Y1 + Y2) Shr 1;
    End;

    type
      TIntegerArray = array of integer;
      T2dIntegerArray = array of TIntegerArray;

    Function BmpToTIA(DC : integer): T2dIntegerArray; Stdcall;
    Var
      I, J ,w ,h : Integer;
      B : TBitmap;
    Begin
      try
      B := TBitmap.Create;
      B.Canvas.Handle := DC;
      w := B.Width;
      h := B.Height;
      SetLength(Result,w);
      For I:= 0 to w-1 Do
        SetLength(Result[I],h);
      For I := 0 to w-1 Do
        For J := 0 to h-1 Do
           Result[I][J] := B.Canvas.Pixels[I, J];
      B.Free;
      except
      writeln('Exeption in BmpToTIA');
      end;
    End;

    function GetFunctionCount(): Integer; stdcall; export;
    begin
      Result := 2;
    end;

    function GetFunctionInfo(x: Integer; var ProcAddr: Pointer; var ProcDef: PChar): Integer; stdcall;
    begin
      case x of
        0:
          begin
            ProcAddr := @MiddleBox;
            StrPCopy(ProcDef, 'function MiddleBox(X1, Y1, X2, Y2 : Integer): TPoint;');
          end;
        1:
          begin
            ProcAddr := @BmpToTIA;
            StrPCopy(ProcDef, 'Function BmpToTIA(DC : integer): T2dIntegerArray');
          end;
      else
        x := -1;
      end;
      Result := x;
    end;

    exports GetFunctionCount;
    exports GetFunctionInfo;

    end.

  2. #2
    Join Date
    Oct 2009
    Location
    Stockton, CA
    Posts
    2,040
    Mentioned
    0 Post(s)
    Quoted
    1 Post(s)

    Default

    Join the IRC! irc.rizon.net:6667/srl | SQLite (0.99rc3+) | SRL Doc | Simba Doc | Extra Simba Libraries (openSSL & sqlite3)
    Quote Originally Posted by #srl
    10:45 < Toter> daphil when can get sex anyday I want
    10:45 < Toter> he is always on #SRL
    "A programmer is just a tool which converts caffeine into code"

  3. #3
    Join Date
    Oct 2011
    Posts
    805
    Mentioned
    21 Post(s)
    Quoted
    152 Post(s)

    Default

    Thx ,you are fast

    Everything is working now.
    Last edited by bg5; 04-25-2012 at 10:27 PM.

  4. #4
    Join Date
    Oct 2011
    Posts
    805
    Mentioned
    21 Post(s)
    Quoted
    152 Post(s)

    Default

    After all ,I have some trouble. I followed template ,but I can't get it to work:

    SCAR Code:
    library test;

    uses
      FastShareMem,
      SysUtils,
      Classes,
      Windows,
      Graphics;

    {$R *.res}

    type
      TIntegerArray = array of integer;
      T2dIntegerArray = array of TIntegerArray;

     function GetHigh(i : TIntegerArray) : integer;
    var
    x : integer;
    begin
      writeln('Result is:');
      x := High(i);
      writeln(x);
      Result := x;
    end;

     function GetHigh2(var i : TIntegerArray) : integer;
    var
    x : integer;
    begin
      writeln('Result is:');
      x := High(i);
      writeln(x);
      Result := x;
    end;

    function GetTypeCount() : Integer; stdcall; export;
    begin
      Result := 2;
    end;

    function GetTypeInfo(x: integer; var sType, sTypeDef : string): integer; stdcall;
    begin
      result := x;
      case (x) of
        0 : begin
          sType := 'TIntegerArray';
          sTypeDef := 'array of integer;';
          end;
        1 : begin
          sType := 'T2dIntegerArray';
          sTypeDef := 'array of TIntegerArray;';
        end
      else
        result := -1;
      end;
    end;

    function GetFunctionCount(): Integer; stdcall; export;
    begin
      Result := 2;
    end;

    function GetFunctionInfo(x: Integer; var ProcAddr: Pointer; var ProcDef: PChar): Integer; stdcall;
    begin
      case x of
        0:
          begin
            ProcAddr := @GetHigh;
            StrPCopy(ProcDef, 'function GetHigh(i : TIntegerArray) : integer;');
          end;
        1:
          begin
            ProcAddr := @GetHigh2;
            StrPCopy(ProcDef, 'function GetHigh2(var i : TIntegerArray) : integer;');
          end;
      else
        x := -1;
      end;
      Result := x;
    end;

    exports GetFunctionCount;
    exports GetFunctionInfo;
    exports GetTypeCount;
    exports GetTypeInfo;
    begin
    end.

    This gives me error:
    Simba Code:
    program new;
    //{$I SRL/srl.simba}
    {$loadlib test.dll}
    var
    i :Tintegerarray;
    begin
    i := [3,3,3,3,3];
    writeln(High(i));
    writeln(GetHigh(i));
    writeln( GetHigh2(i)); //[Error] (11:19): Type mismatch at line 10
    end.
    What is odd error gives second function with var in argument ,first not.

    ...Then if I uncomment {$I SRL/srl.simba} another error:
    Code:
    Simba\Includes\SRL/SRL/core/simba.simba(90:24): Type mismatch at line 89
    What's wrong with my code?

  5. #5
    Join Date
    Apr 2007
    Posts
    581
    Mentioned
    1 Post(s)
    Quoted
    2 Post(s)

    Default

    You must convert an integer to a String using IntToStr(); before you can write it to the console.

  6. #6
    Join Date
    Oct 2011
    Posts
    805
    Mentioned
    21 Post(s)
    Quoted
    152 Post(s)

    Default

    Quote Originally Posted by ShawnjohnSJ View Post
    You must convert an integer to a String using IntToStr(); before you can write it to the console.
    Uhm ,you don't need ,try it.

  7. #7
    Join Date
    Feb 2011
    Location
    The Future.
    Posts
    5,600
    Mentioned
    396 Post(s)
    Quoted
    1598 Post(s)

    Default

    Simba Code:
    library test;

    {$mode objfpc}{$H+}

    uses
      FastShareMem, SysUtils, Classes, Windows, Graphics;

    {$R *.res}

    type
      TIntegerArray = array of integer;
      T2DIntegerArray = array of TIntegerArray;

    function GetHigh(i: TIntegerArray): integer; Register;
    var
    x : integer;
    begin
      writeln('Result is:');
      x := High(i);
      writeln(x);
      Result := x;
    end;

    function GetHigh2(var i: TIntegerArray): integer; Register;
    var
    x : integer;
    begin
      writeln('Result is:');
      x := High(i);
      writeln(x);
      Result := x;
    end;

    {                                       EXPORTS                                }


    procedure SetPluginMemoryManager(MemMgr : TMemoryManager); stdcall; export;
    begin
      SetMemoryManager(MemMgr);
    end;


    {                                    EXPORT TYPES                              }


    function GetTypeCount(): Integer; stdcall; export;
    begin
      Result := 2;
    end;

    function GetTypeInfo(x: Integer; var sType, sTypeDef: string): integer; stdcall;
    begin
      case x of
        0: begin
            sType := 'TCharArray';
            sTypeDef := 'Array of Char;';
          end;
        else
          Result := -1;
      end;
    end;



    {                                    EXPORT FUNCS                              }

    function GetFunctionCount(): Integer; stdcall; export;
    begin
      Result := 2;
    end;

    function GetFunctionCallingConv(x : Integer) : Integer; stdcall; export;
    begin
      Result := 0;
      case x of
         0..1 : Result := 1;
      end;
    end;

    function GetFunctionInfo(x: Integer; var ProcAddr: Pointer; var ProcDef: PChar): Integer; stdcall; export;
    begin
      case x of
        0:
          begin
            ProcAddr := @GetHigh;
            StrPCopy(ProcDef, 'Function GetHigh(i: TIntegerArray): Integer');
          end;
        1:
          begin
            ProcAddr := @GetHigh2;
            StrPCopy(ProcDef, 'Function GetHigh2(var i: TIntegerArray): Integer;');
          end;
      else
        x := -1;
      end;
      Result := x;
    end;


    //Exports
    exports SetPluginMemoryManager;

    //Types
    exports GetTypeCount;
    exports GetTypeInfo;

    //Functions
    exports GetFunctionCount;
    exports GetFunctionInfo;
    exports GetFunctionCallingConv;

    begin
    end.

  8. #8
    Join Date
    Oct 2011
    Posts
    805
    Mentioned
    21 Post(s)
    Quoted
    152 Post(s)

    Default

    I compiled this ,only removed {$mode objfpc}{$H+},because of "invalid compiler directive 'mode' ",and fixed GetTypeInfo. Still same errors. :/ I use Delphi7 ,maybe should I try other compiler?

  9. #9
    Join Date
    Oct 2009
    Location
    Stockton, CA
    Posts
    2,040
    Mentioned
    0 Post(s)
    Quoted
    1 Post(s)

    Default

    Use Lazarus..
    Join the IRC! irc.rizon.net:6667/srl | SQLite (0.99rc3+) | SRL Doc | Simba Doc | Extra Simba Libraries (openSSL & sqlite3)
    Quote Originally Posted by #srl
    10:45 < Toter> daphil when can get sex anyday I want
    10:45 < Toter> he is always on #SRL
    "A programmer is just a tool which converts caffeine into code"

  10. #10
    Join Date
    Apr 2007
    Posts
    581
    Mentioned
    1 Post(s)
    Quoted
    2 Post(s)

    Default

    Sorry, last time I scripted in SCAR you had to use IntToStr to convert an integer to a string.

  11. #11
    Join Date
    Oct 2009
    Location
    Stockton, CA
    Posts
    2,040
    Mentioned
    0 Post(s)
    Quoted
    1 Post(s)

    Default

    Quote Originally Posted by ShawnjohnSJ View Post
    Sorry, last time I scripted in SCAR you had to use IntToStr to convert an integer to a string.
    If you are just WriteLn'ing the integer by itself you do not need to convert it:
    Simba Code:
    writeln(i);
    If you are combining it with a string literal you do have to convert it:
    Simba Code:
    writeln('i: ' + ToStr(i)); // could also use IntToStr however ToStr converts floats, bools, etc.
    Join the IRC! irc.rizon.net:6667/srl | SQLite (0.99rc3+) | SRL Doc | Simba Doc | Extra Simba Libraries (openSSL & sqlite3)
    Quote Originally Posted by #srl
    10:45 < Toter> daphil when can get sex anyday I want
    10:45 < Toter> he is always on #SRL
    "A programmer is just a tool which converts caffeine into code"

  12. #12
    Join Date
    Feb 2006
    Location
    Amsterdam
    Posts
    13,692
    Mentioned
    146 Post(s)
    Quoted
    130 Post(s)

    Default

    I started to work on this yesterday: http://docs.villavu.com/simba/simbaref/plugins.html although I'm not sure if it is on any interest you to.

    Anyway, you should generally write plugins for Simba with lazarus if you want to directly share Pascal types (that is arrays and strings). In all other languages (Delphi included) this is not possible without dirty hacks. So FastShareMem won't help.



    The best way to contact me is by email, which you can find on my website: http://wizzup.org
    I also get email notifications of private messages, though.

    Simba (on Twitter | Group on Villavu | Website | Stable/Unstable releases
    Documentation | Source | Simba Bug Tracker on Github and Villavu )


    My (Blog | Website)

  13. #13
    Join Date
    Oct 2011
    Posts
    805
    Mentioned
    21 Post(s)
    Quoted
    152 Post(s)

    Default

    What a shame I can't get it to work Still same errors :
    Simba reject my dll:
    Code:
    Simba\Includes\SRL/SRL/core/simba.simba(90:24): Type mismatch at line 89
    And when I comment {$I SRL/srl.simba} it gives type mismatch in second function(which uses var as argument).

    That's my lazarus code:
    Simba Code:
    library project1;
     {$mode objfpc}{$H+}

    uses
      SysUtils, Classes, Windows, Interfaces ,Graphics ;

    {$R *.res}

    type
      TIntegerArray = array of integer;
      T2DIntegerArray = array of TIntegerArray;

    function GetHigh(i: TIntegerArray): integer; Register;
    var
    x : integer;
    begin
      writeln('Result is:');
      x := High(i);
      writeln(x);
      Result := x;
    end;

    function GetHigh2(var i: TIntegerArray): integer; Register;
    var
    x : integer;
    begin
      writeln('Result is:');
      x := High(i);
      writeln(x);
      Result := x;
    end;

    {                                       EXPORTS                                }


    procedure SetPluginMemoryManager(MemMgr : TMemoryManager); stdcall; export;
    begin
      SetMemoryManager(MemMgr);
    end;


    {                                    EXPORT TYPES                              }


    function GetTypeCount(): Integer; stdcall; export;
    begin
      Result := 2;
    end;

    function GetTypeInfo(x: integer; var sType, sTypeDef : string): integer; stdcall;
    begin
      result := x;
      case (x) of
        0 : begin
          sType := 'TIntegerArray';
          sTypeDef := 'array of integer;';
          end;
        1 : begin
          sType := 'T2dIntegerArray';
          sTypeDef := 'array of TIntegerArray;';
        end
      else
        result := -1;
      end;
    end;



    {                                    EXPORT FUNCS                              }

    function GetFunctionCount(): Integer; stdcall; export;
    begin
      Result := 2;
    end;

    function GetFunctionCallingConv(x : Integer) : Integer; stdcall; export;
    begin
      Result := 0;
      case x of
         0..1 : Result := 1;
      end;
    end;

    function GetFunctionInfo(x: Integer; var ProcAddr: Pointer; var ProcDef: PChar): Integer; stdcall; export;
    begin
      case x of
        0:
          begin
            ProcAddr := @GetHigh;
            StrPCopy(ProcDef, 'Function GetHigh(i: TIntegerArray): Integer');
          end;
        1:
          begin
            ProcAddr := @GetHigh2;
            StrPCopy(ProcDef, 'Function GetHigh2(var i: TIntegerArray): Integer;');
          end;
      else
        x := -1;
      end;
      Result := x;
    end;


    //Exports
    exports SetPluginMemoryManager;

    //Types
    exports GetTypeCount;
    exports GetTypeInfo;

    //Functions
    exports GetFunctionCount;
    exports GetFunctionInfo;
    exports GetFunctionCallingConv;

    begin
    end.
    + I added LCL to required packets in project inspector


    btw. Delphi's output dll has 97 KB ,when Lazarus creates 13 MB ! ,lol . It push into dll a lot of unnecessary stuff!

    I started to work on this yesterday: http://docs.villavu.com/simba/simbaref/plugins.html although I'm not sure if it is on any interest you to.
    That's great idea ,could spare a lot of time ppl like me

  14. #14
    Join Date
    Oct 2011
    Posts
    805
    Mentioned
    21 Post(s)
    Quoted
    152 Post(s)

    Default

    bump

    Anyone can compile this code in lazarus and check if dll works? So I will know if it's problem with code or something with my system or settings.

    code to check dll:
    Simba Code:
    program new;
    {$I SRL/srl.simba}
    {$loadlib test.dll}
    var
    i :Tintegerarray;
    begin
    i := [3,3,3,3,3];
    writeln(High(i));
    writeln(GetHigh(i));
    writeln( GetHigh2(i));
    end.

  15. #15
    Join Date
    Nov 2007
    Location
    46696E6C616E64
    Posts
    3,069
    Mentioned
    44 Post(s)
    Quoted
    302 Post(s)

    Default

    Don't you have to export GetTypeInfo() too?
    There used to be something meaningful here.

  16. #16
    Join Date
    Feb 2011
    Location
    The Future.
    Posts
    5,600
    Mentioned
    396 Post(s)
    Quoted
    1598 Post(s)

    Default

    Quote Originally Posted by beginner5 View Post
    bump

    Anyone can compile this code in lazarus and check if dll works? So I will know if it's problem with code or something with my system or settings.

    I don't have lazarus installed atm but when I used to make plugins for encryption, I remember having to strip them.

    http://villavu.com/forum/showthread....012#post902012

    This will shrink it from that 13mb to around 0.4 or something close to 1mb.. Can't remember. Also I think you need LibMML includes :S See this for my old plugin examples: http://villavu.com/forum/showthread.php?t=69447
    I am Ggzz..
    Hackintosher

  17. #17
    Join Date
    Oct 2011
    Posts
    805
    Mentioned
    21 Post(s)
    Quoted
    152 Post(s)

    Default

    This will shrink it from that 13mb to around 0.4 or something close to 1mb.. Can't remember. Also I think you need LibMML includes :S See this for my old plugin examples: http://villavu.com/forum/showthread.php?t=69447
    Thx ,It's awesome.

    LibMML ,you mean MufasaTypes unit?

    @E:
    I added some units you have in your plugin.
    SCAR Code:
    SysUtils, Classes, Windows, Interfaces ,Graphics ,
     Forms, Dialogs, LCLType, Controls, IniFiles, MufasaTypes ;

    Still same errors :/

  18. #18
    Join Date
    Oct 2011
    Posts
    805
    Mentioned
    21 Post(s)
    Quoted
    152 Post(s)

    Default

    Ok...so I resolved one issue with type mismatch - instead of exporting types I included MufasaTypes unit.
    But i have still problem with arrays:


    SCAR Code:
    library project1;
     {$mode objfpc}{$H+}

    uses
      Classes,SysUtils, FileUtil, Interfaces  ,MufasaTypes;

     type
      T3DIntegerArray = array of T2DIntegerArray;
      T4DIntegerArray = array of T3DIntegerArray;

    function GetHigh(i: TIntegerArray): integer; Register;
    var
    x : integer;
    begin
      writeln('Result is:');
      x := High(i);
      writeln(x);
      Result := x;
    end;

    function MakeArr( hi: integer): TIntegerArray; Register;
    var
    a : integer;
    begin
      SetLength(Result,hi+1);
      for a:=0 to hi do
          Result[a] := a;
    end;

    {                                       EXPORTS                                }


    procedure SetPluginMemoryManager(MemMgr : TMemoryManager); stdcall; export;
    begin
      SetMemoryManager(MemMgr);
    end;


    {                                    EXPORT TYPES                              }

    function GetTypeCount(): Integer; stdcall; export;
    begin
      Result := 2;
    end;

    function GetTypeInfo(x: Integer; var sType, sTypeDef: string): integer; stdcall; export;
    begin
      case x of
        0: begin
            sType := 'T3DIntegerArray';
            sTypeDef := 'array of T2DIntegerArray;';
          end;
        1: begin
            sType := 'T4DIntegerArray';
            sTypeDef := 'array of T3DIntegerArray;';
          end;
        else
          x := -1;
      end;
      Result := x;
    end;
    {                                    EXPORT FUNCS                              }

    function GetFunctionCount(): Integer; stdcall; export;
    begin
      Result := 2;
    end;

    function GetFunctionCallingConv(x : Integer) : Integer; stdcall; export;
    begin
      Result := 0;
      case x of
         0..1 : Result := 1;
      end;
    end;

    function GetFunctionInfo(x: Integer; var ProcAddr: Pointer; var ProcDef: PChar): Integer; stdcall; export;
    begin
      case x of
        0:
          begin
            ProcAddr := @GetHigh;
            StrPCopy(ProcDef, 'Function GetHigh(i: TIntegerArray): Integer;');
          end;
        1:
          begin
            ProcAddr := @MakeArr;
            StrPCopy(ProcDef, 'function MakeArr( hi: integer): TIntegerArray;');
          end;
      else
        x := -1;
      end;
      Result := x;
    end;


    //Exports
    exports SetPluginMemoryManager;

    //Types
    exports GetTypeCount;
    exports GetTypeInfo;

    //Functions
    exports GetFunctionCount;
    exports GetFunctionInfo;
    exports GetFunctionCallingConv;

    begin
    end.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •