• Page:
  • 1
  • 2

TOPIC: accessing a c++ DLL from Rad Studio 10 Delphi

accessing a c++ DLL from Rad Studio 10 Delphi 3 months 1 week ago #14316

How do I access a DLL written in C++ that I have no access to modify from a rad 10 Delphi application
I have this info on the DLL
namespace OOP.RNG
{
public sealed class RNGInfernoServiceManager
{
public const long Zero = 0;
public const long OneBillion = 1000000000;

public static readonly RNGInfernoServiceManager
Current = new RNGInfernoServiceManager();

public RNGInfernoServiceManager()

public long[] CreateArrayOfRandomNumbers(uint arraySize = 1,
long min = Zero,
long max = OneBillion);
}
}

namespace SecurityDriven.Inferno
{
public class CryptoRandom : System.Random
{
public CryptoRandom()

public override int Next();
public override int Next(int maxValue);
public override int Next(int minValue, int maxValue);

public override void NextBytes(byte[] buffer);
public void NextBytes(byte[] buffer, int offset, int count);
public byte[] NextBytes(int count);

public override double NextDouble();

public long NextLong();
public long NextLong(long maxValue);
public long NextLong(long minValue, long maxValue);
}
}

and tried this
unit glirng1;

interface

uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;

type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);


private
{ Private declarations }
public
{ Public declarations }
end;
type
trngv = class
rngvs: array[0..2] of integer;
end;

var
Form1: TForm1;

maxOdds: integer;
haswon: boolean;
rngValues: trngv;

procedure RNGInfernoServiceManager(); external 'ooprng.dll';
procedure CryptoRandom(); external 'ooprng.dll' ;
function CreateArrayOfRandomNumbers(a: integer; b:integer; c: integer):trngv; external 'ooprng.dll';

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
close;
end;



procedure TForm1.Button2Click(Sender: TObject);
begin
maxOdds := 25000000;
rngValues := CreateArrayOfRandomNumbers(2, 0, maxOdds);
if (rngValues.rngvs[0] = rngValues.rngvs[1]) then haswon := true else haswon := false;

end;

end.

If I comment out the lines under button2.click the app runs but does nothing
otherwise I get a 0x000007b error
the DLL in in the appropriate directory

Please Log in or Create an account to join the conversation.

accessing a c++ DLL from Rad Studio 10 Delphi 3 months 1 week ago #14372

That DLL code is using C#, not C++.

Even so, there are only 2 ways to use a DLL in Delphi:

- if the DLL exports flat C style functions.

- if the DLL exposes access to COM objects.

Is your DLL doing either of those? Based on the code you showed, it doesn't appear to be doing so.

That being said, your Delphi code does not match the DLL code you have shown. In the DLL, RNGInfernoServiceManager() and CryptoRandom() are class constructors, not standalone procedures. And CreateArrayOfRandomNumbers() is a class method, not a standalone function, and it returns a dynamically allocated array, not a fixed-sized array.

Even if they were standalone procedures/functions exported by the DLL, like your Delphi code is expecting, your Delphi code is not declaring any calling convention for them, so Delphi's 'register' calling convention will be used, which is not compatible with ANY other compiler except for C++Builder (via its __fastcall calling convention). Most compilers use 'cdecl' or 'stdcall' instead when exporting functions for other compilers to call.

Please Log in or Create an account to join the conversation.

accessing a c++ DLL from Rad Studio 10 Delphi 3 months 1 week ago #14379

attached is the documentation I have for this DLL - if you can show what I am missing I would appreciate it
I have not used a DLL that I did not create before
thanks

Please Log in or Create an account to join the conversation.

accessing a c++ DLL from Rad Studio 10 Delphi 3 months 6 days ago #14396

dwight wrote: attached is the documentation I have for this DLL


There is no attachment present. And even if there were, my experience with this forum server is that attachments simply don't work anyway. Even if the forum shows an attachment is present, it never lets me click on them.

Please Log in or Create an account to join the conversation.

Last Edit: by Remy.

accessing a c++ DLL from Rad Studio 10 Delphi 3 months 5 days ago #14414

try creveltcomputer.com/spec.pdf
I really need to get this figured out

Please Log in or Create an account to join the conversation.

accessing a c++ DLL from Rad Studio 10 Delphi 3 months 2 days ago #14445

That documentation is for a .NET library, which would be consistent with your original example in C#. Since the library is written for .NET, the only ways it can be used in Delphi are either:

1. if it exposes its classes as COM objects, in which case you can use Delphi's native COM interop features.

2. if you install the library into Visual Studio and then write your own Delphi-compatible wrapper for it (exporting flat C style functions, or your own COM objects).

3. if you use AToZed CrossTalk or other similar 3rd party framework for accessing .NET libraries in native Delphi code.
The following user(s) said Thank You: dwight

Please Log in or Create an account to join the conversation.

Last Edit: by Remy.
  • Page:
  • 1
  • 2
Moderators: April Anne