api: port nci package from wireguard-go
Signed-off-by: Simon Rozman <simon@rozman.si>
This commit is contained in:
parent
6f55786c65
commit
3fa45fec71
@ -17,9 +17,11 @@ DllMain(_In_ HINSTANCE hinstDLL, _In_ DWORD fdwReason, _In_ LPVOID lpvReserved)
|
||||
case DLL_PROCESS_ATTACH:
|
||||
ResourceModule = hinstDLL;
|
||||
NamespaceInit();
|
||||
NciInit();
|
||||
break;
|
||||
|
||||
case DLL_PROCESS_DETACH:
|
||||
NciCleanup();
|
||||
NamespaceCleanup();
|
||||
break;
|
||||
}
|
||||
|
15
api/api.h
15
api/api.h
@ -21,3 +21,18 @@ NamespaceInit();
|
||||
|
||||
void
|
||||
NamespaceCleanup();
|
||||
|
||||
_Return_type_success_(return ==
|
||||
0) extern DWORD(WINAPI *NciSetConnectionName)(_In_ LPCGUID Guid, _In_z_ LPCWSTR NewName);
|
||||
|
||||
_Return_type_success_(return == 0) extern DWORD(WINAPI *NciGetConnectionName)(
|
||||
_In_ LPCGUID Guid,
|
||||
_Out_z_bytecap_(InDestNameBytes) LPWSTR Name,
|
||||
_In_ DWORD InDestNameBytes,
|
||||
_Out_opt_ DWORD *OutDestNameBytes);
|
||||
|
||||
void
|
||||
NciInit();
|
||||
|
||||
void
|
||||
NciCleanup();
|
||||
|
@ -160,6 +160,7 @@
|
||||
<ItemGroup>
|
||||
<ClCompile Include="api.c" />
|
||||
<ClCompile Include="namespace.c" />
|
||||
<ClCompile Include="nci.c" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
|
@ -36,5 +36,8 @@
|
||||
<ClCompile Include="namespace.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="nci.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
</Project>
|
33
api/nci.c
Normal file
33
api/nci.c
Normal file
@ -0,0 +1,33 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0
|
||||
*
|
||||
* Copyright (C) 2018-2020 WireGuard LLC. All Rights Reserved.
|
||||
*/
|
||||
|
||||
#include "api.h"
|
||||
|
||||
static HMODULE NciModule;
|
||||
|
||||
_Return_type_success_(return == 0) DWORD (WINAPI *NciSetConnectionName)(_In_ LPCGUID Guid, _In_z_ LPCWSTR NewName);
|
||||
|
||||
_Return_type_success_(return == 0) DWORD (WINAPI *NciGetConnectionName)(
|
||||
_In_ LPCGUID Guid,
|
||||
_Out_z_bytecap_(InDestNameBytes) LPWSTR Name,
|
||||
_In_ DWORD InDestNameBytes,
|
||||
_Out_opt_ DWORD *OutDestNameBytes);
|
||||
|
||||
void
|
||||
NciInit()
|
||||
{
|
||||
NciModule = LoadLibraryW(L"nci.dll");
|
||||
if (!NciModule)
|
||||
return;
|
||||
NciSetConnectionName = (DWORD (WINAPI *)(LPCGUID, LPCWSTR))GetProcAddress(NciModule, "NciSetConnectionName");
|
||||
NciGetConnectionName = (DWORD (WINAPI *)(LPCGUID, LPWSTR, DWORD, DWORD *))GetProcAddress(NciModule, "NciGetConnectionName");
|
||||
}
|
||||
|
||||
void
|
||||
NciCleanup()
|
||||
{
|
||||
if (NciModule)
|
||||
FreeLibrary(NciModule);
|
||||
}
|
Loading…
Reference in New Issue
Block a user