[Ttssh2-commit] [8458] keycode警告対策

scmno****@osdn***** scmno****@osdn*****
2020年 1月 10日 (金) 22:12:13 JST


Revision: 8458
          https://osdn.net/projects/ttssh2/scm/svn/commits/8458
Author:   zmatsuo
Date:     2020-01-10 22:12:13 +0900 (Fri, 10 Jan 2020)
Log Message:
-----------
keycode警告対策

- GetProcAddress() の戻り値を一旦 FARPROC 変数に入れるようにした
- cmakeビルド + VS 時警告レベルを4に上げた

Modified Paths:
--------------
    trunk/teraterm/keycode/CMakeLists.txt
    trunk/teraterm/keycode/keycode.c

-------------- next part --------------
Modified: trunk/teraterm/keycode/CMakeLists.txt
===================================================================
--- trunk/teraterm/keycode/CMakeLists.txt	2020-01-10 13:12:00 UTC (rev 8457)
+++ trunk/teraterm/keycode/CMakeLists.txt	2020-01-10 13:12:13 UTC (rev 8458)
@@ -1,12 +1,9 @@
 project(keycode)
 
-if(USE_UNICODE_API)
-  add_definitions(-DUNICODE -D_UNICODE)
-endif()
-
 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/")
 
-set(SRC
+add_executable(
+  keycode WIN32
   keycode.c
   keycode.ico
   keycode-version.rc
@@ -14,19 +11,23 @@
   kc_res.h
   )
 
-include_directories(
+target_include_directories(
+  keycode
+  PRIVATE
   ../common
-  ../ttpfile
-  .
   )
 
-add_executable(
-  keycode WIN32
-  ${SRC}
-  )
+if(MSVC)
+  target_compile_options(
+    keycode
+    PRIVATE
+    /W4
+    )
+endif()
 
-target_link_libraries(
+target_compile_options(
   keycode
+  PRIVATE
   )
 
 install(

Modified: trunk/teraterm/keycode/keycode.c
===================================================================
--- trunk/teraterm/keycode/keycode.c	2020-01-10 13:12:00 UTC (rev 8457)
+++ trunk/teraterm/keycode/keycode.c	2020-01-10 13:12:13 UTC (rev 8458)
@@ -1,6 +1,6 @@
 /*
  * Copyright (C) 1994-1998 T. Teranishi
- * (C) 2006-2017 TeraTerm Project
+ * (C) 2006-2020 TeraTerm Project
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -48,7 +48,7 @@
 static BOOL Short;
 static WORD Scan;
 
-int PASCAL WinMain(HINSTANCE hInstance,
+int WINAPI WinMain(HINSTANCE hInstance,
                    HINSTANCE hPrevInstance,
                    LPSTR lpszCmdLine,
                    int nCmdShow)
@@ -63,17 +63,24 @@
 	pSetDllDir setDllDir;
 	pSetDefDllDir setDefDllDir;
 
+	(void)lpszCmdLine;
 	DoCover_IsDebuggerPresent();
 
 	if ((module = GetModuleHandleA("kernel32.dll")) != NULL) {
-		if ((setDefDllDir = (pSetDefDllDir)GetProcAddress(module, "SetDefaultDllDirectories")) != NULL) {
+		FARPROC func_ptr = GetProcAddress(module, "SetDefaultDllDirectories");
+		setDefDllDir = (pSetDefDllDir)func_ptr;
+		if (setDefDllDir != NULL) {
 			// SetDefaultDllDirectories() \x82\xAA\x8Eg\x82\xA6\x82\xE9\x8Fꍇ\x82́A\x8C\x9F\x8D\xF5\x83p\x83X\x82\xF0 %WINDOWS%\system32 \x82݂̂ɐݒ肷\x82\xE9
 			(*setDefDllDir)((DWORD)0x00000800); // LOAD_LIBRARY_SEARCH_SYSTEM32
 		}
-		else if ((setDllDir = (pSetDllDir)GetProcAddress(module, "SetDllDirectoryA")) != NULL) {
-			// SetDefaultDllDirectories() \x82\xAA\x8Eg\x82\xA6\x82Ȃ\xAD\x82Ă\xE0\x81ASetDllDirectory() \x82\xAA\x8Eg\x82\xA6\x82\xE9\x8Fꍇ\x82\xCD
-			// \x83J\x83\x8C\x83\x93\x83g\x83f\x83B\x83\x8C\x83N\x83g\x83\x8A\x82\xBE\x82\xAF\x82ł\xE0\x8C\x9F\x8D\xF5\x83p\x83X\x82\xA9\x82\xE7\x82͂\xB8\x82\xB5\x82Ă\xA8\x82\xAD\x81B
-			(*setDllDir)("");
+		else {
+			func_ptr = GetProcAddress(module, "SetDllDirectoryA");
+			setDllDir = (pSetDllDir)func_ptr;
+			if (setDllDir != NULL) {
+				// SetDefaultDllDirectories() \x82\xAA\x8Eg\x82\xA6\x82Ȃ\xAD\x82Ă\xE0\x81ASetDllDirectory() \x82\xAA\x8Eg\x82\xA6\x82\xE9\x8Fꍇ\x82\xCD
+				// \x83J\x83\x8C\x83\x93\x83g\x83f\x83B\x83\x8C\x83N\x83g\x83\x8A\x82\xBE\x82\xAF\x82ł\xE0\x8C\x9F\x8D\xF5\x83p\x83X\x82\xA9\x82\xE7\x82͂\xB8\x82\xB5\x82Ă\xA8\x82\xAD\x81B
+				(*setDllDir)("");
+			}
 		}
 	}
 
@@ -121,7 +128,7 @@
 		DispatchMessage(&msg);
 	}
 
-	return msg.wParam;
+	return (int)msg.wParam;
 }
 
 void KeyDownProc(HWND hWnd, WPARAM wParam, LPARAM lParam)
@@ -153,6 +160,8 @@
 
 void KeyUpProc(HWND hWnd, WPARAM wParam, LPARAM lParam)
 {
+	(void)wParam;
+	(void)lParam;
 	if (! KeyDown) {
 		return;
 	}
@@ -175,7 +184,7 @@
 
 	if (KeyDown) {
 		_snprintf_s(OutStr,sizeof(OutStr),_TRUNCATE,"Key code is %u.",Scan);
-		TextOutA(hDC,10,10,OutStr,strlen(OutStr));
+		TextOutA(hDC,10,10,OutStr, (int)strlen(OutStr));
 	}
 	else {
 		TextOutA(hDC,10,10,"Push any key.",13);


Ttssh2-commit メーリングリストの案内