制作DLL

xxx.asm:

%macro fb 0
push ebp
mov ebp,esp
%endmacro %macro fa 1
mov esp,ebp
pop ebp
ret %1
%endmacro section .text
global dllmain dllmain:
mov eax,1
ret 12 f1:
fb
mov eax,[ebp+8]
add eax,[ebp+12]
fa 8

xxx_link.fil:

; > golink @xxx_link.fil
/entry dllmain
/dll
/exports f1 xxx.obj
>nasm -f win32 xxx.asm
>golink @xxx_link.fil

制作dll后可以看下pe结构,免得的出问题

在x86汇编中调用

将xxx.dll拷贝到asm项目文件中

hello.asm:

extern MessageBoxA
extern ExitProcess
extern f1 section .data
title db "caption.",0
message db "hello world....",0 section .text
global main main:
push 1
push 2
call f1 push 0
push title
push message
push 0
call MessageBoxA _exit:
push 0
call ExitProcess
> nasm -f win32 hello.asm
> golink /entry main hello.obj kernel32.dll user32.dll xxx.dll

c++ 显示连接

将xxx.dll拷贝到c++项目文件中

#include <iostream>
#include <Windows.h> typedef int (CALLBACK* f1_t)(int, int); f1_t f1; int main()
{
HMODULE myDLL = LoadLibraryA("xxx.dll");
f1 = (f1_t)GetProcAddress(myDLL, "f1");
if (f1)
printf("%d\n", f1(1, 2)); // 3
else
printf("dll not export f1");
return 0;
}

See also:

nasm and golink create a DLL x86的更多相关文章

  1. create dll project based on the existing project

    Today, I have to create a dll project(called my.sln), the dllmain.cpp/.h/ is already in another proj ...

  2. [转]Replace all UUIDs in an ATL COM DLL.

    1. Introduction. 1.1 Recently, a friend asked me for advise on a very unusual requirement. 1.2 He ne ...

  3. Dll学习一_Dll 创建并动态引用窗体且释放窗体Demo

    1.新建Dll工程 2.Dll工程全部代码 library SubMain; { Important note about DLL memory management: ShareMem must b ...

  4. Delphi中编写无输出函数名的DLL文件(有点意思)(400多篇博客)

    用 Delphi 用长了,总是发现,有些和 MS 不同的地方.例如,MS 的公开库中,常常隐藏了许多重要函数,这些函数在系统中常常有起着非常巨大的作用.一旦知道如何调用,可以给自己的应用程序提供很强的 ...

  5. Cannot generate C# proxy dll with JNI4NET tool, running batch file as trusted assembly?

    From: https://stackoverflow.com/questions/41042368/cannot-generate-c-sharp-proxy-dll-with-jni4net-to ...

  6. Delphi调用DLL中的接口

    问题描述: 具体问题就是在隐式使用接口变量后,在FreeLibrary执行后,就会出现一个非法访址的错误. 这个错误的原因就是在FreeLibrary后,DLL以的代码均为不可用状态,而在代码执行完整 ...

  7. Delphi DLL制作和加载 Static, Dynamic, Delayed 以及 Shared-Memory Manager

    一 Dll的制作一般分为以下几步:1 在一个DLL工程里写一个过程或函数2 写一个Exports关键字,在其下写过程的名称.不用写参数和调用后缀.二 参数传递1 参数类型最好与window C++的参 ...

  8. DYNAMIC LINK LIBRARY - DLL

    https://www.tenouk.com/ModuleBB.html MODULE BB DYNAMIC LINK LIBRARY - DLL Part 1: STORY What do we h ...

  9. Walkthrough: Create and use your own Dynamic Link Library (C++)

    参考网站:https://docs.microsoft.com/en-us/cpp/build/walkthrough-creating-and-using-a-dynamic-link-librar ...

随机推荐

  1. setTimeout、Promise、Async/Await 的区别

    事件循环中分为宏任务队列和微任务队列其中setTimeout的回调函数放到宏任务队列里,等到执行栈清空以后执行promise.then里的回调函数会放到相应宏任务的微任务队列里,等宏任务里面的同步代码 ...

  2. VS Code 使用教程详解

    一.写在前面 1.为什么选择 \(VS\) \(code\) 一款非常好用的代码编辑器 标准化 \(Language\) \(Service\) \(Protocol\) 内置调试器和标准化 \(De ...

  3. (19)ln命令:在文件之间建立链接(硬链接和软链接)

    1.ext 文件系统(Linux 文件系统)是如何工作的. 我们在前面讲解了分区的格式化就是写入文件系统,而 Linux 目前使用的是 ext4 文件系统.如果用一张示意图来描述 ext4 文件系统 ...

  4. Java数组模拟队列 + 优化

    队列介绍 队列是一个有序列表,可以用数组或是链表来实现. 遵循先入先出的原则. 即:先存入队列的数据,要先取出.后存入的要后取出 示意图:(使用数组模拟队列示意图)  数组模拟队列 队列本身是有序列表 ...

  5. JavaHomeWorkList

    3.17 关键词:剪刀石头布:随机数 1 import java.util.Scanner; 2 public class JSB { 3 public static void main(String ...

  6. Luogu4168 蒲公英 (分块)

    题目传送门 题意 长度为n的序列,有m次询问,每次询问求\([l,r]\) 间的众数,如果有多个,输出最小的那个 \(n\le 4\times 10^4,m\le 5\times 10^5,a_i\l ...

  7. Educational Codeforces Round 30

    Educational Codeforces Round 30  A. Chores 把最大的换掉 view code #pragma GCC optimize("O3") #pr ...

  8. Grakn Forces 2020

    比赛链接:https://codeforces.com/contest/1408 A. Circle Coloring 题意 给出三个长为 $n$ 的序列 $a,b,c$,对于每个 $i$,$a_i ...

  9. 灯光照射,圆形探测类问题(解题报告)<分层差分><cmath取整>

    题目描述 一个n*n的网格图上有m个探测器,每个探测器有个探测半径r,问这n*n个点中有多少个点能被探测到. 输入输出格式 输入格式: (1<=r<n<=5000) (1<=m ...

  10. 【noi 2.2_1751】分解因数(递归)

    题意:问一个给定正整数的分解因数的方式数.N=a1*a2*...*ak(a1<=a2<=...<=ak). 解法:一步步分解该数,总方式数为一个个因数被分解的方案数之和. 可用大括号 ...