ååã¾ã§ã¯Turbo HAMLOGãã¼ã¿ãã¼ã¹ãä»å±ã®ã©ã¤ãã©ãªHAMLOG50.DLLãä»ãã¦Pythonããæä½ãã¦ãã¾ããã
HAMLOGã«ã¯ãã¼ã¿ãã¼ã¹ãç´æ¥ã¢ã¯ã»ã¹ããæ¹æ³ä»¥å¤ã«ããWindowsã®ã¦ã£ã³ãã¦ã¡ãã»ã¼ã¸ã使ã£ãã¢ããªã±ã¼ã·ã§ã³éã§ãã¼ã¿ãããåãããä»çµã¿ãæä¾ããã¦ãã¾ãã詳細ã¯æ¬¡ã®ãã¼ã¸ãã覧ãã ããã
ãHAMLOG50.DLLã®ä»æ§ï¼ä»ã®ã¢ããªããHAMLOGãæä½ããä»æ§ã https://hamlog.sakura.ne.jp/mou/thwapi.html
ä¸è¨ã®ãã¼ã¸ãããã¦ã³ãã¼ãããã¢ã¼ã«ã¤ãã®ä¸ã®ãã¡ã¤ã«ãHamlogMs.txtãããã®ä»æ§æ¸ã§ããããã«ããã¨ãHAMLOGã®äº¤ä¿¡ãã¼ã¿ãå ¥åããã¦ã£ã³ãã¦ã«äº¤ä¿¡ãã¼ã¿ãéã£ãããå ¥åã¦ã£ã³ãã¦ã«è¡¨ç¤ºããã¦ãã交信ãã¼ã¿ãåãåããããã§ãã
ããã§ã¯ãã¾ãã¯PythonããTurbo HAMLOGã®å ¥åã¦ã£ã³ãã¦ã«ãã¼ã¿ãéã£ã¦ã¿ã¾ãã
PythonããWindows APIãå¼ã³åºãã«ã¯ãããã¾ã§ä½¿ç¨ãã¦ããctypesãããå¯è½ã§ããããã£ã¨ä¾¿å©ãªæ¬¡ã®ã©ã¤ãã©ãªã使ããã¨ã«ãã¾ãã
ããã±ã¼ã¸ãã¤ã³ã¹ãã¼ã«ããåã«ãä»®æ³ç°å¢ãæºåãã¦ããã¾ãã
python -m venv .venv .venv\Scripts\activate
次ã«pywin32ãã¤ã³ã¹ãã¼ã«ãã¾ãã
pip install pywin32
ãã㧠win32guiãwin32conã¨ãã£ãã¢ã¸ã¥ã¼ã«ãå©ç¨ã§ããããã«ãªãã¾ããã
ä»æ§æ¸ã«ããã¨ãTurbo HAMLOGã¨ã®ãã¼ã¿ã®ããåãã«ã¯ã¦ã£ã³ãã¦ã¡ãã»ã¼ã¸ WM_COPYDATA ã使ãããã§ãã
WM_COPYDATA メッセージ (Winuser.h) - Win32 apps | Microsoft Learn
ãã¼ã¿ã¯ COPYDATASTRUCT æ§é ä½ã«å ¥ãã¾ãã
COPYDATASTRUCT (winuser.h) - Win32 apps | Microsoft Learn
COPYDATASTRUCTã®å®ç¾©ã¯æ¬¡ã®éãã§ãã
typedef struct tagCOPYDATASTRUCT { ULONG_PTR dwData; DWORD cbData; PVOID lpData; } COPYDATASTRUCT, *PCOPYDATASTRUCT;
ãããPythonå´ã§æ±ããããã«ctypesã§å®ç¾©ãã¾ãã
class COPYDATASTRUCT(ctypes.Structure): _fields_ = [ ("dwData", PULONG), ("cbData", DWORD), ("lpData", LPVOID) ]
ããã§ãã¼ã¿æ§é ã®æºåã¯ã§ãã¾ããããã¼ã¿ãéãã«ã¯Turbo HAMLOGã®ã¦ã£ã³ãã¦ãã³ãã«ãå¿
è¦ã§ãã次ã®ããã«ã¦ã£ã³ãã¦ã¯ã©ã¹ãæå®ãã¦ãèµ·åä¸ã®Turbo HAMLOGã®ã¦ã£ã³ãã¦ãã³ãã«ãæ¢ãã¾ãã
hwnd = win32gui.FindWindow("TThwin", None)
ä»åã¯Turbo HAMLOGã®å
¥åã¦ã£ã³ãã¦ã«ã³ã¼ã«ãµã¤ã³ãå
¥åãã¦ã¿ã¾ããä»æ§æ¸ã«ã¯dwDataã«è¨å®ããã³ãã³ãã¨ãã¦ã1ããæå®ããã¨ããã¾ãã
ï¼ COPYDATASTRUCT æ§é ä½ã¡ã³ãã¼ dwData ã«ã¤ã㦠âã³ãã³ããæ°å¤ã§æå®ããTurbo HAMLOG/Winã®å ¥åã¦ã¤ã³ãã¦ã«æååãéãã ã 1 = ã³ã¼ã«ãµã¤ã³ã«æååãéãã ã 2 = æ¥ä»ã«æååãéãã ããã ã»ã»1ï½14ã¾ã§ãTurbo HAMLOG/Winã®å ¥åæ¬ã®ä¸¦ã³ã®ã¨ããã»ã» ã12 = QTHã«æååãéãã ã13 = Remarksï¼ã«æååãéãã ã14 = Remarksï¼ã«æååãéãã
dwDataã«è¨å®ããã³ãã³ãã«ã¯ã次ã®ããã«ãã¼ãã¼ãããENTERãã¼ãæ¼ããã¨ãã¨åãæ¯ãèããããããã¨ãã§ãã¾ãã
(Delphi) const THW_ENTER = $10000; // ãã¼ã¿éä¿¡å¾ãENTERãã¼ãæ¼ããã®ã¨åã THW_FOCUS = $20000; // ãã¼ã¿éä¿¡å¾ãç·¨éããã¯ã¹ã«ãã©ã¼ã«ã¹
ãããPythonã§å®è£
ããã¨æ¬¡ã®ããã«ãªãã¾ãã
THW_ENTER = 0x10000 THW_FOCUS = 0x20000 call = create_string_buffer("JI1JDI".encode()) cmd = 1 | THW_FOCUS | THW_ENTER cds = COPYDATASTRUCT() cds.dwData = cast(cmd, PULONG) cds.cbData = sizeof(call) cds.lpData = cast(call, LPVOID) win32gui.SendMessage(hwnd, win32con.WM_COPYDATA, None, cds)
ã½ã¼ã¹ã³ã¼ãã¯å
¨ä½ã§æ¬¡ã®ããã«ãªãã¾ãããã¨ã©ã¼å¦çã¯çç¥ãã¦ãã¾ãã
import win32gui import win32con from ctypes import * from ctypes.wintypes import * class COPYDATASTRUCT(ctypes.Structure): _fields_ = [ ("dwData", PULONG), ("cbData", DWORD), ("lpData", LPVOID) ] hwnd = win32gui.FindWindow("TThwin", None) THW_ENTER = 0x10000 THW_FOCUS = 0x20000 call = create_string_buffer("JI1JDI".encode()) cmd = 1 | THW_FOCUS | THW_ENTER cds = COPYDATASTRUCT() cds.dwData = cast(cmd, PULONG) cds.cbData = sizeof(call) cds.lpData = cast(call, LPVOID) win32gui.SendMessage(hwnd, win32con.WM_COPYDATA, None, cds)
å®è¡ããã¨ã次ã®ããã«è¡¨ç¤ºããã¾ããï¼ååã¯ãã¹ã¯ãã¦ãã¾ãï¼ãã¦ã¼ã¶ã¼ç»é²ãã¦ããã³ã¼ã«ãµã¤ã³ã¯ååã¨QTHã表示ããã¾ããã
ããã¾ã§ã§PythonããTurbo HAMLOGã®å ¥åã¦ã£ã³ãã¦ã«ãã¼ã¿ãéããã¨ãã§ãã¾ããã次åã¯å ¥åã¦ã£ã³ãã¦ã®ãã¼ã¿ãåå¾ããã¨ããã¾ã§è©¦ãã¦ã¿ããã¨æãã¾ãã
JI1JDI
ããã楽ããã¢ããã¥ã¢ç¡ç·ã¨ããã°ã©ãã³ã°ã楽ããã§ãã¾ãã scrapbox.io