Jump to content
slacky

Writing a plugin for SCAR (In FPC).. Not working (TIntArray)

Recommended Posts

Well, as the topic states, I'm tryin' to write a plugin for scar but I constantly bump in to some sort of problem. Now the only thing I actually need is to be able to "transfer" (from/and to) arrays more spesific: T2DIntArray (Array of array of Integer)... Yet something that simple is giving me a hard time.

 

So I know the plugin "works", as the plugin is able to send/recieve Integers, strings was partial working (seemed to have encoding truble) - tried AnsiString...

 

Anyways, all I need is to be able to, is to send an array (T2DIntArray) from Scar, and get the result-array (T2IntArray) back.

 

 

I havn't actually tried with T2DIntArray, but I tried a basic Array of Integer.. The result was: "Access voilation at address 058BFE09...".


library TestPlugin;
{$mode objfpc}{$H+}

uses
SysUtils,
Classes;

Type
TIntArray = Array of Integer;

//Test function: '' NOT working last time I checked ''
function TIAFuncTest: TIntArray; Stdcall;
var
Arr: TIntArray;
begin
SetLength(Arr, 2);
Arr[0] := 645;
Arr[1] := 321;
Result := Arr;
end;

//Test procedure: '' working last time I checked ''
procedure IntProcTest(var T: Integer); Stdcall;
begin
T := T * 10;
end;


{=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=]
Export our functions, name, information etc...
All that is needed for scar to see this as a DLL.
[=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=}
//Count of functions that will be exported...
function GetFunctionCount(): Integer; stdcall; export;
begin Result := 2; end;

//Information about our functions... And seems to be linking am as well. I've tried PAnsiChar
function GetFunctionInfo(x: Integer; var ProcAddr: Pointer; var ProcDef: PChar): Integer; stdcall;
begin
case x of
0:
begin
ProcAddr := @TIAFuncTest;
StrPCopy(ProcDef, 'function TIAFuncTest: TIntArray;');
end;
1:
begin
ProcAddr := @IntProcTest;
StrPCopy(ProcDef, 'procedure IntProcTest(var T: Integer);');
end;
else
x := -1;
end;
Result := x;
end;

exports GetFunctionCount;
exports GetFunctionInfo;

begin
end.
[/Code]

[i]Edit:[/i] I managed to get parts of the TIntArray, more exactly the first index (Arr[0] := 645;)... It was simply enough to change the function to a procedure... But the first index does not really cut it... Haha

:P

 

>> I've looked at the

SPS-source for SCAR, and see some parts that I miss (not that I can see it matters..). I also noted that it was a .dpr file (delphi), so I have a feeling i'll be needing to use Delphi?? <-- Is it so? I also took a look at the source for

 

In both thoes examples I see: "Uses FastShareMem" <--- Is that what i'm missing to get it working?

FastShareMem.pas is ofcourse written Delphi so am I forced to use delphi?..

 

If only someone could give me some pointers, and/or some good tips. Or even better: A code example of how to do this, I would be SO HAPPY!

:D

 

 

[b]EDIT (Of topic):[/b] After 5 years of service my monitor "finally" decided to [u]die[/u].. :'( So now I had to put my 37 inch TV to use.. And my TV is not made for this, pixels get's blurry, and it's only HD.. FUCK! This is giving me a headache... And ofc, it's Sunday.. I can't even go to the store to look for a cheap new monitor..

"Wizzyplugin", my include does not seem wrong... Edited by slacky
Arrrg!
Link to comment
Share on other sites

EDIT (Of topic): After 5 years of service my monitor "finally" decided to die.. :'( So now I had to put my 37 inch TV to use.. And my TV is not made for this, pixels get's blurry, and it's only HD.. FUCK! This is giving me a headache... And ofc, it's Sunday.. I can't even go to the store to look for a cheap new monitor..

 

Sorry I don't know the solution to your problems (try Delphi maybe?)

 

But you could try craigslist or a pawn shop for a monitor lol.

 

I'm sure Freddy can help. Catch him on IRC/here.

Link to comment
Share on other sites

I'm aware that i'm using the outdated library-architecture, but honestly there's a lack on documentation (and preferably some examples) on that part, so I found my self using the old api.

 

But if you would be able to give me some pointers when you get back, it would be much appreciated! : )

 

 

