栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

Delphi XE2+ 调用NASM生成的obj

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Delphi XE2+ 调用NASM生成的obj

; Message Box, 64 bit. V1.02
MB_DEFBUTTON1 EQU 0                             ; Constants
MB_DEFBUTTON2 EQU 100h
IDNO          EQU 7
MB_YESNO      EQU 4

extern MessageBoxA                              ; import external symbols
extern ExitProcess                              ; Windows API functions, not decorated

global Start                                    ; Export symbols. The entry point

section .data                                   ; Initialized data segment
 MessageBoxText    db "Do you want to exit?", 0
 MessageBoxCaption db "MessageBox 64", 0

section .text                                   ; Code segment
Start:
 sub   RSP, 8                                   ; Align the stack to a multiple of 16 bytes

 sub   RSP, 32                                  ; 32 bytes of shadow space

.DisplayMessageBox:
 xor   ECX, ECX                                 ; 1st parameter
 lea   RDX, [REL MessageBoxText]                ; 2nd parameter
 lea   R8, [REL MessageBoxCaption]              ; 3rd parameter
 mov   R9D, MB_YESNO | MB_DEFBUTTON2            ; 4th parameter. 2 constants ORed together
 call  MessageBoxA

 cmp   RAX, IDNO                                ; Check the return value for "No"
 je    .DisplayMessageBox

 add   RSP, 32                                  ; Remove the 32 bytes

 xor   ECX, ECX
 call  ExitProcess

nasm -f win64 MessageBox64.asm -o MessageBox64.objgolink /entry:Start kernel32.dll user32.dll MessageBox64.obj

program Test_ASMOBJ;

{$APPTYPE CONSOLE}

{$R *.res}

uses
  System.SysUtils, Winapi.Windows;


{$link   MessageBox64.obj}
{$IFDEF CPUX64}
     procedure Start();external;

{$ENDIF}
type
Test = record
  a : byte;
  b : int16;
  c : byte;
  d : integer;
end;

Test2 = record
case Integer of
  0: (p : Pointer);
  1: (s : byte);
  2: (l: Integer);
end;

begin
  try
    Writeln(SizeOf(test));
    Writeln(SizeOf(test2));
    Start();
  except
    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);
  end;
end.

 从Delphi XE2开始,已能够支持C语言编译而成的coff格式文件。NASM有着更广泛的用户群,其编译的obj能够非常顺畅的被XE2以上调用。

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/703488.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号