小编İsm*_*can的帖子

64位系统上更大指针的好处是什么?

我试图理解64位编译,所以我在C++ Builder中做了一点测试:

  int i = 12345;
  ShowMessage(i);
  int *pi = &i;
  ShowMessage(sizeof(pi));


  Largeint li = 9223372036854775807;
  ShowMessage(li);
  Largeint *pli = &li;
  ShowMessage(sizeof(pli));
Run Code Online (Sandbox Code Playgroud)

当我将此程序编译为64位时,指针的大小增加到8个字节(64位).

指针大小增加的优点是什么?

c++ 64-bit pointers c++builder

14
推荐指数
2
解决办法
2367
查看次数

实现接口在运行时有什么好处?

我正在尝试了解TVirtualInterface类.

{$APPTYPE CONSOLE}

uses
  SysUtils, Rtti;

type
  ISpecificInterface = interface(IInvokable)
    ['{281D8B97-397E-430A-895A-9CA4E1F5FB5F}']
    procedure SpecificProcedure;
  end;

procedure AProcedure(Method: TRttiMethod; const Args: TArray<TValue>;
  out Result: TValue);
begin
  Writeln(Method.ToString);
end;

var
  ISpecificInterfaceInstance: ISpecificInterface;

begin
  ISpecificInterfaceInstance := TVirtualInterface.Create
    (TypeInfo(ISpecificInterface), AProcedure) as ISpecificInterface;

  ISpecificInterfaceInstance.SpecificProcedure;

end. // TVirtualInterface ref. counter is decremented
Run Code Online (Sandbox Code Playgroud)

在运行时实现接口有什么好处?

空间的用途是什么?

delphi oop rtti

6
推荐指数
1
解决办法
209
查看次数

使用RTTI获取变量名称

我试图像这样使用RTTI获取变量名.

这是我的测试.

type
  TStringHelper = record helper for string
    function Name: string;
  end;

  TMyRecord = record
    Field1:string;
  end;

implementation

{ TStringHelper }
function TStringHelper.Name: string;
var
 context : TRttiContext;
begin
 context := TRttiContext.Create;
 result := context.GetType(@Self).Name; // return empty
 context.Free;
end;

procedure TForm2.FormCreate(Sender: TObject);
var
 r : TMyRecord;
begin
  ShowMessage(r.Field1.Name);
end;
Run Code Online (Sandbox Code Playgroud)

TRttiType返回的名称为空.

有没有办法得到变量名?

delphi rtti

6
推荐指数
1
解决办法
819
查看次数

使用地址调用 .Net 函数

我尝试从本机代码并通过虚拟地址调用 .NET 函数。我编写了一个简单的类库,其中有一个类和静态方法,我使用dnSpy进行浏览

我还检查了 ImageBase 值是 0x10000000

using System;

// Token: 0x02000002 RID: 2
public class Class1 : object
{
    // Token: 0x06000001 RID: 1 RVA: 0x00002050 File Offset: 0x00000250
    public static int Calculate(int x, int y)
    {
        return x + y;
    }
}
Run Code Online (Sandbox Code Playgroud)

我正在查看LoadLibrary的文档,其中写着:

将指定的模块加载到调用进程的地址空间中。

当我调用计算函数时,我收到 AV 错误。

ConsoleApplication1.exe 中的 0x10002050 处抛出异常:0xC0000005:执行位置 0x10002050 时发生访问冲突。发生

#include <Windows.h>
#include <iostream>

using namespace std;

typedef int(*Calculate)(int x, int y);

PVOID RvaToVa(PVOID rva, PVOID imageBase)
{
    return PVOID((int)rva + (int)imageBase);
} …
Run Code Online (Sandbox Code Playgroud)

c#

6
推荐指数
0
解决办法
1142
查看次数

如何接收SQL Server探查器事件?

我是这样尝试的:

using System;
using System.Windows.Forms;
using Microsoft.SqlServer.Management.Common;
using Microsoft.SqlServer.Management.Trace;

namespace SqlProfiller
{
    public partial class Form1 : Form
    {
        TraceServer reader = new TraceServer();
        SqlConnectionInfo connInfo = new SqlConnectionInfo();

        public Form1()
        {
            InitializeComponent();

        }

        private void button1_Click(object sender, EventArgs e)
        {
            connInfo.ServerName = @".\SQLR2";
            connInfo.DatabaseName = "DB";
            connInfo.UserName = "sa";
            connInfo.Password = "123";

            reader.InitializeAsReader(connInfo, @"Standard.tdf");


            while (reader.Read())
            {
                Console.WriteLine("SPID  : " + reader["SPID"]);
                Console.WriteLine("Login : " + reader["SessionLoginName"]);
                Console.WriteLine("Object: " + reader["ObjectName"]);
                Console.WriteLine("Text  : " + reader["TextData"]);
                Console.WriteLine();

                textBox1.Text += …
Run Code Online (Sandbox Code Playgroud)

c# sql-server events trace profiling

4
推荐指数
1
解决办法
2494
查看次数

从C#调用Delphi函数

我有一个下面的DLL源代码.

library Project1;

uses
  System.SysUtils,
  System.Classes;

type

  IStringFunctions = interface
    ['{240B567B-E619-48E4-8CDA-F6A722F44A71}']
    function GetMethodValueAsString():PAnsiChar; stdcall;
  end;

  TStringFunctions = class(TInterfacedObject, IStringFunctions)
  public
    function GetMethodValueAsString():PAnsiChar; stdcall;
  end;

{$R *.res}

function  TStringFunctions.GetMethodValueAsString():PAnsiChar; stdcall;
begin
  Result := 'test';
end;


procedure GetImplementation(out instance:IStringFunctions); stdcall; export;
begin
  instance := TStringFunctions.Create;
end;

exports GetImplementation;

begin
end.
Run Code Online (Sandbox Code Playgroud)

我想在C#中使用这样的

using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

namespace ConsoleApplication1
{
    [ComVisible(true)]
    [ComImport, InterfaceType(ComInterfaceType.InterfaceIsIUnknown), Guid("240B567B-E619-48E4-8CDA-F6A722F44A71")]
    public interface IStringFunctions
    {
        [MethodImplAttribute(MethodImplOptions.PreserveSig)]
        [return: MarshalAs(UnmanagedType.AnsiBStr)]
        string GetMethodValueAsString();
    }

    class Program
    {
        [DllImport("kernel32.dll", EntryPoint = "LoadLibrary", CallingConvention …
Run Code Online (Sandbox Code Playgroud)

c# delphi pinvoke marshalling delphi-xe2

3
推荐指数
1
解决办法
1260
查看次数