1
0

VC++/MASMでx64 DLLを作る

Posted at

環境

Windows 11 Pro (x64)
Visual Studio Community 2022

Visual Studio 2022
x64 Native Tools Command Prompt for VS 2022

作成

C++

fig_c.cpp
/*
cl /LD /MD fig_c.cpp
*/
#define DLL_EXPORT extern "C" __declspec(dllexport)

DLL_EXPORT int hoge(int a, int b)
{
	return a * b;
}

MASM64

fig_a.asm
comment *
ml64 /c /Fl fig_a.asm
link /dll /entry:DllMain fig_a
*
.code
DllMain proc
	mov	eax, 1
	ret
DllMain endp

hoge proc export
	imul	ecx, edx
	mov	eax, ecx
	ret
hoge endp
end

確認

C++

fig1.cpp
/*
cl /MD fig1.cpp
*/
#pragma comment(lib, "fig_c")

#include <stdio.h>

extern "C" int hoge(int a, int b);

int main(void)
{
	int x = hoge(3, 4);
	printf("%d\n", x);
}

Python

fig2.py
# "C:\Program Files\LibreOffice\program\python" fig2.py
import ctypes

dll = ctypes.WinDLL(r"./fig_c")
print(dll.hoge(3, 4))
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0