[Ttssh2-commit] [5161] Windows 2000 以前で ttpmacro . exe を実行するとエラーになるのを修正

Back to archive index

svnno****@sourc***** svnno****@sourc*****
2013年 3月 23日 (土) 06:03:32 JST


Revision: 5161
          http://sourceforge.jp/projects/ttssh2/scm/svn/commits/5161
Author:   maya
Date:     2013-03-23 06:03:32 +0900 (Sat, 23 Mar 2013)
Log Message:
-----------
Windows 2000 以前で ttpmacro.exe を実行するとエラーになるのを修正
  GetAdaptersAddresses を見つけられないエラーになるので iphlpapi.dll を LoadLibrary する

Modified Paths:
--------------
    trunk/teraterm/ttpmacro/ttl.c
    trunk/teraterm/ttpmacro/ttpmacro.vcproj

-------------- next part --------------
Modified: trunk/teraterm/ttpmacro/ttl.c
===================================================================
--- trunk/teraterm/ttpmacro/ttl.c	2013-03-22 17:28:54 UTC (rev 5160)
+++ trunk/teraterm/ttpmacro/ttl.c	2013-03-22 21:03:32 UTC (rev 5161)
@@ -43,7 +43,6 @@
 #include <winsock2.h>
 #include <ws2tcpip.h>
 #include <iptypes.h>
-#include <iphlpapi.h>
 
 #define TTERMCOMMAND "TTERMPRO /D="
 #define CYGTERMCOMMAND "cyglaunch -o /D="
@@ -2247,6 +2246,12 @@
 }
 
 
+typedef DWORD (__stdcall *pGetAdaptersAddresses)(ULONG Family,
+                                                 DWORD Flags,
+                                                 PVOID Reserved,
+                                                 PIP_ADAPTER_ADDRESSES pAdapterAddresses,
+                                                 PULONG pOutBufLen);
+
 WORD TTLGetIPv6Addr()
 {
 	WORD Err;
@@ -2256,6 +2261,8 @@
     IP_ADAPTER_ADDRESSES addr[256];/* XXX */
     ULONG len = sizeof(addr);
 	char ipv6str[64];
+	HMODULE h;
+	pGetAdaptersAddresses pfunc;
 
 	Err = 0;
 	GetStrVar(&VarId,&Err);
@@ -2264,8 +2271,18 @@
 	if (Err!=0) return Err;
 
 	// \x8E\xA9\x95\xAA\x8E\xA9\x90g\x82̑SIPv6\x83A\x83h\x83\x8C\x83X\x82\xF0\x8E擾\x82\xB7\x82\xE9\x81B
+	if ((h = LoadLibrary("iphlpapi.dll")) == NULL) {
+		int err = GetLastError();
+		SetResult(-1);
+		return Err;
+	}
+	if ((pfunc = (pGetAdaptersAddresses)GetProcAddress(h, "GetAdaptersAddresses")) == NULL) {
+		FreeLibrary(h);
+		SetResult(-1);
+		return Err;
+	}
 	num = 0;
-	ret = GetAdaptersAddresses(AF_INET6, 0, NULL, addr, &len);
+	ret = pfunc(AF_INET6, 0, NULL, addr, &len);
 	if (ret == ERROR_SUCCESS) {
 		IP_ADAPTER_ADDRESSES *padap = &addr[0];
 
@@ -2297,6 +2314,7 @@
 
 	SetResult(num);
 
+	FreeLibrary(h);
 	return Err;
 }
 

Modified: trunk/teraterm/ttpmacro/ttpmacro.vcproj
===================================================================
--- trunk/teraterm/ttpmacro/ttpmacro.vcproj	2013-03-22 17:28:54 UTC (rev 5160)
+++ trunk/teraterm/ttpmacro/ttpmacro.vcproj	2013-03-22 21:03:32 UTC (rev 5161)
@@ -79,7 +79,7 @@
 			/>
 			<Tool
 				Name="VCLinkerTool"
-				AdditionalDependencies="onig_s.lib Version.lib iphlpapi.lib"
+				AdditionalDependencies="onig_s.lib Version.lib"
 				OutputFile="..\Release/ttpmacro.exe"
 				LinkIncremental="1"
 				SuppressStartupBanner="true"
@@ -176,7 +176,7 @@
 			/>
 			<Tool
 				Name="VCLinkerTool"
-				AdditionalDependencies="onig_sd.lib Version.lib iphlpapi.lib"
+				AdditionalDependencies="onig_sd.lib Version.lib"
 				OutputFile="..\Debug/ttpmacro.exe"
 				LinkIncremental="1"
 				SuppressStartupBanner="true"



Ttssh2-commit メーリングリストの案内
Back to archive index