Skip to content

Commit

Permalink
version: 0.0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
au-top committed Nov 4, 2022
1 parent 9302a58 commit 0e1afe4
Show file tree
Hide file tree
Showing 32 changed files with 73 additions and 796 deletions.
20 changes: 5 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,18 @@
use service mode running dart to windows

`service_base` from <https://github.com/tromgy/service-base> provides windows api => lib

|

v
> in `dart_windows_service_support`
`WindowsServiceDLL` Import the api in lib and package the API => dll

|

v

`dart_windows_service_support` use `dart:ffi` access dll api

## Example

example global var

```dart
final dllPath = join(Directory.current.path, "../../../dll/WindowsServiceDLL.dll");
final dllPath = join(Directory.current.path, "../../../dll/WindowsServiceDLL64.dll");
const serviceName = "dartTestService";
```

Expand All @@ -44,9 +37,10 @@ void main(List<String> args) {
/// path
servicePath.toNativeUtf16().cast<Uint16>(),
true,
1,
1,
Pointer.fromAddress(0),
1
);
}
```
Expand Down Expand Up @@ -84,11 +78,7 @@ See `dart_windows_service_support/example`

## Make dll `WindowsServiceDLL.dll`

1. use VS2022 open `windows_platform\service_base` make project out `service-base.lib` file

2. move `service-base.lib` to `windows_platform\WindowsServiceDLL\lib\service-base.lib`

3. open project `windows_platform\WindowsServiceDLL` make out `WindowsServiceDLL.dll`
use VS2022 open project `windows_platform\WindowsServiceDLL` make out `WindowsServiceDLL.dll`

> Complete the compilation of dll
>
Expand Down
6 changes: 6 additions & 0 deletions dart_windows_service_support/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@

# 0.0.3

feat: add delayed start option

fix: use dart int to BOOL(int)

# 0.0.2

fix: export dartUninstallService from dll
5 changes: 3 additions & 2 deletions dart_windows_service_support/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
example global var

```dart
final dllPath = join(Directory.current.path, "../../../dll/WindowsServiceDLL.dll");
final dllPath = join(Directory.current.path, "../../../dll/WindowsServiceDLL64.dll");
const serviceName = "dartTestService";
```

Expand All @@ -32,9 +32,10 @@ void main(List<String> args) {
/// path
servicePath.toNativeUtf16().cast<Uint16>(),
true,
1,
1,
Pointer.fromAddress(0),
1
);
}
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ void main(List<String> args) {

/// path
servicePath.toNativeUtf16().cast<Uint16>(),
true,
1,
1,
Pointer.fromAddress(0),
1,
);
}
6 changes: 4 additions & 2 deletions dart_windows_service_support/example/lib/define.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@ import 'dart:io';

import 'package:path/path.dart';

final dllPath = normalize(join(dirname(Platform.script.toFilePath()), "../../../dll/WindowsServiceDLL.dll"));
const serviceName = "dartTestService";
/// WindowsServiceDLL64 is x64
/// WindowsServiceDLL is x86
final dllPath = normalize(join(dirname(Platform.script.toFilePath()), "../../../dll/WindowsServiceDLL64.dll"));
const serviceName = "dart_test_service";
6 changes: 4 additions & 2 deletions dart_windows_service_support/lib/src/load_lib.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ typedef CDartInstallService = ffi.Void Function(
PCWSTR pszAccount,
PCWSTR pszPassword,
PCWSTR serviceCallPath,
ffi.Bool bRegisterWithEventLog,
ffi.Int bRegisterWithEventLog,
DWORD dwNumMessageCategories,
PCWSTR pszMessageResourceFilePath,
ffi.Int delayedStart,
);

typedef DartInstallService = void Function(
Expand All @@ -28,9 +29,10 @@ typedef DartInstallService = void Function(
PCWSTR pszAccount,
PCWSTR pszPassword,
PCWSTR serviceCallPath,
bool bRegisterWithEventLog,
int bRegisterWithEventLog,
int dwNumMessageCategories,
PCWSTR pszMessageResourceFilePath,
int delayedStart,
);

typedef CDartConnectService = ffi.Void Function(PCWSTR);
Expand Down
2 changes: 1 addition & 1 deletion dart_windows_service_support/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: dart_windows_service_support
description: Support running dart as a Windows service
version: 0.0.2
version: 0.0.3
repository: https://github.com/au-top/dart_windows_service

environment:
Expand Down
3 changes: 0 additions & 3 deletions windows_platform/.vs/ProjectSettings.json

This file was deleted.

7 changes: 0 additions & 7 deletions windows_platform/.vs/VSWorkspaceState.json

This file was deleted.

Binary file removed windows_platform/.vs/slnx.sqlite
Binary file not shown.
Binary file not shown.
Empty file.
Binary file removed windows_platform/.vs/windows_platform/v17/.suo
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,10 @@
* WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
\***************************************************************************/

#pragma region Includes
#include <assert.h>
#include <strsafe.h>

#include "pch.h"
#include "ServiceBase.h"
#pragma endregion


#pragma region Static Members

// Initialize the singleton service instance.
CServiceBase *CServiceBase::s_service = NULL;
Expand Down Expand Up @@ -628,4 +623,3 @@ void CServiceBase::WriteErrorLogEntry(PCWSTR pszFunction, DWORD dwError)
WriteLogEntry(szMessage, EVENTLOG_ERROR_TYPE, m_dwErrorEventId, m_wErrorCategoryId);
}

#pragma endregion
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@
* WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
\***************************************************************************/

#pragma region "Includes"
#include "ServiceInstaller.h"
#pragma endregion
#include "pch.h"

//
// FUNCTION: InstallService
Expand Down Expand Up @@ -52,7 +51,8 @@ void InstallService(PCWSTR pszServiceName,
PCWSTR serviceCallPath,
BOOL bRegisterWithEventLog,
DWORD dwNumMessageCategories,
PCWSTR pszMessageResourceFilePath
PCWSTR pszMessageResourceFilePath,
BOOL delayedStart
)
{
wchar_t wszPath[MAX_PATH];
Expand Down Expand Up @@ -95,6 +95,7 @@ void InstallService(PCWSTR pszServiceName,
{
// Add service description
SERVICE_DESCRIPTION sd;

wchar_t wszDesc[1024];

wcsncpy_s(wszDesc, _countof(wszDesc), pszDescription, _TRUNCATE);
Expand All @@ -107,6 +108,16 @@ void InstallService(PCWSTR pszServiceName,
goto Cleanup;
}

if (delayedStart) {
SERVICE_DELAYED_AUTO_START_INFO sdasi = { delayedStart };
if (!ChangeServiceConfig2(schService, SERVICE_CONFIG_DELAYED_AUTO_START_INFO, &sdasi))
{
wprintf(L"Couldn't set service delayed auto start with error code: 0x%08lx\n", GetLastError());
goto Cleanup;
}

}

// Register service with event logger (optional)
if (bRegisterWithEventLog)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ void InstallService(PCWSTR pszServiceName,
PCWSTR serviceCallPath,
BOOL bRegisterWithEventLog = TRUE,
DWORD dwNumMessageCategories = 0,
PCWSTR pszMessageResourceFilePath = NULL
PCWSTR pszMessageResourceFilePath = NULL,
BOOL delayedStart = FALSE
);

//
Expand Down
14 changes: 10 additions & 4 deletions windows_platform/WindowsServiceDLL/WindowsServiceDLL.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
<ConformanceMode>true</ConformanceMode>
<PrecompiledHeader>Use</PrecompiledHeader>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<AdditionalIncludeDirectories>;$(SolutionDir)includes\</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
</ClCompile>
<Link>
Expand All @@ -109,7 +109,8 @@
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableUAC>false</EnableUAC>
<AdditionalDependencies>%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>$(ProjectDir)lib;</AdditionalLibraryDirectories>
<AdditionalLibraryDirectories>
</AdditionalLibraryDirectories>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
Expand Down Expand Up @@ -141,7 +142,7 @@
<ConformanceMode>true</ConformanceMode>
<PrecompiledHeader>Use</PrecompiledHeader>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<AdditionalIncludeDirectories>$(ProjectDir)includes;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
</ClCompile>
<Link>
Expand All @@ -150,7 +151,8 @@
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableUAC>false</EnableUAC>
<AdditionalLibraryDirectories>$(ProjectDir)lib;C:\Users\autop\source\repos\WindowsServiceDLL\lib</AdditionalLibraryDirectories>
<AdditionalLibraryDirectories>
</AdditionalLibraryDirectories>
<AdditionalDependencies>%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
Expand All @@ -159,6 +161,8 @@
<ClInclude Include="exportWindowsServiceDLLApi.h" />
<ClInclude Include="framework.h" />
<ClInclude Include="pch.h" />
<ClInclude Include="ServiceBase.h" />
<ClInclude Include="ServiceInstaller.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="BaseWindowsService.cpp" />
Expand All @@ -169,6 +173,8 @@
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader>
</ClCompile>
<ClCompile Include="ServiceBase.cpp" />
<ClCompile Include="ServiceInstaller.cpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@
<ClInclude Include="exportWindowsServiceDLLApi.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="ServiceBase.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="ServiceInstaller.h">
<Filter>头文件</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="exportWindowsServiceDLLApi.cpp">
Expand All @@ -38,5 +44,11 @@
<ClCompile Include="BaseWindowsService.cpp">
<Filter>源文件</Filter>
</ClCompile>
<ClCompile Include="ServiceBase.cpp">
<Filter>源文件</Filter>
</ClCompile>
<ClCompile Include="ServiceInstaller.cpp">
<Filter>源文件</Filter>
</ClCompile>
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ extern "C" void DartInstallService(PCWSTR pszServiceName,
PCWSTR serviceCallPath,
BOOL bRegisterWithEventLog,
DWORD dwNumMessageCategories,
PCWSTR pszMessageResourceFilePath
PCWSTR pszMessageResourceFilePath,
BOOL delayedStart
) {

InstallService(pszServiceName,
Expand All @@ -29,7 +30,8 @@ extern "C" void DartInstallService(PCWSTR pszServiceName,
serviceCallPath,
bRegisterWithEventLog,
dwNumMessageCategories,
pszMessageResourceFilePath
pszMessageResourceFilePath,
delayedStart
);

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ extern "C" __declspec(dllexport) void DartInstallService(PCWSTR pszServiceName,
PCWSTR serviceCallPath,
BOOL bRegisterWithEventLog,
DWORD dwNumMessageCategories,
PCWSTR pszMessageResourceFilePath
PCWSTR pszMessageResourceFilePath,
BOOL delayedStart
);

extern "C" __declspec(dllexport) void DartConnectService(
Expand Down
Loading

0 comments on commit 0e1afe4

Please sign in to comment.