Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace ClassLibrary1;
- interface
- uses System.Runtime.InteropServices;
- type
- [StructLayout(LayoutKind.Sequential)]
- TestRecord = public record
- public
- X: Int32;
- Y: Int32;
- end;
- TestClass = public class
- private
- protected
- public
- [UnmanagedExport('Test', CallingConvention.StdCall)]
- class procedure Test(out B: TestRecord);
- [UnmanagedExport('TestString', CallingConvention.StdCall)]
- class procedure TestString(out AString: WideString);
- [UnmanagedExport('TestStringRes', CallingConvention.StdCall)]
- class function TestStringRes: String;
- end;
- implementation
- class procedure TestClass.Test(out B: TestRecord);
- begin
- B.X := 25;
- B.Y := -10;
- end;
- class procedure TestClass.TestString(out AString: WideString);
- begin
- AString := 'A wide string';
- end;
- class function TestClass.TestStringRes: String;
- begin
- Result := 'A wider string';
- end;
- end.
- unit untTest1;
- interface
- uses
- Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
- Dialogs, StdCtrls;
- type
- TForm1 = class(TForm)
- btn1: TButton;
- procedure btn1Click(Sender: TObject);
- private
- { Private declarations }
- public
- { Public declarations }
- end;
- TTestRecord = packed record
- X, Y: integer;
- end;
- procedure Test(out B: TTestRecord);stdcall; external 'ClassLibrary1.dll' name 'Test';
- procedure TestString(out AString: Widestring);stdcall; external 'ClassLibrary1.dll' name 'TestString';
- function TestStringRes: Widestring;stdcall; external 'ClassLibrary1.dll' name 'TestStringRes';
- var
- Form1: TForm1;
- implementation
- {$R *.dfm}
- procedure TForm1.btn1Click(Sender: TObject);
- var
- B: TTestRecord;
- AString: widestring;
- begin
- Test(B);
- ShowMessage(IntToStr(B.X));
- ShowMessage(IntToStr(B.Y));
- ShowMessage(TestStringRes);
- SetLength(AString, 100);
- TestSTring(AString);
- ShowMessage(AString);
- end;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement