浏览代码

添加Console

Wang Jeff 3 年之前
父节点
当前提交
d791c236a2

+ 3 - 0
Source/OGCAssist/OGCAssist.sln

@@ -5,10 +5,13 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "OGCAssist", "OGCAssist\OGCA
 EndProject
 EndProject
 Global
 Global
 	GlobalSection(SolutionConfigurationPlatforms) = preSolution
 	GlobalSection(SolutionConfigurationPlatforms) = preSolution
+		Console|Win32 = Console|Win32
 		Debug|Win32 = Debug|Win32
 		Debug|Win32 = Debug|Win32
 		Release|Win32 = Release|Win32
 		Release|Win32 = Release|Win32
 	EndGlobalSection
 	EndGlobalSection
 	GlobalSection(ProjectConfigurationPlatforms) = postSolution
 	GlobalSection(ProjectConfigurationPlatforms) = postSolution
+		{3A08430B-2381-49B3-8C6B-1D733C6357D5}.Console|Win32.ActiveCfg = Console|Win32
+		{3A08430B-2381-49B3-8C6B-1D733C6357D5}.Console|Win32.Build.0 = Console|Win32
 		{3A08430B-2381-49B3-8C6B-1D733C6357D5}.Debug|Win32.ActiveCfg = Debug|Win32
 		{3A08430B-2381-49B3-8C6B-1D733C6357D5}.Debug|Win32.ActiveCfg = Debug|Win32
 		{3A08430B-2381-49B3-8C6B-1D733C6357D5}.Debug|Win32.Build.0 = Debug|Win32
 		{3A08430B-2381-49B3-8C6B-1D733C6357D5}.Debug|Win32.Build.0 = Debug|Win32
 		{3A08430B-2381-49B3-8C6B-1D733C6357D5}.Release|Win32.ActiveCfg = Release|Win32
 		{3A08430B-2381-49B3-8C6B-1D733C6357D5}.Release|Win32.ActiveCfg = Release|Win32

+ 92 - 0
Source/OGCAssist/OGCAssist/OGCAssist.vcproj

@@ -161,6 +161,77 @@
 				Name="VCPostBuildEventTool"
 				Name="VCPostBuildEventTool"
 			/>
 			/>
 		</Configuration>
 		</Configuration>
+		<Configuration
+			Name="Console|Win32"
+			OutputDirectory="..\..\..\..\bin\$(SolutionName)"
+			IntermediateDirectory="$(OutDir)\$(ProjectName)\$(ConfigurationName)"
+			ConfigurationType="1"
+			CharacterSet="1"
+			>
+			<Tool
+				Name="VCPreBuildEventTool"
+			/>
+			<Tool
+				Name="VCCustomBuildTool"
+			/>
+			<Tool
+				Name="VCXMLDataGeneratorTool"
+			/>
+			<Tool
+				Name="VCWebServiceProxyGeneratorTool"
+			/>
+			<Tool
+				Name="VCMIDLTool"
+			/>
+			<Tool
+				Name="VCCLCompilerTool"
+				Optimization="0"
+				PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_CONSOLE;OGCASSIST_EXPORTS"
+				MinimalRebuild="true"
+				BasicRuntimeChecks="3"
+				RuntimeLibrary="3"
+				UsePrecompiledHeader="2"
+				WarningLevel="3"
+				DebugInformationFormat="4"
+			/>
+			<Tool
+				Name="VCManagedResourceCompilerTool"
+			/>
+			<Tool
+				Name="VCResourceCompilerTool"
+			/>
+			<Tool
+				Name="VCPreLinkEventTool"
+			/>
+			<Tool
+				Name="VCLinkerTool"
+				LinkIncremental="2"
+				GenerateDebugInformation="true"
+				SubSystem="1"
+				TargetMachine="1"
+			/>
+			<Tool
+				Name="VCALinkTool"
+			/>
+			<Tool
+				Name="VCManifestTool"
+			/>
+			<Tool
+				Name="VCXDCMakeTool"
+			/>
+			<Tool
+				Name="VCBscMakeTool"
+			/>
+			<Tool
+				Name="VCFxCopTool"
+			/>
+			<Tool
+				Name="VCAppVerifierTool"
+			/>
+			<Tool
+				Name="VCPostBuildEventTool"
+			/>
+		</Configuration>
 	</Configurations>
 	</Configurations>
 	<References>
 	<References>
 	</References>
 	</References>
