はじめに
- [コマンドラインからマウスを操作する方法 (rundll32.exeで動くDLLの作成法)]
(https://language-and-engineering.hatenablog.jp/entry/20081117/1226943698)
を参考にさせて頂きました。圧倒的感謝……!
環境
- Windows 10 Home (64bit)
- Visual Studio Community 2019
手順
プロジェクトの作成
プロジェクト テンプレート:空のプロジェクト [C++]
プロジェクト名:rdtest
プロジェクトのプロパティ
全般
構成の種類:ダイナミック ライブラリ (.dll)
ソースの記述
rdtest.cpp
# include <Windows.h>
# include <stdio.h>
extern "C" __declspec(dllexport)
void CALLBACK test1(HWND hwnd, HINSTANCE hinst, LPSTR lpszCmdLine, int nCmdShow)
{
MessageBoxA(nullptr, lpszCmdLine, "rdtest", MB_OK);
}
extern "C" __declspec(dllexport)
void test2(HWND hwnd, HINSTANCE hinst, LPSTR lpszCmdLine, int nCmdShow)
{
printf("dlltest[%s]\n", lpszCmdLine);
}
エクスポート名の確認
[ツール]→[コマンド ライン]→[開発者コマンド プロンプト]
dumpbin /exports rdtest.dll
1 0 00001040 _test1@16 = _test1@16
2 1 00001060 test2 = _test2
動作確認
rundll32 rdtest.dll _test1@16 hello, world
rundll32 rdtest.dll test2 hello, world > a.txt
dlltest[hello, world ]
コンソールには出力されないがリダイレクトは可能。