HYPER MIKAN BOX
検索
最近の変更
メディアマネージャー
サイトマップ
文書の表示
以前のリビジョン
バックリンク
ログイン
トレース:
この文書は読取専用です。文書のソースを閲覧することは可能ですが、変更はできません。もし変更したい場合は管理者に連絡してください。
====== Toymath ====== 作成日: 2023-08-22 (火) [[https://youtu.be/q7L6ZtljFRU|第2回 DLLについて]] ===== プロジェクト Toymath ===== ==== toymath.h ==== <file cpp> #ifndef TOYMATH_H #define TOYMATH_H #ifdef TOYMATH_EXPORT # define DECLSPEC __declspec(dllexport) #else # define DECLSPEC __declspec(dllimport) #endif #define TMCALL __stdcall #ifdef __cplusplus extern "C" { #endif DECLSPEC int TMCALL add(int x, int y); #ifdef __cplusplus } #endif #endif </file> ==== toymath.cpp ==== <file cpp> #include "toymath.h" int TMCALL add(int x, int y) { return x + y; } </file> ==== test_toymath.cpp ==== <file cpp> #include "toymath.h" #include <cassert> int main() { int z = add(100, 200); assert(z == 300); } </file> ==== toymath-vc.def ==== <file> LIBRARY "toymath.dll" EXPORTS add = _add@8 </file> ==== toymath-mgw.def ==== <file> LIBRARY "toymath-mgw.dll" EXPORTS add = add@8 </file> ==== Makefile ==== <file makefile> .PHONY: all all: vc .PHONY: vc mgw vc: toymath-vc.dll mgw: toymath-mgw.dll toymath-vc.dll: toymath.cpp toymath.h toymath-vc.def cl /LD /EHsc /DTOYMATH_EXPORT $< /link /DEF:toymath-vc.def toymath-mgw.dll: toymath.cpp toymath.h g++ -shared -DTOYMATH_EXPORT -o $@ $< -Wl,--out-implib,libtoymath-mgw.dll.a,--add-stdcall-alias .PHONY: clean clean: ${RM} *.exe *.dll *.obj *.lib *.exp *.a </file> ===== VBAモジュール Toymath ===== <file vba> Declare Function Add Lib "toymath-mgw.dll" Alias "add" (ByVal X As Long, ByVal Y As Long) As Long Sub test_Add() ChDir "C:\Users\happycat\Documents\code\excel-dll\toymath" Z = Add(100, 200) Debug.Assert Z = 300 End Sub </file>
文書の先頭へ