@@ -191,6 +262,15 @@
 						CompileAsManaged="0"
 						CompileAsManaged="0"
 					/>
 					/>
 				</FileConfiguration>
 				</FileConfiguration>
+				<FileConfiguration
+					Name="Console|Win32"
+					>
+					<Tool
+						Name="VCCLCompilerTool"
+						UsePrecompiledHeader="0"
+						CompileAsManaged="0"
+					/>
+				</FileConfiguration>
 			</File>
 			</File>
 			<File
 			<File
 				RelativePath=".\stdafx.cpp"
 				RelativePath=".\stdafx.cpp"
@@ -211,6 +291,14 @@
 						UsePrecompiledHeader="1"
 						UsePrecompiledHeader="1"
 					/>
 					/>
 				</FileConfiguration>
 				</FileConfiguration>
+				<FileConfiguration
+					Name="Console|Win32"
+					>
+					<Tool
+						Name="VCCLCompilerTool"
+						UsePrecompiledHeader="1"
+					/>
+				</FileConfiguration>
 			</File>
 			</File>
 		</Filter>
 		</Filter>
 		<Filter
 		<Filter
@@ -252,6 +340,10 @@
 				RelativePath=".\PipeClient.h"
 				RelativePath=".\PipeClient.h"
 				>
 				>
 			</File>
 			</File>
+			<File
+				RelativePath=".\Protocol.h"
+				>
+			</File>
 			<File
 			<File
 				RelativePath=".\Utility.cpp"
 				RelativePath=".\Utility.cpp"
 				>
 				>

+ 33 - 13
Source/OGCAssist/OGCAssist/PipeClient.cpp

