差分
このページの2つのバージョン間の差分を表示します。
| 両方とも前のリビジョン前のリビジョン | |||
| youtube:vba-dll-002 [2024/02/28 18:26] – 削除 - 外部編集 (不明な日付) 127.0.0.1 | youtube:vba-dll-002 [2024/02/28 18:26] (現在) – ↷ toybox:vba-dll-002 から youtube:vba-dll-002 へページを移動しました。 freemikan | ||
|---|---|---|---|
| 行 1: | 行 1: | ||
| + | ====== Toymath ====== | ||
| + | |||
| + | 作成日: 2023-08-22 (火) | ||
| + | |||
| + | [[https:// | ||
| + | |||
| + | ===== プロジェクト Toymath ===== | ||
| + | |||
| + | ==== toymath.h ==== | ||
| + | |||
| + | <file cpp> | ||
| + | #ifndef TOYMATH_H | ||
| + | #define TOYMATH_H | ||
| + | |||
| + | #ifdef TOYMATH_EXPORT | ||
| + | # | ||
| + | #else | ||
| + | # | ||
| + | #endif | ||
| + | |||
| + | #define TMCALL __stdcall | ||
| + | |||
| + | #ifdef __cplusplus | ||
| + | extern " | ||
| + | #endif | ||
| + | |||
| + | DECLSPEC int TMCALL add(int x, int y); | ||
| + | |||
| + | #ifdef __cplusplus | ||
| + | } | ||
| + | #endif | ||
| + | |||
| + | #endif | ||
| + | </ | ||
| + | |||
| + | ==== toymath.cpp ==== | ||
| + | |||
| + | <file cpp> | ||
| + | #include " | ||
| + | |||
| + | int TMCALL add(int x, int y) { | ||
| + | return x + y; | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | ==== test_toymath.cpp ==== | ||
| + | |||
| + | <file cpp> | ||
| + | #include " | ||
| + | |||
| + | #include < | ||
| + | |||
| + | int main() { | ||
| + | int z = add(100, 200); | ||
| + | assert(z == 300); | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | ==== toymath-vc.def ==== | ||
| + | |||
| + | < | ||
| + | LIBRARY " | ||
| + | EXPORTS | ||
| + | add = _add@8 | ||
| + | </ | ||
| + | |||
| + | ==== toymath-mgw.def ==== | ||
| + | |||
| + | < | ||
| + | LIBRARY " | ||
| + | EXPORTS | ||
| + | add = add@8 | ||
| + | </ | ||
| + | |||
| + | ==== Makefile ==== | ||
| + | |||
| + | <file makefile> | ||
| + | .PHONY: all | ||
| + | all: vc | ||
| + | |||
| + | .PHONY: vc mgw | ||
| + | vc: toymath-vc.dll | ||
| + | mgw: toymath-mgw.dll | ||
| + | |||
| + | toymath-vc.dll: | ||
| + | cl /LD /EHsc / | ||
| + | | ||
| + | toymath-mgw.dll: | ||
| + | g++ -shared -DTOYMATH_EXPORT -o $@ $< -Wl, | ||
| + | |||
| + | .PHONY: clean | ||
| + | clean: | ||
| + | ${RM} *.exe *.dll *.obj *.lib *.exp *.a | ||
| + | </ | ||
| + | |||
| + | ===== VBAモジュール Toymath ===== | ||
| + | |||
| + | <file vba> | ||
| + | Declare Function Add Lib " | ||
| + | |||
| + | Sub test_Add() | ||
| + | ChDir " | ||
| + | Z = Add(100, 200) | ||
| + | Debug.Assert Z = 300 | ||
| + | End Sub | ||
| + | </ | ||
| + | |||
| + | |||
| + | |||
| + | |||
| + | |||