As for my monitor problem, I actually managed to get a fine 19" screen that'll do for now! It feels a little small, but i'll get used to it!

Link to comment
Share on other sites

I'm aware that i'm using the outdated library-architecture, but honestly there's a lack on documentation (and preferably some examples) on that part, so I found my self using the old api.

 

But if you would be able to give me some pointers when you get back, it would be much appreciated! : )

 

 

As for my monitor problem, I actually managed to get a fine 19" screen that'll do for now! It feels a little small, but i'll get used to it!

 

What were you on before lol?

 

I'm on a 14" (900p max) laptop dualsetup with a 23" (1080p max) LCD monitor via compRGB

Link to comment
Share on other sites

First I downloaded borlands delphi 8, which I later noted was 100 years old. So I went to my friend google and asked some questions. He told me about embarcadero, but they did not help me, instead they offered to take my money. And I said "hell NO!" and walked away.

So I asked google again, he told me that I could look at Wikipedia. So I did that, Wiki told me that embarcadero is the current holder of delphi, so i tought to my self that I would have to pay money to get a delphi-compiler...

 

Umm, so.. Where can I get a delphi-compiler? Should I use borlands old delphi 8? This requres me to get some REALLY old SDK's...

 

 

Wanted, not that much bigger ;)

Edited by slacky
Link to comment
Share on other sites

They used to offer a free scaled down version of Delphi (similiar to how Visual Studio offers a free scaled down version). The current owners decided this was a bad thing (Delphi has always been owned by people who know shit about marketing/getting people to use the product) They now offer a "light" version you have to buy for some silly amount (couple hundred dollars).

 

So the answer is your old version of Delphi and take your chances or Fpc and take your chances.

Link to comment
Share on other sites

Well, the tought of downloading something as closed as Delphi does not get me in a good mood. So, that wont happen. I'll give FPC some tries..

 

Freddy, is SCAR Titan in line of sight? You posted a pre alpha(was it?) a few years back, but I never heard of it after that.

 

- - - Updated - - -

 

Bixby Sayz, would you be so kind to upload the file!? I might just be able to grab something from it.

Link to comment
Share on other sites

Well, the tought of downloading something as closed as Delphi does not get me in a good mood. So, that wont happen. I'll give FPC some tries..

 

Freddy, is SCAR Titan in line of sight? You posted a pre alpha(was it?) a few years back, but I never heard of it after that.

 

- - - Updated - - -

 

Bixby Sayz, would you be so kind to upload the file!? I might just be able to grab something from it.

 

Titan, not so ,much, but I am working on something big :)

 

As for your code:

 

Make sure GetFunctionInfo has ProcDef as PAnsiChar, I think this is the default for fpc, but it doesn't hurt to make sure, SCAR will not work with a PWideChar, which is the default for PChar in Delphi 2009 and up.

You don't need the begin at the bottom.

I'd recommend "$mode delphi" over "$mode objfpc".

 

EDIT: Also, the reason why it might not be working is that you're missing the FastShareMem unit.

Edited by Freddy
Link to comment
Share on other sites

Yes, true indeed. I figured out about "$Mode DELPHI", I also know that chars are defult Ansi. As a side not I tested it anyways...

 

What I did not yet know was that I needed FastShareMem... This is indeed a bigger chalange, i'll see what I can do.

 

Thanks for your feedback! :)

Link to comment
Share on other sites

If it's the version I downloaded a day or two ago, ye... Some problems there. It wont work with FPC-delphimode, multiple errors: EG:

- Identifier not found TMemoryManagerEx..

- Identifier not found GetMemoryManagerState

 

Etc... The list is long.

Link to comment
Share on other sites

If it's the version I downloaded a day or two ago, ye... Some problems there. It wont work with FPC-delphimode, multiple errors: EG:

- Identifier not found TMemoryManagerEx..

- Identifier not found GetMemoryManagerState

 

Etc... The list is long.

 

Well, those are part of Delphi, not FPC, it's not surprising...

Link to comment
Share on other sites

Bixby Sayz, would you be so kind to upload the file!? I might just be able to grab something from it.

 

Nvm. Just tried it using passing simple integers to a function and it generates a run time error same as you were getting. So no further along using Delphi plugin than you got.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
  • Create New...