@@ -6,7 +6,7 @@
 
 
 CPipeClient::CPipeClient(LPCTSTR lpPipeName, DWORD dwMode)
 CPipeClient::CPipeClient(LPCTSTR lpPipeName, DWORD dwMode)
 {
 {
-    m_hPipeInst = INVALID_HANDLE_VALUE;
+    m_hReadInst = INVALID_HANDLE_VALUE;
     m_bClientStop = FALSE;
     m_bClientStop = FALSE;
     m_dwMode = dwMode;
     m_dwMode = dwMode;
     memset(m_szPipeName, 0, MAX_PATH*sizeof(TCHAR));
     memset(m_szPipeName, 0, MAX_PATH*sizeof(TCHAR));
@@ -19,8 +19,8 @@ CPipeClient::CPipeClient(LPCTSTR lpPipeName, DWORD dwMode)
 CPipeClient::~CPipeClient(void)
 CPipeClient::~CPipeClient(void)
 {
 {
     StopWork();
     StopWork();
-    if ( m_hPipeInst != INVALID_HANDLE_VALUE )
-        CloseHandle(m_hPipeInst);
+    if ( m_hReadInst != INVALID_HANDLE_VALUE )
+        CloseHandle(m_hReadInst);
 }
 }
 
 
 BOOL CPipeClient::StartWork()
 BOOL CPipeClient::StartWork()
@@ -54,10 +54,10 @@ DWORD CPipeClient::ConnectThread(LPVOID lpParam)
 
 
     while(!pInstance->m_bClientStop)
     while(!pInstance->m_bClientStop)
     {
     {
-        if ( pInstance->m_hPipeInst != INVALID_HANDLE_VALUE ) {
+        if ( pInstance->m_hReadInst != INVALID_HANDLE_VALUE ) {
             // 1分钟检测;
             // 1分钟检测;
             Sleep(60000);
             Sleep(60000);
-            Utility::dprintf(_T("m_hPipeInst 已存在\n"));
+            Utility::dprintf(_T("m_hReadInst 已存在\n"));
             continue;
             continue;
         }
         }
 
 
@@ -69,7 +69,7 @@ DWORD CPipeClient::ConnectThread(LPVOID lpParam)
             continue;
             continue;
         }
         }
 
 
-        pInstance->m_hPipeInst = CreateFile(
+        pInstance->m_hReadInst = CreateFile(
             pInstance->m_szPipeName,        // pipe name 
             pInstance->m_szPipeName,        // pipe name 
             GENERIC_READ | GENERIC_WRITE,   // read and write access 
             GENERIC_READ | GENERIC_WRITE,   // read and write access 
             0,                              // no sharing 
             0,                              // no sharing 
@@ -79,19 +79,29 @@ DWORD CPipeClient::ConnectThread(LPVOID lpParam)
             NULL);                          // no template file 
             NULL);                          // no template file 
 
 
         // 创建成功,退出;
         // 创建成功,退出;
-        if ( pInstance->m_hPipeInst != INVALID_HANDLE_VALUE ) 
+        if ( pInstance->m_hReadInst != INVALID_HANDLE_VALUE ) 
         {
         {
             // 管道连接成功,修改管道通信模式:message-read mode. 
             // 管道连接成功,修改管道通信模式:message-read mode. 
             BOOL fSuccess = SetNamedPipeHandleState( 
             BOOL fSuccess = SetNamedPipeHandleState( 
-                pInstance->m_hPipeInst,     // pipe handle 
+                pInstance->m_hReadInst,     // pipe handle 
                 &pInstance->m_dwMode,       // new pipe mode 
                 &pInstance->m_dwMode,       // new pipe mode 
                 NULL,                       // don't set maximum bytes 
                 NULL,                       // don't set maximum bytes 
                 NULL);                      // don't set maximum time 
                 NULL);                      // don't set maximum time 
 
 
             if (!fSuccess) {
             if (!fSuccess) {
                 Utility::dprintf(_T("SetNamedPipeHandleState failed. GLE=%d\n"), GetLastError() ); 
                 Utility::dprintf(_T("SetNamedPipeHandleState failed. GLE=%d\n"), GetLastError() ); 
-                CloseHandle(pInstance->m_hPipeInst);
+                CloseHandle(pInstance->m_hReadInst);
             }
             }
+
+			// 初始化写管道;
+			pInstance->m_hWriteInst = CreateFile(
+				pInstance->m_szPipeName,        // pipe name 
+				GENERIC_READ | GENERIC_WRITE,   // read and write access 
+				0,                              // no sharing 
+				NULL,                           // default security attributes
+				OPEN_EXISTING,                  // opens existing pipe 
+				0,                              // default attributes 
+				NULL);                          // no template file 
         }
         }
         else
         else
         {
         {
@@ -122,7 +132,7 @@ DWORD CPipeClient::ReadMsgThread(LPVOID lpParam)
 
 
     while(!pInstance->m_bClientStop)
     while(!pInstance->m_bClientStop)
     {
     {
-        if ( pInstance->m_hPipeInst == INVALID_HANDLE_VALUE ) {
+        if ( pInstance->m_hReadInst == INVALID_HANDLE_VALUE ) {
             Sleep(2000);
             Sleep(2000);
             continue;
             continue;
         }
         }
@@ -130,7 +140,7 @@ DWORD CPipeClient::ReadMsgThread(LPVOID lpParam)
         do 
         do 
         { 
         { 
             bSuccess = ReadFile( 
             bSuccess = ReadFile( 
-                pInstance->m_hPipeInst,     // pipe handle 
+                pInstance->m_hReadInst,     // pipe handle 
                 chBuf,                      // buffer to receive reply 
                 chBuf,                      // buffer to receive reply 
                 BUFSIZE*sizeof(TCHAR),      // size of buffer 
                 BUFSIZE*sizeof(TCHAR),      // size of buffer 
                 &cbRead,                    // number of bytes read 
                 &cbRead,                    // number of bytes read 
@@ -170,8 +180,8 @@ DWORD CPipeClient::ReadMsgThread(LPVOID lpParam)
             Utility::dprintf(_T("ReadFile from pipe failed. GLE=%d\n"), dwError );
             Utility::dprintf(_T("ReadFile from pipe failed. GLE=%d\n"), dwError );
             if ( dwError == ERROR_PIPE_NOT_CONNECTED || dwError == ERROR_BROKEN_PIPE)
             if ( dwError == ERROR_PIPE_NOT_CONNECTED || dwError == ERROR_BROKEN_PIPE)
             {
             {
-                CloseHandle(pInstance->m_hPipeInst);
-                pInstance->m_hPipeInst = INVALID_HANDLE_VALUE;
+                CloseHandle(pInstance->m_hReadInst);
+                pInstance->m_hReadInst = INVALID_HANDLE_VALUE;
             }
             }
 
 
 #ifdef _DEBUG
 #ifdef _DEBUG
@@ -185,4 +195,14 @@ DWORD CPipeClient::ReadMsgThread(LPVOID lpParam)
     Utility::dprintf(_T("<%ld> ReadMsgThread 退出\n"),Utility::g_WndInfo.dwProcessId);
     Utility::dprintf(_T("<%ld> ReadMsgThread 退出\n"),Utility::g_WndInfo.dwProcessId);
 
 
     return 0;
     return 0;
+}
+
+BOOL CPipeClient::SendMessage(PACKAGE &pak)
+{
+	// 是否连接了服务端;
+	if ( m_hReadInst == INVALID_HANDLE_VALUE ) 
+		return FALSE;
+
+	// 是否初始化了句柄;
+
 }
 }

+ 7 - 16
Source/OGCAssist/OGCAssist/PipeClient.h

@@ -1,19 +1,5 @@
 #pragma once
 #pragma once
-
-#pragma region Simple communication protocol
-
-typedef enum
-{
-    CP_REQ_1,
-    CP_REP_1,
-};
-
-typedef struct _SPCP_
-{
-
-}SimpleCP, *pSimpleCP;
-
-#pragma endregion 简单通信协议
+#include "Protocol.h"
 
 
 class CPipeClient
 class CPipeClient
 {
 {
@@ -23,7 +9,10 @@ public:
     ~CPipeClient(void);
     ~CPipeClient(void);
 
 
 private:
 private:
-    HANDLE m_hPipeInst;
+	// ReadFile管道句柄;
+    HANDLE m_hReadInst;
+	// WriteFIle管道句柄;
+	HANDLE m_hWriteInst;
     // 客户端状态;
     // 客户端状态;
     BOOL m_bClientStop;
     BOOL m_bClientStop;
     // 管道名称;
     // 管道名称;
@@ -40,4 +29,6 @@ public:
     static DWORD WINAPI ConnectThread(LPVOID lpParam);
     static DWORD WINAPI ConnectThread(LPVOID lpParam);
     // 读取管道消息线程;
     // 读取管道消息线程;
     static DWORD WINAPI ReadMsgThread(LPVOID lpParam);
     static DWORD WINAPI ReadMsgThread(LPVOID lpParam);
+	// 发送消息给服务端;
+	BOOL SendMessage(PACKAGE &pak);
 };
 };

+ 79 - 0
Source/OGCAssist/OGCAssist/Protocol.h

@@ -0,0 +1,79 @@
+#define NAME_LEN 128
+#define DATA_LEN 256
+
+#pragma region Simple communication protocol
+
+#pragma pack(push)
+#pragma pack(1)
+typedef enum
+{
+	//////////////////////////////////////////////////////////////////////////
+	// 服务端:发出劫持消息;		客户端返回:成功/失败
+	S2C_BEGIN_HIJACK,
+	// 服务端:发出恢复消息;		客户端返回:成功/失败;
+	S2C_END_HIJACK,
+	//\ 服务端:发出Connect消息;		客户端返回:成功/失败;
+	S2C_CONNECT,
+	//\ 服务端:发出Disconnect消息;		客户端返回:成功/失败;
+	S2C_DISCONNECT,
+	//\ 服务端:发出CheckFW消息;		客户端返回:成功/失败;
+	S2C_CHECKFW,
+	//\ 服务端:发出Go消息;				客户端返回:成功/失败;
+	S2C_GO,
+
+	//////////////////////////////////////////////////////////////////////////
+	// 客户端:发出Disconnect触发结果;
+	C2S_DISCONNECT,
+	// 客户端:发出Connect触发结果;成功/失败;
+	C2S_CONNECT,
+	// 客户端:发出CheckFW触发结果; 成功/失败;	(成功->服务端读取当前版本);
+	C2S_CHECKFW,
+	// 客户端:发出Go触发结果;成功/失败; 成功->耗时值、输出目录
+	C2S_GO,
+	// 客户端:产生异常时通知服务端结束程序;
+	C2S_EXCEPTION,
+};
+
+typedef struct _HEADER_
+{
+	// 协议标识符;
+	BYTE	byProtocol;
+	// 整个协议包长度;
+	DWORD	dwPackageLen;
+	// 消息类型;
+	BYTE	byMsgType;
+	_HEADER_()
+	{
+		byProtocol = 0xAC;
+		dwPackageLen = 0;
+		byMsgType = 0;
+	}
+}DATAHEADER, *LPDATAHEADER;
+
+// 请求包
+typedef struct _PACKAGE_ {
+	DATAHEADER	header;
+	BYTE		buf[4]; // 具体内容(指针地址);
+}PACKAGE, *LPPACKAGE;
+
+typedef struct _MSG_INFO_
+{
+	// 客户端ID;
+	DWORD	dwClientId;
+	// 客户端名称;
+	TCHAR	szClientName[NAME_LEN];
+	// 按钮执行结果;
+	BYTE	byResult;
+	// 按钮数据;
+	BYTE	byData[DATA_LEN];
+	_MSG_INFO_()
+	{
+		byResult = 0;
+		dwClientId = 0;
+		memset(byData, 0, DATA_LEN);
+		memset(szClientName, 0, sizeof(TCHAR)*NAME_LEN);
+	}
+}MSG_INFO,*LPMSG_INFO;
+
+#pragma pack(pop)
+#pragma endregion 简单通信协议

+ 17 - 0
Source/OGCAssist/OGCAssist/dllmain.cpp

@@ -34,6 +34,22 @@ DWORD WINAPI WorkThreadProc(LPVOID lParam)
 	return 0;
 	return 0;
 }
 }
 
 
+#ifdef _CONSOLE
+int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
+{
+	int nRetCode = 0;
+	Utility::dprintf(_T("×¢Èë\n"));
+	Utility::GetConfigContent();
+	if ( Utility::g_pPipeClient == NULL )
+	{
+		Utility::g_pPipeClient = new CPipeClient(Utility::g_cfgCtx.szPipeName);
+		Utility::g_pPipeClient->StartWork();
+	}
+	
+
+	system("pause");
+}
+#else
 BOOL APIENTRY DllMain( HMODULE hModule,DWORD  ul_reason_for_call,LPVOID lpReserved)
 BOOL APIENTRY DllMain( HMODULE hModule,DWORD  ul_reason_for_call,LPVOID lpReserved)
 {
 {
 	switch (ul_reason_for_call)
 	switch (ul_reason_for_call)
@@ -53,3 +69,4 @@ BOOL APIENTRY DllMain( HMODULE hModule,DWORD  ul_reason_for_call,LPVOID lpReserv
 	return TRUE;
 	return TRUE;
 }
 }
 
 
+#endif

+ 3 - 1
Source/OGCAssist/OGCAssist/stdafx.h

@@ -12,5 +12,7 @@
 #include <windows.h>
 #include <windows.h>
 #include <tchar.h>
 #include <tchar.h>
 #include <stdio.h> 
 #include <stdio.h> 
-
+#ifdef _CONSOLE
+#include <stdlib.h>
+#endif
 // TODO: 在此处引用程序需要的其他头文件
 // TODO: 在此处引用程序需要的其他头文件