添加项目文件。

This commit is contained in:
CaiXiang
2025-06-09 09:09:25 +08:00
parent 75b909652e
commit 88acb23465
1054 changed files with 615623 additions and 0 deletions

View File

@@ -0,0 +1,240 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{4DA0C82B-2496-4A33-BDCE-E89D85A60BF8}</ProjectGuid>
<RootNamespace>VcsClient</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
<Keyword>MFCProj</Keyword>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet>
<UseOfMfc>Dynamic</UseOfMfc>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
<UseOfMfc>Dynamic</UseOfMfc>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet>
<UseOfMfc>Dynamic</UseOfMfc>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
<UseOfMfc>Dynamic</UseOfMfc>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_WINDOWS;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>false</SDLCheck>
<AdditionalIncludeDirectories>E:\work\tank_svn\shiyu\project\fan\warehouse\code\cpp\vcs-client\Inc\json\inc;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
</Link>
<Midl>
<MkTypLibCompatible>false</MkTypLibCompatible>
<ValidateAllParameters>true</ValidateAllParameters>
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</Midl>
<ResourceCompile>
<Culture>0x0804</Culture>
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>$(IntDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ResourceCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>_WINDOWS;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>false</SDLCheck>
<AdditionalIncludeDirectories>$(SolutionDir)3rdparty\json\inc;$(SolutionDir)3rdparty\curl\inc;$(SolutionDir)CCEXPipe\;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<AdditionalLibraryDirectories>$(SolutionDir)3rdparty\curl\lib\x64;$(SolutionDir)$(Platform)\$(Configuration)\;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
</Link>
<Midl>
<MkTypLibCompatible>false</MkTypLibCompatible>
<ValidateAllParameters>true</ValidateAllParameters>
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</Midl>
<ResourceCompile>
<Culture>0x0804</Culture>
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>$(IntDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ResourceCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>Use</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;_WINDOWS;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
<Midl>
<MkTypLibCompatible>false</MkTypLibCompatible>
<ValidateAllParameters>true</ValidateAllParameters>
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</Midl>
<ResourceCompile>
<Culture>0x0804</Culture>
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>$(IntDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ResourceCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>_WINDOWS;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>false</SDLCheck>
<AdditionalIncludeDirectories>$(SolutionDir)3rdparty\json\inc;$(SolutionDir)3rdparty\curl\inc;$(SolutionDir)CCEXPipe\;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<AdditionalLibraryDirectories>$(SolutionDir)3rdparty\curl\lib\x64;$(SolutionDir)$(Platform)\$(Configuration)\</AdditionalLibraryDirectories>
<AdditionalDependencies>libcurl.lib</AdditionalDependencies>
<UACExecutionLevel>AsInvoker</UACExecutionLevel>
</Link>
<Midl>
<MkTypLibCompatible>false</MkTypLibCompatible>
<ValidateAllParameters>true</ValidateAllParameters>
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</Midl>
<ResourceCompile>
<Culture>0x0804</Culture>
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>$(IntDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ResourceCompile>
</ItemDefinitionGroup>
<ItemGroup>
<Text Include="ReadMe.txt" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="HttpClient.h" />
<ClInclude Include="HttpService.h" />
<ClInclude Include="Inc\CCEXPipeLib.h" />
<ClInclude Include="ModuleListCtrl.h" />
<ClInclude Include="ModuleProcess.h" />
<ClInclude Include="Resource.h" />
<ClInclude Include="stdafx.h" />
<ClInclude Include="targetver.h" />
<ClInclude Include="AgvMainDialog.h" />
<ClInclude Include="Agv.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\3rdparty\json\src\json_reader.cpp" />
<ClCompile Include="..\3rdparty\json\src\json_value.cpp" />
<ClCompile Include="..\3rdparty\json\src\json_writer.cpp" />
<ClCompile Include="HttpClient.cpp" />
<ClCompile Include="HttpService.cpp" />
<ClCompile Include="ModuleListCtrl.cpp" />
<ClCompile Include="ModuleProcess.cpp" />
<ClCompile Include="stdafx.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader>
</ClCompile>
<ClCompile Include="AgvMainDialog.cpp" />
<ClCompile Include="Agv.cpp" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="Agv.rc" />
</ItemGroup>
<ItemGroup>
<None Include="res\Agv.rc2" />
</ItemGroup>
<ItemGroup>
<Image Include="res\Agv.ico" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
<ProjectExtensions>
<VisualStudio>
<UserProperties RESOURCE_FILE="Agv.rc" />
</VisualStudio>
</ProjectExtensions>
</Project>

View File

@@ -0,0 +1,50 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<ClCompile Include="HttpClient.cpp" />
<ClCompile Include="ModuleListCtrl.cpp" />
<ClCompile Include="ModuleProcess.cpp" />
<ClCompile Include="stdafx.cpp" />
<ClCompile Include="..\3rdparty\json\src\json_reader.cpp">
<Filter>json</Filter>
</ClCompile>
<ClCompile Include="..\3rdparty\json\src\json_value.cpp">
<Filter>json</Filter>
</ClCompile>
<ClCompile Include="..\3rdparty\json\src\json_writer.cpp">
<Filter>json</Filter>
</ClCompile>
<ClCompile Include="HttpService.cpp" />
<ClCompile Include="AgvMainDialog.cpp" />
<ClCompile Include="Agv.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="HttpClient.h" />
<ClInclude Include="HttpService.h" />
<ClInclude Include="Inc\CCEXPipeLib.h" />
<ClInclude Include="ModuleListCtrl.h" />
<ClInclude Include="ModuleProcess.h" />
<ClInclude Include="Resource.h" />
<ClInclude Include="stdafx.h" />
<ClInclude Include="targetver.h" />
<ClInclude Include="AgvMainDialog.h" />
<ClInclude Include="Agv.h" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="Agv.rc" />
</ItemGroup>
<ItemGroup>
<Image Include="res\Agv.ico" />
</ItemGroup>
<ItemGroup>
<None Include="res\Agv.rc2" />
</ItemGroup>
<ItemGroup>
<Text Include="ReadMe.txt" />
</ItemGroup>
<ItemGroup>
<Filter Include="json">
<UniqueIdentifier>{79a32759-a4db-47d6-9e89-5ec8dd9bd03d}</UniqueIdentifier>
</Filter>
</ItemGroup>
</Project>

128
Platform/Agv.cpp Normal file
View File

@@ -0,0 +1,128 @@
// Vcs-Client.cpp : <20><><EFBFBD><EFBFBD>Ӧ<EFBFBD>ó<EFBFBD><C3B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>
//
#include "stdafx.h"
#include "Agv.h"
#include "AgvMainDialog.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// CVcsClientApp
BEGIN_MESSAGE_MAP(CAgvApp, CWinApp)
ON_COMMAND(ID_HELP, &CWinApp::OnHelp)
END_MESSAGE_MAP()
// CVcsClientApp <20><><EFBFBD><EFBFBD>
CAgvApp::CAgvApp()
{
// ֧<><D6A7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
m_dwRestartManagerSupportFlags = AFX_RESTART_MANAGER_SUPPORT_RESTART;
// TODO: <20>ڴ˴<DAB4><CBB4><EFBFBD><EFBFBD>ӹ<EFBFBD><D3B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD>ij<EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> InitInstance <20><>
char acPath[2048] = { 0 };
GetModuleFileName(NULL, acPath, 2048);
CString strConf(acPath);
m_strBaseDir = strConf.Left(strConf.ReverseFind('\\')+1);
m_strConfigFile = m_strBaseDir + "config.ini";
m_strPipeFile = m_strBaseDir + "pipe.ini";
}
// Ψһ<CEA8><D2BB>һ<EFBFBD><D2BB> CVcsClientApp <20><><EFBFBD><EFBFBD>
CAgvApp theApp;
// CVcsClientApp <20><>ʼ<EFBFBD><CABC>
HANDLE hmutex;
BOOL CAgvApp::InitInstance()
{
hmutex = CreateMutexA(nullptr, FALSE, "kingcharm-wcs-server");
int err = GetLastError();
if (err == ERROR_ALREADY_EXISTS) {
CloseHandle(hmutex);
hmutex = nullptr;
//AfxMessageBox("<22><><EFBFBD><EFBFBD>ʵ<EFBFBD><CAB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.");
return FALSE;
}
// <20><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> Windows XP <20>ϵ<EFBFBD>Ӧ<EFBFBD>ó<EFBFBD><C3B3><EFBFBD><EFBFBD>嵥ָ<E5B5A5><D6B8>Ҫ
// ʹ<><CAB9> ComCtl32.dll <20>汾 6 <20><><EFBFBD><EFBFBD><EFBFBD>߰汾<DFB0><E6B1BE><EFBFBD><EFBFBD><EFBFBD>ÿ<EFBFBD><C3BF>ӻ<EFBFBD><D3BB><EFBFBD>ʽ<EFBFBD><CABD>
//<2F><><EFBFBD><EFBFBD>Ҫ InitCommonControlsEx()<29><> <20><><EFBFBD>򣬽<EFBFBD><F2A3ACBD>޷<EFBFBD><DEB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڡ<EFBFBD>
INITCOMMONCONTROLSEX InitCtrls;
InitCtrls.dwSize = sizeof(InitCtrls);
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA>Ӧ<EFBFBD>ó<EFBFBD><C3B3><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD>õ<EFBFBD>
// <20><><EFBFBD><EFBFBD><EFBFBD>ؼ<EFBFBD><D8BC>
InitCtrls.dwICC = ICC_WIN95_CLASSES;
InitCommonControlsEx(&InitCtrls);
CWinApp::InitInstance();
AfxEnableControlContainer();
// <20><><EFBFBD><EFBFBD> shell <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Է<EFBFBD><D4B7>Ի<EFBFBD><D4BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// <20>κ<EFBFBD> shell <20><><EFBFBD><EFBFBD>ͼ<EFBFBD>ؼ<EFBFBD><D8BC><EFBFBD> shell <20>б<EFBFBD><D0B1><EFBFBD>ͼ<EFBFBD>ؼ<EFBFBD><D8BC><EFBFBD>
CShellManager *pShellManager = new CShellManager;
// <20><><EFBFBD>Windows Native<76><65><EFBFBD>Ӿ<EFBFBD><D3BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ա<EFBFBD><D4B1><EFBFBD> MFC <20>ؼ<EFBFBD><D8BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerWindows));
// <20><>׼<EFBFBD><D7BC>ʼ<EFBFBD><CABC>
// <20><><EFBFBD><EFBFBD>δʹ<CEB4><CAB9><EFBFBD><EFBFBD>Щ<EFBFBD><D0A9><EFBFBD>ܲ<EFBFBD>ϣ<EFBFBD><CFA3><EFBFBD><EFBFBD>С
// <20><><EFBFBD>տ<EFBFBD>ִ<EFBFBD><D6B4><EFBFBD>ļ<EFBFBD><C4BC>Ĵ<EFBFBD>С<EFBFBD><D0A1><EFBFBD><EFBFBD>Ӧ<EFBFBD>Ƴ<EFBFBD><C6B3><EFBFBD><EFBFBD><EFBFBD>
// <20><><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD>ض<EFBFBD><D8B6><EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ洢<DAB4><E6B4A2><EFBFBD>õ<EFBFBD>ע<EFBFBD><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// TODO: Ӧ<>ʵ<EFBFBD><CAB5>޸ĸ<DEB8><C4B8>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD>
// <20><><EFBFBD><EFBFBD><EFBFBD>޸<EFBFBD>Ϊ<EFBFBD><CEAA>˾<EFBFBD><CBBE><EFBFBD><EFBFBD>֯<EFBFBD><D6AF>
SetRegistryKey(_T("Ӧ<EFBFBD>ó<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɵı<EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD>ó<EFBFBD><EFBFBD><EFBFBD>"));
CAgvMainDialog dlg;
m_pMainWnd = &dlg;
INT_PTR nResponse = dlg.DoModal();
if (nResponse == IDOK)
{
// TODO: <20>ڴ˷<DAB4><CBB7>ô<EFBFBD><C3B4><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
// <20><>ȷ<EFBFBD><C8B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>رնԻ<D5B6><D4BB><EFBFBD><EFBFBD>Ĵ<EFBFBD><C4B4><EFBFBD>
}
else if (nResponse == IDCANCEL)
{
// TODO: <20>ڴ˷<DAB4><CBB7>ô<EFBFBD><C3B4><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
// <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>رնԻ<D5B6><D4BB><EFBFBD><EFBFBD>Ĵ<EFBFBD><C4B4><EFBFBD>
}
else if (nResponse == -1)
{
TRACE(traceAppMsg, 0, "<EFBFBD><EFBFBD><EFBFBD><EFBFBD>: <20>Ի<EFBFBD><D4BB>򴴽<EFBFBD>ʧ<EFBFBD>ܣ<EFBFBD>Ӧ<EFBFBD>ó<EFBFBD><C3B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֹ<EFBFBD><D6B9>\n");
TRACE(traceAppMsg, 0, "<EFBFBD><EFBFBD><EFBFBD><EFBFBD>: <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڶԻ<DAB6><D4BB><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9> MFC <20>ؼ<EFBFBD><D8BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>޷<EFBFBD> #define _AFX_NO_MFC_CONTROLS_IN_DIALOGS<47><53>\n");
}
// ɾ<><C9BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E6B4B4><EFBFBD><EFBFBD> shell <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if (pShellManager != NULL)
{
delete pShellManager;
}
#ifndef _AFXDLL
ControlBarCleanUp();
#endif
// <20><><EFBFBD>ڶԻ<DAB6><D4BB><EFBFBD><EFBFBD>ѹرգ<D8B1><D5A3><EFBFBD><EFBFBD>Խ<EFBFBD><D4BD><EFBFBD><EFBFBD><EFBFBD> FALSE <20>Ա<EFBFBD><D4B1>˳<EFBFBD>Ӧ<EFBFBD>ó<EFBFBD><C3B3><EFBFBD><EFBFBD><EFBFBD>
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD>ó<EFBFBD><C3B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD>á<EFBFBD>
return FALSE;
}

37
Platform/Agv.h Normal file
View File

@@ -0,0 +1,37 @@
// Vcs-Client.h : PROJECT_NAME Ӧ<>ó<EFBFBD><C3B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ<EFBFBD>ļ<EFBFBD>
//
#pragma once
#ifndef __AFXWIN_H__
#error "<22>ڰ<EFBFBD><DAB0><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>֮ǰ<D6AE><C7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD>stdafx.h<><68><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> PCH <20>ļ<EFBFBD>"
#endif
#include "resource.h" // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// CVcsClientApp:
// <20>йش<D0B9><D8B4><EFBFBD><EFBFBD><EFBFBD>ʵ<EFBFBD>֣<EFBFBD><D6A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> Vcs-Client.cpp
//
class CAgvApp : public CWinApp
{
public:
CAgvApp();
CString m_strBaseDir;
CString m_strConfigFile;
CString m_strPipeFile;
// <20><>д
public:
virtual BOOL InitInstance();
// ʵ<><CAB5>
DECLARE_MESSAGE_MAP()
};
extern CAgvApp theApp;
extern CString g_strProjectConfigFile;

BIN
Platform/Agv.rc Normal file

Binary file not shown.

472
Platform/AgvMainDialog.cpp Normal file
View File

@@ -0,0 +1,472 @@
// WcsMainDialog.cpp : ʵ<><CAB5><EFBFBD>ļ<EFBFBD>
//
#include "stdafx.h"
#include "Agv.h"
#include "AgvMainDialog.h"
#include "ModuleProcess.h"
#include "afxdialogex.h"
#include "tlhelp32.h"//<2F><><EFBFBD><EFBFBD>ͷ<EFBFBD>ļ<EFBFBD>
#define TRAY_ICON_ID 666
// CAgvMainDialog <20>Ի<EFBFBD><D4BB><EFBFBD>
IMPLEMENT_DYNAMIC(CAgvMainDialog, CDialogEx)
CAgvMainDialog::CAgvMainDialog(CWnd* pParent /*=NULL*/)
: CDialogEx(IDD_WCS_MAIN_DIALOG, pParent)
{
//m_nSubDlg = 3;
}
CAgvMainDialog::~CAgvMainDialog()
{
}
void CAgvMainDialog::DoDataExchange(CDataExchange* pDX)
{
CDialogEx::DoDataExchange(pDX);
DDX_Control(pDX, IDC_LIST_MODULE, m_ModuleListCtrl);
DDX_Control(pDX, IDC_EDIT_LOG, m_EditMultiLine);
}
BEGIN_MESSAGE_MAP(CAgvMainDialog, CDialogEx)
ON_MESSAGE(WM_SYSTEMTRAY, &CAgvMainDialog::OnSystemtray)
ON_COMMAND(ID_TRAY_SHOW, &CAgvMainDialog::OnTrayShow)
ON_COMMAND(ID_TRAY_EXIT, &CAgvMainDialog::OnTrayExit)
ON_WM_CLOSE()
ON_NOTIFY(NM_RCLICK, IDC_LIST_MODULE, &CAgvMainDialog::OnNMRClickListModule)
ON_MESSAGE(WM_UPDATE_MODULE_STATUS, &CAgvMainDialog::OnUpdateModule)
ON_NOTIFY(NM_DBLCLK, IDC_LIST_MODULE, &CAgvMainDialog::OnNMDblclkListModule)
END_MESSAGE_MAP()
// CAgvMainDialog <20><>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
void CAgvMainDialog::OnTrayShow()
{
AfxGetApp()->m_pMainWnd->ShowWindow(SW_SHOWNORMAL);
SetForegroundWindow();
}
void CAgvMainDialog::OnTrayExit()
{
NOTIFYICONDATA nid;
nid.cbSize = sizeof(NOTIFYICONDATA);
nid.hWnd = m_hWnd; // <20><><EFBFBD>ھ<EFBFBD><DABE><EFBFBD>
nid.uID = TRAY_ICON_ID; // <20><><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD>Ψһ<CEA8><D2BB>ʶ<EFBFBD><CAB6>
Shell_NotifyIcon(NIM_DELETE, &nid);
OnOK();
}
void CAgvMainDialog::AddLog2Edit(CString strMsg)
{
CString str;
m_EditMultiLine.GetWindowText(str);
if (str.GetLength() > 2048)
{
str = ""; //<2F>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>־
}
str += strMsg;
str += "\r\n";
m_EditMultiLine.SetWindowText(str);
m_EditMultiLine.LineScroll(m_EditMultiLine.GetLineCount());
}
BOOL CAgvMainDialog::OnInitDialog()
{
CDialogEx::OnInitDialog();
//ModifyStyleEx(WS_EX_APPWINDOW, WS_EX_TOOLWINDOW, 1);//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
m_ModuleListCtrl.SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES | LVS_EX_FULLROWSELECT);
//<2F><><EFBFBD><EFBFBD>ϵͳ<CFB5><CDB3><EFBFBD><EFBFBD>
NotifyIcon.cbSize = sizeof(NOTIFYICONDATA);
NotifyIcon.hIcon=AfxGetApp()->LoadIcon(IDR_MAINFRAME);
//NotifyIcon.hIcon = m_hIcon; //<2F><><EFBFBD><EFBFBD><EFBFBD>Ǿ<EFBFBD>Ҳ<EFBFBD><D2B2><EFBFBD><EFBFBD>
NotifyIcon.hWnd = m_hWnd;
lstrcpy(NotifyIcon.szTip, _T("WDQ-WCS-PLATFORM"));
NotifyIcon.uCallbackMessage = WM_SYSTEMTRAY;
NotifyIcon.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;
NotifyIcon.uID = TRAY_ICON_ID;
Shell_NotifyIcon(NIM_ADD, &NotifyIcon); //<2F><><EFBFBD><EFBFBD>ϵͳ<CFB5><CDB3><EFBFBD><EFBFBD>
m_ModuleListCtrl.InsertColumn(0, "<EFBFBD><EFBFBD><EFBFBD><EFBFBD>", 0, 150);
m_ModuleListCtrl.InsertColumn(1, "ģ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>", 0, 200);
m_ModuleListCtrl.InsertColumn(2, "<EFBFBD><EFBFBD><EFBFBD><EFBFBD>״̬", 0, 80);
m_ModuleListCtrl.InsertColumn(3, "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", 0, 80);
m_ModuleListCtrl.InsertColumn(4, "·<EFBFBD><EFBFBD>", 0, 400);
StartHttpServer();
InitModule();
RefresModuleShow();
//static CFont fontList;
//fontList.CreatePointFont(120, "<22><><EFBFBD><EFBFBD>");
//m_ModuleListCtrl.SetFont(&fontList);
//m_ModuleListCtrl.SetExtendedStyle(LVS_EX_FULLROWSELECT);
return TRUE; // return TRUE unless you set the focus to a control
// <20>쳣: OCX <20><><EFBFBD><EFBFBD>ҳӦ<D2B3><D3A6><EFBFBD><EFBFBD> FALSE
}
afx_msg LRESULT CAgvMainDialog::OnSystemtray(WPARAM wParam, LPARAM lParam)
{
//wParam<61><6D><EFBFBD>յ<EFBFBD><D5B5><EFBFBD>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD>ID<49><44><EFBFBD><EFBFBD>lParam<61><6D><EFBFBD>յ<EFBFBD><D5B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ
// if(wParam!=IDR_MAINFRAME)
// return 1;
switch (lParam)
{
case WM_RBUTTONDOWN://<2F>Ҽ<EFBFBD><D2BC><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݲ˵<DDB2>
{
CMenu menuexit; //menu.LoadMenuW(IDR_MENU1);
//<2F><><EFBFBD>ز˵<D8B2><CBB5><EFBFBD>Դ
menuexit.LoadMenuA(IDR_MENU);
CMenu *pPopup=menuexit.GetSubMenu(0);
CPoint mypoint; GetCursorPos(&mypoint);
//ClientToScreen(&mypoint);//<2F><><EFBFBD>ͻ<EFBFBD><CDBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ת<EFBFBD><D7AA>Ϊ<EFBFBD><CEAA>Ļ<EFBFBD><C4BB><EFBFBD><EFBFBD>
//SetForegroundWindow();
PostMessage(WM_NULL,0,0); //<2F><>ʾ<EFBFBD>Ҽ<EFBFBD><D2BC>˵<EFBFBD><CBB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E0B4B0>ӵ<EFBFBD>С<EFBFBD>
pPopup->TrackPopupMenu(TPM_LEFTALIGN,mypoint.x,mypoint.y,this);
break;
}
}
return 0;
}
BOOL CAgvMainDialog::StartHttpServer()
{
char acIp[64] = { 0 };
GetPrivateProfileString("AGV", "IP", "0.0.0.0", acIp, 63, theApp.m_strConfigFile);
int nPort = (short)GetPrivateProfileInt("AGV", "PORT", 0, theApp.m_strConfigFile);
httpServerListener = new HttpServiceListener(this);
BOOL bRet = httpService.Create(acIp, nPort, httpServerListener, this);
if (bRet)
{
CString strMsg;
strMsg.Format("***HTTP Server %s:%d Start Succeed***", acIp, nPort);
GetDlgItem(IDC_STATIC_SERVER_STATUS)->SetWindowText(strMsg);
}
else
{
CString strMsg;
strMsg.Format("***HTTP Server %s:%d Start Failed***", acIp, nPort);
GetDlgItem(IDC_STATIC_SERVER_STATUS)->SetWindowText(strMsg);
}
return bRet;
}
CString CAgvMainDialog::UTF8ToMultiByte(const std::string& utf8String)
{
int len = MultiByteToWideChar(CP_UTF8, 0, utf8String.c_str(), -1, NULL, 0);
std::wstring wideString(len, L'\0');
MultiByteToWideChar(CP_UTF8, 0, utf8String.c_str(), -1, &wideString[0], len);
len = WideCharToMultiByte(CP_ACP, 0, wideString.c_str(), -1, NULL, 0, NULL, NULL);
CString multiByteString;
multiByteString.GetBufferSetLength(len);
WideCharToMultiByte(CP_ACP, 0, wideString.c_str(), -1, multiByteString.GetBuffer(), len, NULL, NULL);
multiByteString.ReleaseBuffer();
return multiByteString;
}
void CAgvMainDialog::InitModule()
{
//<2F><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>
time_t lNowTime = 0;
time(&lNowTime);
int lPort = 7000 + lNowTime % 1000 * 10;//<2F>˿ں<CBBF>ÿ<EFBFBD><C3BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>£<EFBFBD><C2A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E1B3AC>10<31><30>ģ<EFBFBD><C4A3>
int lCount = GetPrivateProfileInt("AGV-MODULE", "COUNT", 0, theApp.m_strConfigFile);
for (int i = 0; i < lCount; i++)
{
char acCnNameKey[64] = { 0 }, acCnName[64] = { 0 },
acNameKey[64] = { 0 }, acName[64] = { 0 },
acPathKey[64] = { 0 }, acPath[256] = { 0 }, acPipe[256] = { 0 },
acLastStatusKey[64] = {0};
sprintf_s(acCnNameKey, "CN_NAME_%d", i);
sprintf_s(acNameKey, "NAME_%d", i);
sprintf_s(acPathKey, "PATH_%d", i);
sprintf_s(acLastStatusKey, "LAST_STATUS_%d", i);
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƣ<EFBFBD><C6A3><EFBFBD><EFBFBD><EFBFBD>ʾ<EFBFBD><CABE>
GetPrivateProfileString("AGV-MODULE", acCnNameKey, "", acCnName, sizeof(acCnName) - 1, theApp.m_strConfigFile);
//<2F><><EFBFBD><EFBFBD>--ͬʱ<CDAC><CAB1>Ϊ<EFBFBD><CEAA>Ϣ<EFBFBD><CFA2>ʶ
GetPrivateProfileString("AGV-MODULE", acNameKey, "", acName, sizeof(acName)-1, theApp.m_strConfigFile);
//ģ<><C4A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>·<EFBFBD><C2B7>
GetPrivateProfileString("AGV-MODULE", acPathKey, "", acPath, sizeof(acPath)-1, theApp.m_strConfigFile);
CString strPath(acPath);
if (strPath.Find(":") <= 0)
{
strPath = theApp.m_strBaseDir + "\\" + strPath;
}
int lLastStatus = GetPrivateProfileInt("AGV-MODULE", acLastStatusKey, 0, theApp.m_strConfigFile);
CModuleProcess* pModule = new CModuleProcess(this, strPath, acName, i);
CString strPipeName;
strPipeName.Format("%d", lPort++);
pModule->SetPipeName(strPipeName);
m_mapAllNormal[acName] = pModule;
sprintf_s(acPipe, "PIPE_%s", acName);
WritePrivateProfileString("AGV-MODULE", acPipe, strPipeName, theApp.m_strPipeFile);
CString strChName = UTF8ToMultiByte(acCnName);
int lItem = m_ModuleListCtrl.InsertItem(65535, strChName);
m_ModuleListCtrl.SetItemText(lItem, 1, acName);
m_ModuleListCtrl.SetItemText(lItem, 4, strPath);
m_ModuleListCtrl.SetItemData(lItem, (DWORD_PTR)pModule);
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>Ĭ<EFBFBD><C4AC>ɱ<EFBFBD><C9B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģ<EFBFBD><C4A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
int nPos = strPath.ReverseFind('\\');
CString fileName = strPath.Right(strPath.GetLength() - nPos - 1);
KillProcess(fileName);
int nDebug = GetPrivateProfileInt("AGV-MODULE", "DEBUG", 0, theApp.m_strConfigFile);
m_nDebug = nDebug;
if (lLastStatus == 1 || nDebug == 1)//0<><30><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>1<EFBFBD><31><EFBFBD><EFBFBD>
{
pModule->Start(nDebug);
}
}
return ;
}
void CAgvMainDialog::RefresModuleShow()
{
for (int i = 0; i < m_ModuleListCtrl.GetItemCount(); i++)
{
CModuleProcess* pModule = (CModuleProcess*)m_ModuleListCtrl.GetItemData(i);
CString strText;
strText.Format("%d", pModule->m_lReStartCount);
int lStatus = pModule->GetStatus();
if (0 == lStatus)
{
m_ModuleListCtrl.SetItemText(i, 2, "<EFBFBD><EFBFBD>ֹͣ");
}
else if (1 == lStatus)
{
m_ModuleListCtrl.SetItemText(i, 2, "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
}
else if (2 == lStatus)
{
m_ModuleListCtrl.SetItemText(i, 2, "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
}
else
{
m_ModuleListCtrl.SetItemText(i, 2, "<EFBFBD>");
}
if (m_nDebug == 1)
{
m_ModuleListCtrl.SetItemText(i, 2, "<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģʽ");
}
m_ModuleListCtrl.SetItemText(i, 3, strText);
}
}
void CAgvMainDialog::OnClose()
{
// TODO: <20>ڴ<EFBFBD><DAB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>/<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ĭ<EFBFBD><C4AC>ֵ
AfxGetApp()->m_pMainWnd->ShowWindow(SW_HIDE);
}
CModuleProcess* CAgvMainDialog::GetModuleByName(CString strName)
{
for (int i = 0; i < m_ModuleListCtrl.GetItemCount(); i++)
{
CModuleProcess* pModule = (CModuleProcess*)m_ModuleListCtrl.GetItemData(i);
if (pModule->GetModuleName() == strName)
{
return pModule;
}
}
return NULL;
}
void CAgvMainDialog::OnNMRClickListModule(NMHDR *pNMHDR, LRESULT *pResult)
{
LPNMITEMACTIVATE pNMItemActivate = reinterpret_cast<LPNMITEMACTIVATE>(pNMHDR);
// TODO: <20>ڴ<EFBFBD><DAB4><EFBFBD><EFBFBD>ӿؼ<D3BF>֪ͨ<CDA8><D6AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
int lIndex = pNMLV->iItem;
if (lIndex == -1)
{
*pResult = 0;
return;
}
CModuleProcess* pModule = (CModuleProcess*)m_ModuleListCtrl.GetItemData(lIndex);
CMenu menu;
menu.CreatePopupMenu();
// <20><><EFBFBD>Ӳ˵<D3B2><CBB5><EFBFBD>
int lModuleStatus = pModule->GetStatus();
if (0 == lModuleStatus)
{
menu.AppendMenu(MF_STRING, 100, _T("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģ<EFBFBD><EFBFBD>"));
}
else if (1 == lModuleStatus)
{
menu.AppendMenu(MF_STRING, 101, _T("ֹͣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>"));
}
else
{
menu.AppendMenu(MF_STRING, 101, _T("ǿ<EFBFBD><EFBFBD>ֹͣ"));
}
// <20><><EFBFBD>Ӹ<EFBFBD><D3B8><EFBFBD><EFBFBD>˵<EFBFBD><CBB5><EFBFBD>...
char acLastStatusKey[64] = { 0 };
sprintf_s(acLastStatusKey, "LAST_STATUS_%d", pModule->m_lModuleIndex);
// <20><>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD>
CPoint point;
GetCursorPos(&point);
int nCmdID = menu.TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON | TPM_RETURNCMD, point.x, point.y, this);
// <20><><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD>ѡ<EFBFBD><D1A1><EFBFBD>IJ˵<C4B2><CBB5><EFBFBD>
switch (nCmdID)
{
case 100:
// ִ<>в˵<D0B2><CBB5><EFBFBD>1<EFBFBD>IJ<EFBFBD><C4B2><EFBFBD>
pModule->Start();
WritePrivateProfileString("AGV-MODULE", acLastStatusKey, "1", theApp.m_strConfigFile);
break;
case 101:
// ִ<>в˵<D0B2><CBB5><EFBFBD>2<EFBFBD>IJ<EFBFBD><C4B2><EFBFBD>
pModule->Stop();
WritePrivateProfileString("AGV-MODULE", acLastStatusKey, "0", theApp.m_strConfigFile);
break;
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD><CBB5><EFBFBD>...
}
menu.DestroyMenu();
RefresModuleShow();
*pResult = 0;
}
LRESULT CAgvMainDialog::OnUpdateModule(WPARAM wparam, LPARAM lparam)
{
RefresModuleShow();
return 0;
}
void CAgvMainDialog::OnNMDblclkListModule(NMHDR *pNMHDR, LRESULT *pResult)
{
LPNMITEMACTIVATE pNMItemActivate = reinterpret_cast<LPNMITEMACTIVATE>(pNMHDR);
// TODO: <20>ڴ<EFBFBD><DAB4><EFBFBD><EFBFBD>ӿؼ<D3BF>֪ͨ<CDA8><D6AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
int lIndex = pNMLV->iItem;
if (lIndex == -1)
{
*pResult = 0;
return;
}
CModuleProcess* pModule = (CModuleProcess*)m_ModuleListCtrl.GetItemData(lIndex);
int lModuleStatus = pModule->GetStatus();
if (lModuleStatus == 1)
{
pModule->SendDataToModule(MAIN_2_MODULE_SHOWWINDOW, NULL, 0);
}
*pResult = 0;
}
/*
<EFBFBD>ɽ<EFBFBD><EFBFBD>е<EFBFBD><EFBFBD>ԣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̵<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD>رս<EFBFBD><EFBFBD>̵ĵط<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>KillProcess(_T("Ҫ<>رյĽ<D5B5><C4BD>̵<EFBFBD><CCB5><EFBFBD><EFBFBD><EFBFBD>"));<3B><><EFBFBD>ɡ<EFBFBD>
*/
void CAgvMainDialog::KillProcess(CString sExeName)
{
//CreateToolhelp32Snapshot()<29>õ<EFBFBD>ϵͳ<CFB5><CDB3><EFBFBD>̵<EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
HANDLE hSnapShot = ::CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if (hSnapShot == 0)
return;
PROCESSENTRY32 thePE;
thePE.dwSize = sizeof(PROCESSENTRY32);
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>еĵ<D0B5>һ<EFBFBD><D2BB>ϵͳ<CFB5><CDB3><EFBFBD><EFBFBD>
bool Status = Process32First(hSnapShot, &thePE);
bool bHaveFlag = false; //<2F>ҵ<EFBFBD><D2B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>״̬
DWORD ProcessID = 0;
while (Status)
{
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>е<EFBFBD><D0B5><EFBFBD>һ<EFBFBD><D2BB>ϵͳ<CFB5><CDB3><EFBFBD><EFBFBD>
Status = Process32Next(hSnapShot, &thePE);
//<2F>ҵ<EFBFBD><D2B5><EFBFBD>Ӧ<EFBFBD>Ľ<EFBFBD><C4BD><EFBFBD> **.exe
// if(0 == wcscmp(thePE.szExeFile,L""))
CString sFindName = thePE.szExeFile;//<2F><><EFBFBD><EFBFBD><EFBFBD>еĽ<D0B5><C4BD><EFBFBD><EFBFBD><EFBFBD>
CString sTemp = sExeName.Mid(0, sFindName.GetLength());//Ҫ<>رյĽ<D5B5><C4BD><EFBFBD><EFBFBD><EFBFBD>
if (sFindName == sTemp)
{
bHaveFlag = true;
ProcessID = thePE.th32ProcessID;
//<2F><><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8><EFBFBD>Ľ<EFBFBD><C4BD><EFBFBD> ProcessID
if (!TerminateProcess(OpenProcess
(PROCESS_TERMINATE || PROCESS_QUERY_INFORMATION, false, ProcessID), 0))
{
//AfxMessageBox(L"<22>޷<EFBFBD><DEB7><EFBFBD>ָֹ<D6B9><D6B8><EFBFBD>Ľ<EFBFBD><C4BD>̣<EFBFBD>", MB_ICONWARNING || MB_OK);
}
else
{
//AfxMessageBox(L"<22><><EFBFBD>̽<EFBFBD><CCBD><EFBFBD><EFBFBD><EFBFBD>", MB_ICONWARNING || MB_OK);
break;
}
}
}
CloseHandle(hSnapShot);
}

68
Platform/AgvMainDialog.h Normal file
View File

@@ -0,0 +1,68 @@
#pragma once
#include "afxcmn.h"
#include "ModuleListCtrl.h"
class HttpServiceListener;
class CRobotClientDlg;
class CTransportClientDlg;
class CStackerClientDlg;
class CModuleProcess;
// CAgvMainDialog <20>Ի<EFBFBD><D4BB><EFBFBD>
#define WM_SYSTEMTRAY WM_USER+5
class CAgvMainDialog : public CDialogEx
{
DECLARE_DYNAMIC(CAgvMainDialog)
public:
CAgvMainDialog(CWnd* pParent = NULL); // <20><>׼<EFBFBD><D7BC><EFBFBD><EFBFBD><ECBAAF>
virtual ~CAgvMainDialog();
// <20>Ի<EFBFBD><D4BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
#ifdef AFX_DESIGN_TIME
enum { IDD = IDD_WCS_MAIN_DIALOG };
#endif
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV ֧<><D6A7>
DECLARE_MESSAGE_MAP()
public:
afx_msg LRESULT OnSystemtray(WPARAM wParam, LPARAM lParam);
//CTabCtrl m_SubTab;
CHttpClient m_httpClient;
CDialog *m_pSubDlg[10];
int m_nDebug;
//int m_nSubDlg;
virtual BOOL OnInitDialog();
HttpServiceListener *httpServerListener;
CHttpService httpService;
BOOL StartHttpServer();
afx_msg void OnTrayShow();
afx_msg void OnTrayExit();
void InitModule();
void RefresModuleShow();
std::map<CString, CModuleProcess*> m_mapAllNormal;
CModuleProcess* GetModuleByName(CString strName);
CString UTF8ToMultiByte(const std::string& utf8String);
private:
NOTIFYICONDATA NotifyIcon; //ϵͳ<CFB5><CDB3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
public:
afx_msg void OnClose();
CModuleListCtrl m_ModuleListCtrl;
afx_msg void OnNMRClickListModule(NMHDR *pNMHDR, LRESULT *pResult);
LRESULT OnUpdateModule(WPARAM wparam, LPARAM lparam);
afx_msg void OnNMDblclkListModule(NMHDR *pNMHDR, LRESULT *pResult);
void KillProcess(CString sExeName);
CEdit m_EditMultiLine;
void AddLog2Edit(CString strMsg);
};

493
Platform/HttpClient.cpp Normal file
View File

@@ -0,0 +1,493 @@
#include "stdafx.h"
#include "HttpClient.h"
#include "Agv.h"
#include "curl.h"
char getResponseStr[10240] = { 0 };
//<2F>ص<EFBFBD><D8B5><EFBFBD><EFBFBD><EFBFBD>
size_t write_data(void *ptr, size_t size, size_t nmemb, void *stream)
{
TRACE("%s\r\n", (char*)ptr);
//string data((const char*) ptr, (size_t) size * nmemb);
memcpy((char*)stream+strlen((char*)stream), ptr, size*nmemb);
//*((stringstream*) stream) << data << endl;
return size * nmemb;
}
CHttpClient::CHttpClient()
{
char acIp[64] = { 0 }, acUrl[128] = { 0 };
GetPrivateProfileString("WMS", "IP", "0.0.0.0", acIp, 63, theApp.m_strConfigFile);
m_strWmsIp = acIp;
m_nWmsPort = (short)GetPrivateProfileInt("WMS", "PORT", 0, theApp.m_strConfigFile);
GetPrivateProfileString("WMS", "URL", "0.0.0.0", acUrl, 128, theApp.m_strConfigFile);
m_strWmsUrl = acUrl;
memset(acIp, 0, 64);
memset(acUrl, 0, 128);
GetPrivateProfileString("OPENTCS", "IP", "0.0.0.0", acIp, 63, theApp.m_strConfigFile);
m_strOpentcsIp = acIp;
m_nOpentcsPort = (short)GetPrivateProfileInt("OPENTCS", "PORT", 0, theApp.m_strConfigFile);
GetPrivateProfileString("OPENTCS", "URL", "0.0.0.0", acUrl, 128, theApp.m_strConfigFile);
m_strOpentcsUrl = acUrl;
//LogOutToFile("[info] <20><><EFBFBD>ӷ<EFBFBD><D3B7><EFBFBD><EFBFBD><EFBFBD>:[%s][%s:%d]", m_strWmsUrl.GetBuffer(), acIp, m_nPort);
}
CHttpClient::~CHttpClient(void)
{
}
string get_string(string res) {
//ɾ<><C9BE><EFBFBD><EFBFBD><EFBFBD>з<EFBFBD>
int r = res.find('\r\n');
while (r != string::npos)
{
if (r != string::npos)
{
res.replace(r, 1, "");
r = res.find('\r\n');
}
}
return res;
}
/*
CString CHttpClient::WmsCallBack(CString strSender, CString strMsgType, CString strParam)
{
LogOutToFile("CHttpClient::WmsCallBack Start");
CString strUrl = "/api/Wcs/RecvMsgFromWcs";
INTERNET_PORT m_Port = m_nPort;
CString strHost = m_strIp;
try
{
CInternetSession m_Session("HttpClient");
CHttpConnection * m_Server = NULL;
m_Server = m_Session.GetHttpConnection(strHost, m_Port);
CHttpFile*pFile = m_Server->OpenRequest(CHttpConnection::HTTP_VERB_POST, strUrl);
CString strHeaders, tempStr;
CString strHeader = _T("Content-Type: application/x-www-form-urlencoded\r\n");
//pFile->AddRequestHeaders("Accept: application / json");
//pFile->AddRequestHeaders("Content-Type:application/json");
//pFile->AddRequestHeaders("Content-Type:charset=UTF-8");
Json::Value root;
root["sender"] = strSender.GetBuffer();
root["receiver"] = "WMS";
TRACE("<22>ظ<EFBFBD><D8B8><EFBFBD>Ϣ%s\r\n",strMsgType);
//<2F><>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD>ת<EFBFBD><D7AA>
if (strMsgType == "AGV_ENTER_INTO_ROBOT_REQ") //AGV<47><56><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȥ<EFBFBD><C8A5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ҵ<EFBFBD><D2B5><EFBFBD><EFBFBD>
{
strMsgType = "AGV_RESUME";//AGV<47>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD>
}
else if (strMsgType == "FORKLIFT_ENTER_INTO_ROBOT_REQ")//FORKLIFT<46><54><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ҵ<EFBFBD><D2B5><EFBFBD><EFBFBD>
{
strMsgType = "FORKLIFT_RESUME"; //<2F><EFBFBD>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD>
}
else if (strMsgType == "FORKLIFT_ENTER_INTO_STACKER_REQ")//FORKLIFT<46><54><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{
strMsgType = "FORKLIFT_RESUME"; //<2F><EFBFBD>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD>
}
root["type"] = strMsgType.GetBuffer();
root["params"] = strParam.GetBuffer();
Json::FastWriter writer;
string strJson1 = "params=" + writer.write(root);
//string strJson1 = writer.write(root);
//AfxMessageBox(strJson1.c_str());
pFile->SendRequest(strHeader, (char*)strJson1.c_str(), strJson1.length());
DWORD httpStatus; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>״̬
pFile->QueryInfoStatusCode(httpStatus);
CString statusCode;
CString strResult;
if (httpStatus == HTTP_STATUS_OK)
{
CString strLine;
int m_read;
while ((m_read = pFile->ReadString(strLine)) > 0)
strResult += strLine;
}
else
{
//AfxMessageBox("HTTP_STATUS_FAILED\n");
//LogOutToFile("[info] <20>ִ<EFBFBD>״̬<D7B4>ϴ<EFBFBD><CFB4><EFBFBD><EFBFBD><EFBFBD>״̬...%d", httpStatus);
}
if (pFile)
delete pFile;
if (m_Server)
delete m_Server;
LogOutToFile("CHttpClient::WmsCallBack End1");
m_Session.Close();
//AfxMessageBox(strResult);
return strResult;
//AfxMessageBox(strResult);
}
catch (...)
{
//AfxMessageBox("error2");
}
LogOutToFile("CHttpClient::WmsCallBack End2");
return "";
}
*/
/*
CString CHttpClient::FastCallBack(CString strUrl, CString strParam)
{
//CString strUrl = "/api/project.benma.Fast/CallbacakFromWcs";
INTERNET_PORT m_Port = m_nPort;
CString strHost = m_strIp;
LogOutToFile("CHttpClient::FastCallBack Start");
try
{
CInternetSession m_Session("HttpClient");
CHttpConnection * m_Server = NULL;
m_Server = m_Session.GetHttpConnection(strHost, m_Port);
CHttpFile*pFile = m_Server->OpenRequest(CHttpConnection::HTTP_VERB_POST, strUrl);
CString strHeaders, tempStr;
CString strHeader = _T("Content-Type: application/x-www-form-urlencoded\r\n");
//pFile->AddRequestHeaders("Accept: application / json");
//pFile->AddRequestHeaders("Content-Type:application/json");
//pFile->AddRequestHeaders("Content-Type:charset=UTF-8");
Json::Value root;
root["sender"] = "TEST";
root["receiver"] = "WMS";
root["params"] = strParam.GetBuffer();
Json::FastWriter writer;
string strJson1 = "params=" + writer.write(root);
//string strJson1 = writer.write(root);
//AfxMessageBox(strJson1.c_str());
pFile->SendRequest(strHeader, (char*)strJson1.c_str(), strJson1.length());
DWORD httpStatus; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>״̬
pFile->QueryInfoStatusCode(httpStatus);
CString statusCode;
CString strResult;
if (httpStatus == HTTP_STATUS_OK)
{
CString strLine;
int m_read;
while ((m_read = pFile->ReadString(strLine)) > 0)
strResult += strLine;
}
else
{
//AfxMessageBox("HTTP_STATUS_FAILED\n");
//LogOutToFile("[info] <20>ִ<EFBFBD>״̬<D7B4>ϴ<EFBFBD><CFB4><EFBFBD><EFBFBD><EFBFBD>״̬...%d", httpStatus);
}
if (pFile)
delete pFile;
if (m_Server)
delete m_Server;
m_Session.Close();
//AfxMessageBox(strResult);
LogOutToFile("CHttpClient::FastCallBack End1");
return strResult;
//AfxMessageBox(strResult);
}
catch (...)
{
//AfxMessageBox("error2");
}
LogOutToFile("CHttpClient::FastCallBack End2");
return "";
}
CString CHttpClient::AbnormalCallBack(CString strType, CString strParam)
{
CString strUrl = "/api/Runlog/AbnormalCallBack";
INTERNET_PORT m_Port = m_nPort;
CString strHost = m_strIp;
LogOutToFile("CHttpClient::AbnormalCallBack Start");
try
{
CInternetSession m_Session("HttpClient");
CHttpConnection * m_Server = NULL;
m_Server = m_Session.GetHttpConnection(strHost, m_Port);
CHttpFile*pFile = m_Server->OpenRequest(CHttpConnection::HTTP_VERB_POST, strUrl);
CString strHeaders, tempStr;
CString strHeader = _T("Content-Type: application/x-www-form-urlencoded\r\n");
//pFile->AddRequestHeaders("Accept: application / json");
//pFile->AddRequestHeaders("Content-Type:application/json");
//pFile->AddRequestHeaders("Content-Type:charset=UTF-8");
Json::Value root;
root["type"] = _UnicodeToUtf8(strType);
root["content"] = _UnicodeToUtf8(strParam);
//root["params"] = strParam.GetBuffer();
Json::FastWriter writer;
string strJson1 = "params=" + writer.write(root);
//string strJson1 = writer.write(root);
//AfxMessageBox(strJson1.c_str());
pFile->SendRequest(strHeader, (char*)strJson1.c_str(), strJson1.length());
DWORD httpStatus; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>״̬
pFile->QueryInfoStatusCode(httpStatus);
CString statusCode;
CString strResult;
if (httpStatus == HTTP_STATUS_OK)
{
CString strLine;
int m_read;
while ((m_read = pFile->ReadString(strLine)) > 0)
strResult += strLine;
}
else
{
//AfxMessageBox("HTTP_STATUS_FAILED\n");
//LogOutToFile("[info] <20>ִ<EFBFBD>״̬<D7B4>ϴ<EFBFBD><CFB4><EFBFBD><EFBFBD><EFBFBD>״̬...%d", httpStatus);
}
if (pFile)
delete pFile;
if (m_Server)
delete m_Server;
m_Session.Close();
//AfxMessageBox(strResult);
LogOutToFile("CHttpClient::AbnormalCallBack End1");
return strResult;
//AfxMessageBox(strResult);
}
catch (...)
{
//AfxMessageBox("error2");
}
LogOutToFile("CHttpClient::AbnormalCallBack End2");
return "";
}
*/
CString CHttpClient::GenericPost2Wms(CString strParam)
{
LogOutToFile("CHttpClient::GenericPost Start");
INTERNET_PORT m_Port = m_nWmsPort;
CString strHost = m_strWmsIp;
//CString strRequrl;
//strRequrl.Format("%s:%d%s", m_strIp, m_nPort, m_strUrl);
//AfxMessageBox(strRequrl);
try
{
CInternetSession m_Session("HttpClient");
CHttpConnection * m_Server = NULL;
m_Server = m_Session.GetHttpConnection(strHost, m_Port);
CHttpFile*pFile = m_Server->OpenRequest(CHttpConnection::HTTP_VERB_POST, m_strWmsUrl);
//AfxMessageBox(m_strUrl);
CString strHeaders, tempStr;
CString strHeader = _T("Content-Type: application/x-www-form-urlencoded\r\n");
//pFile->AddRequestHeaders("Accept: application / json");
//pFile->AddRequestHeaders("Content-Type:application/json");
//pFile->AddRequestHeaders("Content-Type:charset=UTF-8");
//string strJson1 = writer.write(root);
//AfxMessageBox(strJson1.c_str());
pFile->SendRequest(strHeader, (char*)strParam.GetBuffer(), strParam.GetLength());
DWORD httpStatus; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>״̬
pFile->QueryInfoStatusCode(httpStatus);
CString statusCode;
CString strResult;
if (httpStatus == HTTP_STATUS_OK)
{
CString strLine;
int m_read;
while ((m_read = pFile->ReadString(strLine)) > 0)
strResult += strLine;
}
else
{
//AfxMessageBox("HTTP_STATUS_FAILED\n");
//LogOutToFile("[info] <20>ִ<EFBFBD>״̬<D7B4>ϴ<EFBFBD><CFB4><EFBFBD><EFBFBD><EFBFBD>״̬...%d", httpStatus);
}
//AfxMessageBox(strResult);
if (pFile)
delete pFile;
if (m_Server)
delete m_Server;
LogOutToFile("CHttpClient::WmsCallBack End1");
m_Session.Close();
//AfxMessageBox(strResult);
return strResult;
//AfxMessageBox(strResult);
}
catch (...)
{
//AfxMessageBox("error2");
}
LogOutToFile("CHttpClient::WmsCallBack End2");
return "";
}
CString CHttpClient::GenericPost2Opentcs(CString strParam)
{
LogOutToFile("CHttpClient::GenericPost Start");
INTERNET_PORT m_Port = m_nOpentcsPort;
CString strHost = m_strOpentcsIp;
//CString strRequrl;
//strRequrl.Format("%s:%d%s", m_strIp, m_nPort, m_strUrl);
//AfxMessageBox(strRequrl);
try
{
CInternetSession m_Session("HttpClient");
CHttpConnection * m_Server = NULL;
m_Server = m_Session.GetHttpConnection(strHost, m_Port);
CHttpFile*pFile = m_Server->OpenRequest(CHttpConnection::HTTP_VERB_POST, m_strOpentcsUrl);
//AfxMessageBox(m_strUrl);
CString strHeaders, tempStr;
CString strHeader = _T("Content-Type: application/x-www-form-urlencoded\r\n");
//pFile->AddRequestHeaders("Accept: application / json");
//pFile->AddRequestHeaders("Content-Type:application/json");
//pFile->AddRequestHeaders("Content-Type:charset=UTF-8");
//string strJson1 = writer.write(root);
//AfxMessageBox(strJson1.c_str());
pFile->SendRequest(strHeader, (char*)strParam.GetBuffer(), strParam.GetLength());
DWORD httpStatus; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>״̬
pFile->QueryInfoStatusCode(httpStatus);
CString statusCode;
CString strResult;
if (httpStatus == HTTP_STATUS_OK)
{
CString strLine;
int m_read;
while ((m_read = pFile->ReadString(strLine)) > 0)
strResult += strLine;
}
else
{
//AfxMessageBox("HTTP_STATUS_FAILED\n");
//LogOutToFile("[info] <20>ִ<EFBFBD>״̬<D7B4>ϴ<EFBFBD><CFB4><EFBFBD><EFBFBD><EFBFBD>״̬...%d", httpStatus);
}
//AfxMessageBox(strResult);
if (pFile)
delete pFile;
if (m_Server)
delete m_Server;
LogOutToFile("CHttpClient::WmsCallBack End1");
m_Session.Close();
//AfxMessageBox(strResult);
return strResult;
//AfxMessageBox(strResult);
}
catch (...)
{
//AfxMessageBox("error2");
}
LogOutToFile("CHttpClient::WmsCallBack End2");
return "";
}

33
Platform/HttpClient.h Normal file
View File

@@ -0,0 +1,33 @@
#pragma once
#include <afxinet.h>
#include <vector>
using namespace std;
class CHttpClient
{
public:
CHttpClient();
~CHttpClient(void);
//<2F>ص<EFBFBD>WMS
//CString WmsCallBack(CString strSender, CString strMsgType, CString strParam);
//CString FastCallBack(CString strUrl, CString strParam);
//CString AbnormalCallBack(CString strType, CString strParam);
CString GenericPost2Wms(CString strParam);
CString GenericPost2Opentcs(CString strParam);
public:
CString m_strWmsIp, m_strOpentcsIp;
CString m_strWmsUrl, m_strOpentcsUrl;
int m_nWmsPort, m_nOpentcsPort;
CInternetSession session;
};

216
Platform/HttpService.cpp Normal file
View File

@@ -0,0 +1,216 @@
#include "StdAfx.h"
#include "HttpService.h"
#include <atlconv.h>
#pragma comment(lib, "httpapi.lib")
#include "AgvMainDialog.h"
#include "ModuleProcess.h"
CHttpService::CHttpService()
{
m_thread = NULL;
m_req_queue = NULL;
m_req_buffer = NULL;
m_req_buffer_size = 4096;
}
BOOL CHttpService::Create(CString strIp, INT port, IHttpServiceListener *listener, CAgvMainDialog *pParentDlg)
{
ULONG ret;
CHAR url[1024];
m_pMainDialog = pParentDlg;
HTTPAPI_VERSION version = HTTP_VERSION_1_0;
sprintf(url, "http://%s:%d/", strIp, port);
ret = HttpInitialize(version, HTTP_INITIALIZE_SERVER, NULL);
if (ret != NO_ERROR)
{
TRACE("HttpInitialize error(%u)!\r\n", ret);
return FALSE;
}
ret = HttpCreateHttpHandle(&m_req_queue, 0);
if (ret != NO_ERROR)
{
TRACE("HttpCreateHttpHandle error(%u)!\n", ret);
HttpTerminate(HTTP_INITIALIZE_SERVER, NULL);
return FALSE;
}
//ERROR_ACCESS_DENIED --- <20><>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD>Ա<EFBFBD><D4B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
USES_CONVERSION;
ret = HttpAddUrl(m_req_queue, A2W(url), NULL);
if (ret != NO_ERROR)
{
TRACE("HttpAddUrl error(%u)!\n", ret);
CloseHandle(m_req_queue);
HttpTerminate(HTTP_INITIALIZE_SERVER, NULL);
return FALSE;
}
m_req_buffer = (LPBYTE)malloc(m_req_buffer_size);
m_listener = listener;
m_thread = AfxBeginThread(RecvRequestThread, this);
return TRUE;
}
BOOL CHttpService::Delete(void)
{
if (m_req_queue)
{
CloseHandle(m_req_queue);
HttpTerminate(HTTP_INITIALIZE_SERVER, NULL);
m_req_queue = NULL;
}
if (m_req_buffer)
{
free(m_req_buffer);
m_req_buffer = NULL;
}
if (m_thread)
{
m_thread->Delete();
m_thread = NULL;
}
return TRUE;
}
BOOL CHttpService::SendRequestResp(HTTP_REQUEST_ID req_id, INT status, LPCSTR reason, LPCSTR type, HANDLE file, LPVOID mem, DWORD mem_size)
{
HTTP_RESPONSE resp;
HTTP_DATA_CHUNK chunk;
DWORD ret;
DWORD sent;
RtlZeroMemory(&resp, sizeof(resp));
resp.StatusCode = status;
resp.pReason = reason;
resp.ReasonLength = (USHORT)strlen(reason);
resp.Headers.KnownHeaders[HttpHeaderContentType].pRawValue = type;
resp.Headers.KnownHeaders[HttpHeaderContentType].RawValueLength = (USHORT)strlen(type);
resp.EntityChunkCount = 1;
resp.pEntityChunks = &chunk;
if (file != NULL)
{
chunk.DataChunkType = HttpDataChunkFromFileHandle;
chunk.FromFileHandle.FileHandle = file;
chunk.FromFileHandle.ByteRange.StartingOffset.QuadPart = 0;
chunk.FromFileHandle.ByteRange.Length.QuadPart = HTTP_BYTE_RANGE_TO_EOF;
}
if (mem != NULL)
{
chunk.DataChunkType = HttpDataChunkFromMemory;
chunk.FromMemory.pBuffer = mem;
chunk.FromMemory.BufferLength = mem_size;
}
ret = HttpSendHttpResponse(m_req_queue, req_id, 0, &resp, NULL, &sent, NULL, 0, NULL, NULL);
if (ret != NO_ERROR)
{
TRACE(L"HttpSendHttpResponse error(%u)!\n", ret);
return FALSE;
}
return TRUE;
}
DWORD CHttpService::RecvRequestBody(HTTP_REQUEST_ID req_id, HANDLE file, char *mem, DWORD mem_size)
{
DWORD read = 0;
if (file != NULL)
{
return read;
}
if (mem != NULL)
{
HttpReceiveRequestEntityBody(m_req_queue, req_id, 0, mem, mem_size, &read, NULL);
mem[read] = 0;
return read;
}
return read;
}
UINT CHttpService::RecvRequestThread(LPVOID param)
{
CHttpService *self;
self = (CHttpService *)param;
self->DoReceiveRequests();
Sleep(INFINITE);
return 0;
}
BOOL CHttpService::DoReceiveRequests(void)
{
ULONG ret;
DWORD bytes_read;
PHTTP_REQUEST request;
request = (PHTTP_REQUEST)m_req_buffer;
while (1)
{
RtlZeroMemory(request, m_req_buffer_size);
ret = HttpReceiveHttpRequest(m_req_queue, HTTP_NULL_ID, 0, request, m_req_buffer_size, &bytes_read, NULL);
if (ret == NO_ERROR)
{
m_listener->OnRecvRequest(this, request);
continue;
}
TRACE("HttpReceiveHttpRequest error(%u)!\r\n", ret);
if (ret == ERROR_OPERATION_ABORTED)
{
return FALSE;
}
if (ret == ERROR_INVALID_HANDLE)
{
return FALSE;
}
}
return TRUE;
}
BOOL CHttpService::GetRemoteAddr(PHTTP_REQUEST request, CString &text)
{
PSOCKADDR_IN addr = (PSOCKADDR_IN)request->Address.pRemoteAddress;
text.Format("%d.%d.%d.%d", addr->sin_addr.S_un.S_un_b.s_b1, addr->sin_addr.S_un.S_un_b.s_b2, addr->sin_addr.S_un.S_un_b.s_b3, addr->sin_addr.S_un.S_un_b.s_b4);
return TRUE;
}
BOOL HttpServiceListener::OnRecvRequest(CHttpService *inst, PHTTP_REQUEST request)
{
//<2F><><EFBFBD><EFBFBD>Ϣ
LogOutToFile("HttpServiceListener::OnRecvRequest Begin");
CString strText;
PSOCKADDR_IN addr = (PSOCKADDR_IN)request->Address.pRemoteAddress;
strText.Format("%d.%d.%d.%d", addr->sin_addr.S_un.S_un_b.s_b1, addr->sin_addr.S_un.S_un_b.s_b2, addr->sin_addr.S_un.S_un_b.s_b3, addr->sin_addr.S_un.S_un_b.s_b4);
//AfxMessageBox(strText);
CString strRecvFunc = request->pRawUrl;
CString strRecvParam = "";
//strRecvFunc += "==>";
for (;;)
{
char acBuffer[512] = { 0 };
int lRead = inst->RecvRequestBody(request->RequestId, NULL, acBuffer, 511);
strRecvParam += acBuffer;
if (lRead < 511)
{
break;
}
}
//strRecvParam += "\r\n";
Json::Reader reader;
Json::Value root;
if (reader.parse(strRecvParam.GetBuffer(), root))
{
CString strSender = root["sender"].asString().c_str();
CString strReceiver = root["receiver"].asString().c_str();
//CString strMsgType = root["type"].asString().c_str();
//CString strMsgParam = root["params"].asString().c_str();
CString strMsg = "<EFBFBD><EFBFBD><EFBFBD>յ<EFBFBD>" + strSender;
strMsg += "<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ:" + strRecvParam;
m_pMainDialog->AddLog2Edit(strMsg);
if (m_pMainDialog->m_mapAllNormal.find(strReceiver) != m_pMainDialog->m_mapAllNormal.end())
{
m_pMainDialog->m_mapAllNormal[strReceiver]->SendDataToModule(MAIN_2_MODULE_WMS, strRecvParam.GetBuffer(), strRecvParam.GetLength());
}
}
CString strRetMsg = "succeed";
//<2F>ظ<EFBFBD><D8B8><EFBFBD>Ϣ
inst->SendRequestResp(request->RequestId, 200, "OK", "application/json", NULL, strRetMsg.GetBuffer(), strRetMsg.GetLength());
LogOutToFile("HttpServiceListener::OnRecvRequest End");
return TRUE;
};

40
Platform/HttpService.h Normal file
View File

@@ -0,0 +1,40 @@
#pragma once
#include <http.h>
class CHttpService;
class CAgvMainDialog;
class IHttpServiceListener
{
public:
virtual BOOL OnRecvRequest(CHttpService *inst, PHTTP_REQUEST request) = 0;
};
class HttpServiceListener : public IHttpServiceListener
{
public:
HttpServiceListener(CAgvMainDialog *pParentDlg) { m_pMainDialog = pParentDlg; };
public:
BOOL OnRecvRequest(CHttpService *inst, PHTTP_REQUEST request);
public:
CAgvMainDialog *m_pMainDialog;
};
class CHttpService
{
public:
CHttpService();
BOOL Create(CString strIp, INT port, IHttpServiceListener *listener, CAgvMainDialog *pParentDlg);
BOOL Delete(void);
BOOL SendRequestResp(HTTP_REQUEST_ID req_id, INT status, LPCSTR reason, LPCSTR type, HANDLE file, LPVOID mem, DWORD mem_size);
DWORD RecvRequestBody(HTTP_REQUEST_ID req_id, HANDLE file, char *mem, DWORD mem_size);
BOOL DoReceiveRequests();
BOOL GetRemoteAddr(PHTTP_REQUEST request, CString &text);
public:
static UINT AFX_CDECL RecvRequestThread(LPVOID param);
private:
HANDLE m_req_queue;
LPBYTE m_req_buffer;
UINT m_req_buffer_size;
CWinThread *m_thread;
IHttpServiceListener *m_listener;
CAgvMainDialog *m_pMainDialog;
};

View File

@@ -0,0 +1,29 @@
// ModuleListCtrl.cpp : ʵ<><CAB5><EFBFBD>ļ<EFBFBD>
//
#include "stdafx.h"
#include "ModuleListCtrl.h"
// CModuleListCtrl
IMPLEMENT_DYNAMIC(CModuleListCtrl, CListCtrl)
CModuleListCtrl::CModuleListCtrl()
{
}
CModuleListCtrl::~CModuleListCtrl()
{
}
BEGIN_MESSAGE_MAP(CModuleListCtrl, CListCtrl)
END_MESSAGE_MAP()
// CModuleListCtrl <20><>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>

18
Platform/ModuleListCtrl.h Normal file
View File

@@ -0,0 +1,18 @@
#pragma once
// CModuleListCtrl
class CModuleListCtrl : public CListCtrl
{
DECLARE_DYNAMIC(CModuleListCtrl)
public:
CModuleListCtrl();
virtual ~CModuleListCtrl();
protected:
DECLARE_MESSAGE_MAP()
};

293
Platform/ModuleProcess.cpp Normal file
View File

@@ -0,0 +1,293 @@
#include "StdAfx.h"
#include "Agv.h"
#include "ModuleProcess.h"
#include "AgvMainDialog.h"
int g_ulTerminal = 0;
void g_PipeCallBack(void* pObj, int lMsgId, WPARAM wparam, LPARAM lparam)
{
CModuleProcess* pModule = (CModuleProcess*)pObj;
pModule->PipeCallBack(lMsgId, wparam, lparam);
}
CModuleProcess::CModuleProcess(CAgvMainDialog *pMainWnd, CString strModulePath, CString strModuleName, int lModuleIndex)
{
m_lModuleIndex = lModuleIndex;
m_strModulePath = strModulePath;
m_strModuleName = strModuleName;
m_hProcessManageThr = NULL;
m_bAcitv = FALSE;
m_hWnd = pMainWnd->m_hWnd;
m_pAgvMainWnd = pMainWnd;
m_bIsConnectModule = FALSE;
m_lReStartCount = 0;
m_lState = 0;
ZeroMemory(&m_pi,sizeof(m_pi)); //<2F>˲<EFBFBD><CBB2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
m_pstPipeServer = CCEXPipeServerBase::CreateObj();
m_nDebug = 0;
}
CModuleProcess::~CModuleProcess(void)
{
if (NULL != m_pstPipeServer)
{
delete m_pstPipeServer;
}
}
unsigned int __stdcall g_ProcessManageThr(void* pParam)
{
((CModuleProcess*)pParam)->ProcessManageThr();
return 0;
}
//<2F><><EFBFBD><EFBFBD>ģ<EFBFBD><C4A3>
BOOL CModuleProcess::Start(int nDebug)
{
m_nDebug = nDebug;
if (NULL != m_hProcessManageThr)
{
return FALSE;
}
if (m_strPipeName.IsEmpty())
{
return FALSE;
}
m_bAcitv = TRUE;
if (m_nDebug == 1)
{
if (NULL == m_pstPipeServer)
{
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
return FALSE;
}
m_pstPipeServer->RegisterCall(g_PipeCallBack, this);
m_pstPipeServer->Start(m_strPipeName);
return TRUE;
}
m_hProcessManageThr = (HANDLE)_beginthreadex(NULL, 0, g_ProcessManageThr, this, 0, NULL);
return TRUE;
}
//ֹͣģ<D6B9><C4A3>
void CModuleProcess::Stop()
{
if (NULL == m_hProcessManageThr)
{
LogOutToFile("CModuleProcess::Stop() already stop. [%s]", m_strModulePath);
return ;
}
LogOutToFile("CModuleProcess::Stop() bg [%s]", m_strModulePath);
m_bAcitv = FALSE;
if (m_pstPipeServer->IsConnect())
{
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģ<EFBFBD><C4A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӹܵ<D3B9><DCB5><EFBFBD><EFBFBD><EFBFBD>ֻ<EFBFBD><D6BB>Ҫ<EFBFBD>ر<EFBFBD><D8B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˿ڣ<CBBF><DAA3><EFBFBD>ģ<EFBFBD><C4A3><EFBFBD><EFBFBD><EFBFBD>ƽ̨<C6BD>˹رպ<D8B1><D5BA>ͻ<EFBFBD>ֱ<EFBFBD><D6B1><EFBFBD>˳<EFBFBD>
m_pstPipeServer->Stop();
}
else
{
//m_pstPipeServer->Stop();
//<2F><><EFBFBD><EFBFBD>ģ<EFBFBD><C4A3>δ<EFBFBD><CEB4><EFBFBD><EFBFBD>ƽ̨<C6BD><CCA8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģ<EFBFBD><C4A3><EFBFBD>޷<EFBFBD><DEB7><EFBFBD><EFBFBD><EFBFBD>ƽ̨<C6BD>Ĺرգ<D8B1><D5A3><EFBFBD><EFBFBD><EFBFBD>ǿ<EFBFBD>ư<EFBFBD><C6B0><EFBFBD>ģ<EFBFBD><C4A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
TerminateProcess(m_pi.hProcess, 0);
}
if (WAIT_TIMEOUT == WaitForSingleObject(m_hProcessManageThr, 5000))
{
TerminateProcess(m_pi.hProcess, 0);
Sleep(500);
LogOutToFile("CModuleProcess::Stop() timeout [%s]", m_strModulePath);
TerminateThread(m_hProcessManageThr, 0);
}
else
{
LogOutToFile("CModuleProcess::Stop() succ[%s]", m_strModulePath);
}
m_hProcessManageThr = NULL;
return;
}
int CModuleProcess::GetStatus()
{
if (NULL == m_hProcessManageThr)
{
return 0;
}
return m_lState;
}
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݵ<EFBFBD>ģ<EFBFBD><C4A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
BOOL CModuleProcess::SendDataToModule(int lMsgId, const char* pData, int lLen)
{
if (NULL == m_pstPipeServer)
{
return FALSE;
}
m_pstPipeServer->SendeMsg(lMsgId, pData, lLen);
return TRUE;
}
//<2F><>ģ<EFBFBD><C4A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͨѶ<CDA8>Ĺܵ<C4B9><DCB5>ص<EFBFBD><D8B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//1<><31>lparam > 0ʱ<30><CAB1>wparamΪ<6D><CEAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݣ<EFBFBD>lparamΪ<6D><CEAA><EFBFBD>ݳ<EFBFBD><DDB3><EFBFBD>
//2<><32>lparam<61><6D>-1<>ܵ<EFBFBD><DCB5><EFBFBD><EFBFBD>ӳɹ<D3B3><C9B9><EFBFBD>-2<>ܵ<EFBFBD><DCB5>Ͽ<EFBFBD><CFBF><EFBFBD>-3<>ܵ<EFBFBD><DCB5>
void CModuleProcess::PipeCallBack(int lMsgId, WPARAM wparam, LPARAM lparam)
{
if (CEXPIPE_NEW_DATA == lMsgId)
{
PIPE_DATA_STRUCT* pPipeData = (PIPE_DATA_STRUCT*)wparam;
if (pPipeData->lDataLen + sizeof(PIPE_DATA_STRUCT) - sizeof(char[4]) != (int)lparam)
{
return ;//<2F><><EFBFBD><EFBFBD>ͨѶ<CDA8>
}
Json::Reader reader;
Json::Value root;
CString strData = "data=";
if (reader.parse(pPipeData->acData, root))
{
CString strSender = root["sender"].asString().c_str();
CString strReceiver = root["receiver"].asString().c_str();
//AGV->WMS<4D><53><EFBFBD><EFBFBD>Ϣ
if (strReceiver == "WMS")
{
CString strMsg = "<EFBFBD><EFBFBD><EFBFBD>͸<EFBFBD>WMS<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ:";
strMsg += pPipeData->acData;
m_pAgvMainWnd->AddLog2Edit(strMsg);
m_httpClent.GenericPost2Wms(strData + pPipeData->acData);
}
//AGV->OPENTCS<43><53><EFBFBD><EFBFBD>Ϣ
else if (strReceiver == "OPENTCS")
{
CString strMsg = "<EFBFBD><EFBFBD><EFBFBD>͸<EFBFBD>OPENTCS<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ:";
strMsg += pPipeData->acData;
m_pAgvMainWnd->AddLog2Edit(strMsg);
m_httpClent.GenericPost2Opentcs(strData + pPipeData->acData);
}
else //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
{
CModuleProcess *pModuleProcess = m_pAgvMainWnd->GetModuleByName(strReceiver);
if (NULL != pModuleProcess)
{
pModuleProcess->SendDataToModule(MAIN_2_MODULE_WMS, pPipeData->acData, pPipeData->lDataLen);
CString strMsg = "ת<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Plugin<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ:";
strMsg += pPipeData->acData;
m_pAgvMainWnd->AddLog2Edit(strMsg);
}
}
}
}
else if (CEXPIPE_DIS_CLIENT == lMsgId)
{
//<2F>ܵ<EFBFBD><DCB5>Ͽ<EFBFBD><CFBF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//PostMessage(WM_CLOSE, NULL, NULL);
TRACE("<EFBFBD><EFBFBD>ģ<EFBFBD><EFBFBD><EFBFBD>ѶϿ<EFBFBD>\r\n");
}
else if (CEXPIPE_NEW_CLIENT == lMsgId)
{
//<2F><><EFBFBD>ӳɹ<D3B3>
//PostMessage(WM_PIPE_CONNECT_OK, NULL, NULL);
PostMessage(m_hWnd, WM_MODULE_CONNECT_ID, (WPARAM)this, NULL);
TRACE("<EFBFBD><EFBFBD>ģ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\r\n");
}
else
{
TRACE("<EFBFBD><EFBFBD>ܵ<EFBFBD><EFBFBD><EFBFBD>Ϣ[%d]\r\n", lMsgId);
}
return;
}
void CModuleProcess::ProcessManageThr()
{
int lDelay = 3000;
for (; TRUE == m_bAcitv;)
{
m_lReStartCount++;
m_lState = 1;
PostMessage(m_hWnd, WM_UPDATE_MODULE_STATUS, NULL, NULL);
if (FALSE == StartModule())
{
//lDelay *= 2;//<2F><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD>´<EFBFBD><C2B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӳ<EFBFBD>˫<EFBFBD><CBAB>ʱ<EFBFBD><CAB1>
}
m_lState = 2;
PostMessage(m_hWnd, WM_UPDATE_MODULE_STATUS, NULL, NULL);
TRACE("<EFBFBD><EFBFBD>ģ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>˳<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӳ<EFBFBD>[%d ms]<5D><><EFBFBD><EFBFBD>\r\n", lDelay);
for (int i = 0; i < lDelay && TRUE == m_bAcitv; i+=20)
{
Sleep(20);
}
}
}
BOOL CModuleProcess::StartModule()
{
if (NULL == m_pstPipeServer)
{
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
return FALSE;
}
if (m_pstPipeServer->IsAcitve())
{
//ģ<><C4A3><EFBFBD>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD><EFBFBD>
return FALSE;
}
//Stop();
m_pstPipeServer->RegisterCall(g_PipeCallBack, this);
m_pstPipeServer->Start(m_strPipeName);
STARTUPINFO si; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̲<EFBFBD><CCB2><EFBFBD>
CString strCommend;
strCommend.Format("-u %u -pipe %s", g_ulTerminal, m_strPipeName.GetBuffer());
//<2F><EFBFBD><E1B9B9><EFBFBD><EFBFBD>
ZeroMemory(&si,sizeof(si)); //<2F>˲<EFBFBD><CBB2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
ZeroMemory(&m_pi,sizeof(m_pi)); //<2F>˲<EFBFBD><CBB2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
si.dwFlags =STARTF_USESHOWWINDOW;//<2F><><EFBFBD>ش<EFBFBD><D8B4><EFBFBD><EFBFBD>Ĵ<EFBFBD><C4B4><EFBFBD>
si.wShowWindow=SW_SHOW;//<2F><><EFBFBD>ش<EFBFBD><D8B4><EFBFBD><EFBFBD>Ĵ<EFBFBD><C4B4><EFBFBD>
//Sleep(999999999);
if(FALSE == CreateProcess(m_strModulePath.GetBuffer(), strCommend.GetBuffer(), NULL, NULL, false, 0, NULL, NULL, &si, &m_pi))
{
ZeroMemory(&m_pi,sizeof(m_pi)); //<2F>˲<EFBFBD><CBB2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
LogOutToFile("Ӧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><EFBFBD>:%s[%s]", m_strModulePath.GetBuffer(), strCommend.GetBuffer());
m_pstPipeServer->Stop();
return FALSE;
}
LogOutToFile("[info] ģ<><C4A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>[%s][%s]", m_strModulePath, strCommend.GetBuffer());
TRACE("[info] ģ<><C4A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>[%s][%s]", m_strModulePath, strCommend.GetBuffer());
//Ӧ<>÷<EFBFBD><C3B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˳<EFBFBD><CBB3><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD>Ǵ<EFBFBD><C7B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if (WAIT_OBJECT_0 != WaitForSingleObject(m_pi.hThread, INT_MAX))
{
m_pstPipeServer->Stop();
return FALSE;
}
m_pstPipeServer->Stop();
return TRUE;
}

85
Platform/ModuleProcess.h Normal file
View File

@@ -0,0 +1,85 @@
#pragma once
typedef struct MODULE_DATA
{
void* pModule;
int lMsgId;
int lDataLen;
char acData[4];
}*pMODULE_DATA;
void g_PipeCallBack(void* pObj, int lMsgId,WPARAM wparam, LPARAM lparam);
#define WM_MODULE_DATA_ID (WM_USER + 666)
#define WM_MODULE_CONNECT_ID (WM_USER + 667)
#define WM_UPDATE_MODULE_STATUS (WM_USER + 20668)
class CModuleProcess
{
friend void g_PipeCallBack(void* pObj, int lMsgId, WPARAM wparam, LPARAM lparam);
public:
//hWnd<6E>յ<EFBFBD><D5B5><EFBFBD>ģ<EFBFBD><C4A3><EFBFBD><EFBFBD>Ϣʱת<CAB1><D7AA><EFBFBD><EFBFBD>Ŀ<EFBFBD><EFBFBD>ڣ<EFBFBD>
CModuleProcess(CAgvMainDialog *pMainWnd, CString strModulePath, CString strModuleName, int lModuleIndex);
~CModuleProcess(void);
void SetPipeName(CString strPipeName) { m_strPipeName = strPipeName; }
//<2F><><EFBFBD><EFBFBD>ģ<EFBFBD><C4A3>
BOOL Start(int nDebug=0);
//ֹͣģ<D6B9><C4A3>
void Stop();
//<2F><>ȡ<EFBFBD><C8A1>ǰģ<C7B0><C4A3>״̬̫0 δ<><CEB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>1<EFBFBD><31><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
BOOL GetStatus();
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݵ<EFBFBD>ģ<EFBFBD><C4A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
BOOL SendDataToModule(int lMsgId, const char* pData, int lLen);
//<2F><><EFBFBD><EFBFBD><EFBFBD>߳<EFBFBD>
void ProcessManageThr();
CRect GetRect(){return m_rect;}
void SetRect(CRect rect){m_rect = rect;}
CString GetModulePath() { return m_strModulePath; }
CString GetModuleName() { return m_strModuleName; }
BOOL GetConnectState(){return m_bIsConnectModule;}
VOID SetConnectState(BOOL bState){m_bIsConnectModule = bState;}
CHttpClient m_httpClent;
CAgvMainDialog *m_pAgvMainWnd;
int m_lModuleIndex;
int m_nDebug;
int m_lReStartCount;
int m_lState;//0 δ<><CEB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>1<EFBFBD><31><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>2<EFBFBD>Ժ<EFBFBD><D4BA><EFBFBD><EFBFBD><EFBFBD>
protected:
//<2F><>ģ<EFBFBD><C4A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͨѶ<CDA8>Ĺܵ<C4B9><DCB5>ص<EFBFBD><D8B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//1<><31>lparam > 0ʱ<30><CAB1>wparamΪ<6D><CEAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݣ<EFBFBD>lparamΪ<6D><CEAA><EFBFBD>ݳ<EFBFBD><DDB3><EFBFBD>
//2<><32>lparam<61><6D>-1<>ܵ<EFBFBD><DCB5><EFBFBD><EFBFBD>ӳɹ<D3B3><C9B9><EFBFBD>-2<>ܵ<EFBFBD><DCB5>Ͽ<EFBFBD><CFBF><EFBFBD>-3<>ܵ<EFBFBD><DCB5>
void PipeCallBack(int lMsgId, WPARAM wparam, LPARAM lparam);
//<2F><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>Ӧ<EFBFBD>ã<EFBFBD><C3A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̵߳<DFB3><CCB5><EFBFBD>
BOOL StartModule();
private:
CString m_strModulePath;
CString m_strModuleName;
CCEXPipeServerBase* m_pstPipeServer;
HANDLE m_hProcessManageThr;
BOOL m_bAcitv;
HWND m_hWnd;
CRect m_rect;//ģ<><C4A3><EFBFBD><EFBFBD>ռ<EFBFBD>õľ<C3B5><C4BE>ο<EFBFBD>λ<EFBFBD><CEBB>
CString m_strPipeName;
PROCESS_INFORMATION m_pi; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD>
BOOL m_bIsConnectModule;
};

67
Platform/ReadMe.txt Normal file
View File

@@ -0,0 +1,67 @@
================================================================================
MICROSOFT 基础类库 : Vcs-Client 项目概述
===============================================================================
应用程序向导已为您创建了此 Vcs-Client 应用程序。此应用程序不仅演示 Microsoft 基础类的基本使用方法,还可作为您编写应用程序的起点。
本文件概要介绍组成 Vcs-Client 应用程序的每个文件的内容。
Vcs-Client.vcxproj
这是使用应用程序向导生成的 VC++ 项目的主项目文件,其中包含生成该文件的 Visual C++ 的版本信息,以及有关使用应用程序向导选择的平台、配置和项目功能的信息。
Vcs-Client.vcxproj.filters
这是使用“应用程序向导”生成的 VC++ 项目筛选器文件。它包含有关项目文件与筛选器之间的关联信息。在 IDE 中,通过这种关联,在特定节点下以分组形式显示具有相似扩展名的文件。例如,“.cpp”文件与“源文件”筛选器关联。
Vcs-Client.h
这是应用程序的主头文件。
其中包括其他项目特定的标头(包括 Resource.h并声明 CVcsClientApp 应用程序类。
Vcs-Client.cpp
这是包含应用程序类 CVcsClientApp 的主应用程序源文件。
Vcs-Client.rc
这是程序使用的所有 Microsoft Windows 资源的列表。它包括 RES 子目录中存储的图标、位图和光标。此文件可以直接在 Microsoft Visual C++ 中进行编辑。项目资源包含在 2052 中。
res\Vcs-Client.ico
这是用作应用程序图标的图标文件。此图标包括在主资源文件 Vcs-Client.rc 中。
res\VcsClient.rc2
此文件包含不在 Microsoft Visual C++ 中进行编辑的资源。您应该将不可由资源编辑器编辑的所有资源放在此文件中。
/////////////////////////////////////////////////////////////////////////////
应用程序向导创建一个对话框类:
Vcs-ClientDlg.h、Vcs-ClientDlg.cpp - 对话框
这些文件包含 CVcsClientDlg 类。此类定义应用程序的主对话框的行为。对话框模板包含在 Vcs-Client.rc 中,该文件可以在 Microsoft Visual C++ 中编辑。
/////////////////////////////////////////////////////////////////////////////
其他功能:
ActiveX 控件
该应用程序包含对使用 ActiveX 控件的支持。
/////////////////////////////////////////////////////////////////////////////
其他标准文件:
StdAfx.h, StdAfx.cpp
这些文件用于生成名为 Vcs-Client.pch 的预编译头 (PCH) 文件和名为 StdAfx.obj 的预编译类型文件。
Resource.h
这是标准头文件,可用于定义新的资源 ID。Microsoft Visual C++ 将读取并更新此文件。
Vcs-Client.manifest
Windows XP 使用应用程序清单文件来描述特定版本的并行程序集的应用程序依赖项。加载程序使用这些信息来从程序集缓存中加载相应的程序集,并保护其不被应用程序访问。应用程序清单可能会包含在内,以作为与应用程序可执行文件安装在同一文件夹中的外部 .manifest 文件进行重新分发,它还可能以资源的形式包含在可执行文件中。
/////////////////////////////////////////////////////////////////////////////
其他注释:
应用程序向导使用“TODO:”来指示应添加或自定义的源代码部分。
如果应用程序使用共享 DLL 中的 MFC您将需要重新分发 MFC DLL。如果应用程序所使用的语言与操作系统的区域设置不同则还需要重新分发相应的本地化资源 mfc110XXX.DLL。
有关上述话题的更多信息,请参见 MSDN 文档中有关重新分发 Visual C++ 应用程序的部分。
/////////////////////////////////////////////////////////////////////////////

BIN
Platform/res/Agv.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

BIN
Platform/res/Agv.rc2 Normal file

Binary file not shown.

BIN
Platform/resource.h Normal file

Binary file not shown.

95
Platform/stdafx.cpp Normal file
View File

@@ -0,0 +1,95 @@
// stdafx.cpp : ֻ<><D6BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>׼<EFBFBD><D7BC><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>Դ<EFBFBD>ļ<EFBFBD>
// Vcs-Client.pch <20><><EFBFBD><EFBFBD>ΪԤ<CEAA><D4A4><EFBFBD><EFBFBD>ͷ
// stdafx.obj <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ԥ<EFBFBD><D4A4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
#include "stdafx.h"
#define MIN_XYZ_VALUE (-999999)
float* g_xys = new float[3000 * 3000 * 2];
int g_xyz_flag = 0;
#define Q_R 1500
#define X0 1500
#define Y0 1500
inline float abs_m(float lf)
{
if (lf < 0) lf *= -1;
return lf;
}
CString g_strSavePath = "";
CString g_strCurTime = "";
void LogOutToFile(const char* fmt, ...)
{
static CRITICAL_SECTION stCritical;
static BOOL bInit = FALSE;
static CString strLogPath;
if (FALSE == bInit)
{
bInit = TRUE;
GetModuleFileName(NULL, strLogPath.GetBuffer(2048), 2047);
strLogPath.ReleaseBuffer();
strLogPath = strLogPath.Left(strLogPath.ReverseFind('\\'));
strLogPath += "\\log\\runtime.log";
InitializeCriticalSection(&stCritical);
}
EnterCriticalSection(&stCritical);
va_list ap;
va_start(ap, fmt);
char pBuffer[800] = "";
if (vsnprintf_s(pBuffer, 796, _TRUNCATE, fmt, ap) > 0)
{
if (strlen(pBuffer) == 0 || pBuffer[strlen(pBuffer) - 1] != '\n')
{
pBuffer[strlen(pBuffer) + 1] = '\0';//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>׷<EFBFBD><D7B7>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊԭ<CEAA><D4AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD>޸<EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD>з<EFBFBD>
pBuffer[strlen(pBuffer)] = '\n';
}
}
va_end(ap);
TRACE("%s\n", pBuffer);
FILE* pFile = NULL;
fopen_s(&pFile, strLogPath.GetBuffer(), "ab+");
if (NULL != pFile)
{
char acTime[32] = { 0 };
SYSTEMTIME stTime;
GetLocalTime(&stTime);
sprintf_s(acTime, 32, "[%02d-%02d %02d:%02d:%02d.%03d] ", stTime.wMonth, stTime.wDay, stTime.wHour, stTime.wMinute, stTime.wSecond, stTime.wMilliseconds);
fwrite(acTime, 1, strlen(acTime), pFile);
fwrite(pBuffer, 1, strlen(pBuffer), pFile);
fwrite("\r\n", 1, strlen("\r\n"), pFile);
fclose(pFile);
}
LeaveCriticalSection(&stCritical);
}
int g_nMsgIdx = 998;
string _UnicodeToUtf8(CString Unicodestr)
{
wchar_t* unicode = Unicodestr.AllocSysString();
int len;
len = WideCharToMultiByte(CP_UTF8, 0, unicode, -1, NULL, 0, NULL, NULL);
char *szUtf8 = (char*)malloc(len + 1);
memset(szUtf8, 0, len + 1);
WideCharToMultiByte(CP_UTF8, 0, unicode, -1, szUtf8, len, NULL, NULL);
string result = szUtf8;
free(szUtf8);
return result;
}

62
Platform/stdafx.h Normal file
View File

@@ -0,0 +1,62 @@
// stdafx.h : <20><>׼ϵͳ<CFB5><CDB3><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC>İ<EFBFBD><C4B0><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>
// <20><><EFBFBD>Ǿ<EFBFBD><C7BE><EFBFBD>ʹ<EFBFBD>õ<EFBFBD><C3B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ĵ<EFBFBD>
// <20>ض<EFBFBD><D8B6><EFBFBD><EFBFBD><EFBFBD>Ŀ<EFBFBD>İ<EFBFBD><C4B0><EFBFBD><EFBFBD>ļ<EFBFBD>
#pragma once
#ifndef VC_EXTRALEAN
#define VC_EXTRALEAN // <20><> Windows ͷ<><CDB7><EFBFBD>ų<EFBFBD><C5B3><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD>õ<EFBFBD><C3B5><EFBFBD><EFBFBD><EFBFBD>
#endif
#include "targetver.h"
#define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS // ijЩ CString <20><><EFBFBD><EFBFBD><ECBAAF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ<EFBFBD><CABD>
// <20>ر<EFBFBD> MFC <20><>ijЩ<C4B3><D0A9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɷ<EFBFBD><C9B7>ĺ<EFBFBD><C4BA>Եľ<D4B5><C4BE><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
#define _AFX_ALL_WARNINGS
#include <afxwin.h> // MFC <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͱ<EFBFBD>׼<EFBFBD><D7BC><EFBFBD><EFBFBD>
#include <afxext.h> // MFC <20><>չ
#include <afxdisp.h> // MFC <20>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD>
#include "HttpService.h"
#include "HttpClient.h"
#include "CCEXPipeLib.h"
#ifndef _AFX_NO_OLE_SUPPORT
#include <afxdtctl.h> // MFC <20><> Internet Explorer 4 <20><><EFBFBD><EFBFBD><EFBFBD>ؼ<EFBFBD><D8BC><EFBFBD>֧<EFBFBD><D6A7>
#endif
#ifndef _AFX_NO_AFXCMN_SUPPORT
#include <afxcmn.h> // MFC <20><> Windows <20><><EFBFBD><EFBFBD><EFBFBD>ؼ<EFBFBD><D8BC><EFBFBD>֧<EFBFBD><D6A7>
#endif // _AFX_NO_AFXCMN_SUPPORT
#include "json.h"
#include <queue>
using namespace std;
#include <afxcontrolbars.h> // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϳؼ<CDBF><D8BC><EFBFBD><EFBFBD><EFBFBD> MFC ֧<><D6A7>
#ifdef _UNICODE
#if defined _M_IX86
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' language='*'\"")
#elif defined _M_X64
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='amd64' publicKeyToken='6595b64144ccf1df' language='*'\"")
#else
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
#endif
#endif
extern CString g_strSavePath;
extern CString g_strCurTime;
extern int g_nMsgIdx;
void LogOutToFile(const char* fmt, ...);
string _UnicodeToUtf8(CString Unicodestr);

8
Platform/targetver.h Normal file
View File

@@ -0,0 +1,8 @@
#pragma once
// <20><><EFBFBD><EFBFBD> SDKDDKVer.h <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD><C3B5><EFBFBD><EFBFBD>߰汾<DFB0><E6B1BE> Windows ƽ̨<C6BD><CCA8>
// <20><><EFBFBD><EFBFBD>ҪΪ<D2AA><CEAA>ǰ<EFBFBD><C7B0> Windows ƽ̨<C6BD><CCA8><EFBFBD><EFBFBD>Ӧ<EFBFBD>ó<EFBFBD><C3B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> WinSDKVer.h<><68><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// <20><> _WIN32_WINNT <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ΪҪ֧<D2AA>ֵ<EFBFBD>ƽ̨<C6BD><CCA8>Ȼ<EFBFBD><C8BB><EFBFBD>ٰ<EFBFBD><D9B0><EFBFBD> SDKDDKVer.h<><68>
#include <SDKDDKVer.h>

135
Platform/util.cpp Normal file
View File

@@ -0,0 +1,135 @@
#include "util.h"
#include <iostream>
#include <locale>
#include <codecvt>
Uitil::Uitil()
{
}
std::wstring Uitil::stringToWString(const std::string &string)
{
std::wstring_convert<std::codecvt_utf8<wchar_t>> cv;
return cv.from_bytes(string);
}
HANDLE Uitil::getCurrentUserToken()
{
// 查询sessionID
PWTS_SESSION_INFO pSessionInfo = 0;
DWORD dwCount = 0;
::WTSEnumerateSessions(WTS_CURRENT_SERVER_HANDLE, 0, 1, &pSessionInfo, &dwCount);
int session_id = 0;
for (DWORD i = 0; i < dwCount; ++i)
{
WTS_SESSION_INFO si = pSessionInfo[i];
if (WTSActive == si.State)
{
session_id = si.SessionId;
break;
}
}
::WTSFreeMemory(pSessionInfo);
// 查询token
HANDLE current_token = 0;
BOOL bRet = ::WTSQueryUserToken(session_id, &current_token);
if (bRet == FALSE)
{
std::cout << "WTSQueryUserToken error, code:" << GetLastError() << std::endl;
return nullptr;
}
HANDLE primaryToken = 0;
bRet = ::DuplicateTokenEx(current_token, TOKEN_ASSIGN_PRIMARY | TOKEN_ALL_ACCESS, 0, SecurityImpersonation, TokenPrimary, &primaryToken);
::CloseHandle(current_token);
if (bRet == FALSE)
{
std::cout << "DuplicateTokenEx error, code:" << GetLastError() << std::endl;
return nullptr;
}
return primaryToken;
}
bool Uitil::runProgAsCurUser(HANDLE token, const std::string &progPath, const std::string &progArgs)
{
STARTUPINFO StartupInfo = {0};
PROCESS_INFORMATION processInfo;
StartupInfo.cb = sizeof(STARTUPINFO);
auto command = std::string("\"") + progPath + "\"";
if (!progArgs.empty())
{
command += " " + progArgs;
}
void* lpEnvironment = NULL;
BOOL resultEnv = ::CreateEnvironmentBlock(&lpEnvironment, token, FALSE);
if (!resultEnv)
{
std::cout << "CreateEnvironmentBlock error, code:" << GetLastError() << std::endl;
return false;
}
std::cout << "runProgAsCurUser, command:" << command << std::endl;
// 获取到的hUnfilteredToken就是不受限的token以token作为CreateProcessAsUser的第一个参数就可以创建出具有管理员权限并且属于当前用户的界面程序了并且这种情况下不需要加入窗口站。
BOOL result = ::CreateProcessAsUser(token, 0, (LPSTR)(progPath.c_str()), NULL, NULL, FALSE, CREATE_NEW_CONSOLE | NORMAL_PRIORITY_CLASS | CREATE_UNICODE_ENVIRONMENT, lpEnvironment, 0, &StartupInfo, &processInfo);
if(!result)
{
std::cout << "CreateProcessAsUser error, code:" << GetLastError() << std::endl;
return false;
}
if(lpEnvironment != NULL)
{
::DestroyEnvironmentBlock(lpEnvironment);
}
return true;
}
bool Uitil::RunProgAsCurUserAdminPrivilege(const std::string &progPath, const std::string &progArgs)
{
// UAC开启时当前用户拥有两个token分别是受限的token和不受限的token。explorer.exe进程的token就属于受限的token。
// 在服务程序中可以用下面代码获取到受限的token。
HANDLE primaryToken = getCurrentUserToken();
if (primaryToken == 0)
{
std::cout << "GetCurrentUserToken error." << std::endl;
return false;
}
// 由此token可以得到不受限的token
bool isOpenOk = false;
HANDLE hUnfilteredToken = NULL;
DWORD dwSize = 0;
BOOL bRet = ::GetTokenInformation(primaryToken, TokenLinkedToken, (VOID*)&hUnfilteredToken, sizeof(HANDLE), &dwSize);
if (bRet)
{
isOpenOk = runProgAsCurUser(hUnfilteredToken, progPath, progArgs);
::CloseHandle(hUnfilteredToken);
}
else
{
// UAC未开时继续使用原来的token打开
std::cout << "GetTokenInformation error and continue open width primary token. code:" << GetLastError() << std::endl;
isOpenOk = runProgAsCurUser(primaryToken, progPath, progArgs);
}
::CloseHandle(primaryToken);
return isOpenOk;
}

30
Platform/util.h Normal file
View File

@@ -0,0 +1,30 @@
#ifndef UITIL_H
#define UITIL_H
#ifdef WIN32
#include <Windows.h>
#include <wingdi.h>
#include <tlhelp32.h>
#include <WinUser.h>
#include <wtsapi32.h>
#include <UserEnv.h>
#endif
#include <string>
class Uitil
{
public:
Uitil();
static std::wstring stringToWString(const std::string &string);
static HANDLE getCurrentUserToken();
static bool runProgAsCurUser(HANDLE token, const std::string &progPath, const std::string &progArgs);
static bool RunProgAsCurUserAdminPrivilege(const std::string &progPath, const std::string &progArgs);
};
#endif // UITIL_H