C++ Programm auf einen Dienst umstellen - Probleme
-
Hallo,
ich habe eine funktionierendes C++ File, inklusive Headerfile. Dieses will ich jetzt auf einen Windows Dienst umstellen. Hab dazu ein neues Projekt C++ Windows Dienst erstellt.
In der UPSServiceWinService.h habe ich mein Header File inkludiert und bei den 2 Einsprüngen Start und Stop rufe ich die Start bzw. Stop Funktion meiner C++ Datei auf.Auszug meiner Änderung:
#include "BrAdiUpsSvc.h" virtual void OnStart(array<String^>^ args) override { // TODO: Add code here to start your service. Start(); } /// <summary> /// Stop this service. /// </summary> virtual void OnStop() override { // TODO: Add code here to perform any tear-down necessary to stop your service. Stop(); }
Headerfile:
extern bool Start(void); extern bool Stop(void);
Funktionen im C++ File
bool InitFunctionpointers(void); bool DrvInit(void); void DrvStop(void); bool DrvUPSState(DWORD &State); bool DrvWaitForStateChange(DWORD aCurrentState, DWORD anInterval); void DrvCancelWait(void); bool ShutdownOnBatteryEnabled(DWORD &ShutdownOnBatteryEnable, DWORD &ShutdownOnBatteryWait); void DrvTurnOff(void); void DrvUPSTurnOff(DWORD time); bool CreateShutdown(DWORD time); unsigned WINAPI UPSThread (void* n); unsigned WINAPI WaitThread (void* n); void SetShutdown(void);
Bekomm dann beim Compilieren folgenden Fehler:
error C3641: 'UPSThread' : invalid calling convention '__stdcall ' for function compiled with /clr:pure or /clr:safeHab daraufhin meine Threads auf __clrcall umgestellt:
unsigned __clrcall UPSThread (void* n); unsigned __clrcall WaitThread (void* n);
Nach dem Compilieren folgende neue Fehler:
1>BrAdiUpsSvc.obj : error LNK2028: unresolved token (0A00000B) "extern "C" int __stdcall InitiateSystemShutdownExW(wchar_t *,wchar_t *,unsigned long,int,int,unsigned long)" (?InitiateSystemShutdownExW@@$$J224YGHPA_W0KHHK@Z) referenced in function "void clrcall SetShutdown(void)" (?SetShutdown@@$$FYMXXZ)
1>BrAdiUpsSvc.obj : error LNK2028: unresolved token (0A00000C) "extern "C" int __stdcall AdjustTokenPrivileges(void *,int,struct _TOKEN_PRIVILEGES *,unsigned long,struct _TOKEN_PRIVILEGES *,unsigned long *)" (?AdjustTokenPrivileges@@$$J224YGHPAXHPAU_TOKEN_PRIVILEGES@@K1PAK@Z) referenced in function "void __clrcall SetShutdown(void)" (?SetShutdown@@$$FYMXXZ)
1>BrAdiUpsSvc.obj : error LNK2028: unresolved token (0A00000D) "extern "C" int __stdcall LookupPrivilegeValueW(wchar_t const *,wchar_t const *,struct _LUID *)" (?LookupPrivilegeValueW@@$$J212YGHPB_W0PAU_LUID@@@Z) referenced in function "void clrcall SetShutdown(void)" (?SetShutdown@@$$FYMXXZ)
1>BrAdiUpsSvc.obj : error LNK2028: unresolved token (0A00000F) "extern "C" int __stdcall OpenProcessToken(void *,unsigned long,void * *)" (?OpenProcessToken@@$$J212YGHPAXKPAPAX@Z) referenced in function "void __clrcall SetShutdown(void)" (?SetShutdown@@$$FYMXXZ)
1>BrAdiUpsSvc.obj : error LNK2028: unresolved token (0A000013) "extern "C" long __stdcall RegCloseKey(struct HKEY__ *)" (?RegCloseKey@@$$J14YGJPAUHKEY@@@Z) referenced in function "bool __clrcall ShutdownOnBatteryEnabled(unsigned long &,unsigned long &)" (?ShutdownOnBatteryEnabled@@$$FYM_NAAK0@Z)
1>BrAdiUpsSvc.obj : error LNK2028: unresolved token (0A000014) "extern "C" long __stdcall RegQueryValueExW(struct HKEY__ *,wchar_t const *,unsigned long *,unsigned long *,unsigned char *,unsigned long *)" (?RegQueryValueExW@@$$J224YGJPAUHKEY__@@PB_WPAK2PAE2@Z) referenced in function "bool __clrcall ShutdownOnBatteryEnabled(unsigned long &,unsigned long &)" (?ShutdownOnBatteryEnabled@@$$FYM_NAAK0@Z)
1>BrAdiUpsSvc.obj : error LNK2028: unresolved token (0A000015) "extern "C" long __stdcall RegOpenKeyExW(struct HKEY__ *,wchar_t const *,unsigned long,unsigned long,struct HKEY__ * *)" (?RegOpenKeyExW@@$$J220YGJPAUHKEY@@PB_WKKPAPAU1@@Z) referenced in function "bool __clrcall ShutdownOnBatteryEnabled(unsigned long &,unsigned long &)" (?ShutdownOnBatteryEnabled@@$$FYM_NAAK0@Z)
1>BrAdiUpsSvc.obj : error LNK2019: unresolved external symbol "extern "C" long __stdcall RegCloseKey(struct HKEY__ *)" (?RegCloseKey@@$$J14YGJPAUHKEY__@@@Z) referenced in function "bool __clrcall ShutdownOnBatteryEnabled(unsigned long &,unsigned long &)" (?ShutdownOnBatteryEnabled@@$$FYM_NAAK0@Z)
1>BrAdiUpsSvc.obj : error LNK2019: unresolved external symbol "extern "C" long __stdcall RegQueryValueExW(struct HKEY__ *,wchar_t const *,unsigned long *,unsigned long *,unsigned char *,unsigned long *)" (?RegQueryValueExW@@$$J224YGJPAUHKEY__@@PB_WPAK2PAE2@Z) referenced in function "bool __clrcall ShutdownOnBatteryEnabled(unsigned long &,unsigned long &)" (?ShutdownOnBatteryEnabled@@$$FYM_NAAK0@Z)
1>BrAdiUpsSvc.obj : error LNK2019: unresolved external symbol "extern "C" long __stdcall RegOpenKeyExW(struct HKEY__ *,wchar_t const *,unsigned long,unsigned long,struct HKEY__ * *)" (?RegOpenKeyExW@@$$J220YGJPAUHKEY__@@PB_WKKPAPAU1@@Z) referenced in function "bool __clrcall ShutdownOnBatteryEnabled(unsigned long &,unsigned long &)" (?ShutdownOnBatteryEnabled@@$$FYM_NAAK0@Z)
1>BrAdiUpsSvc.obj : error LNK2019: unresolved external symbol "extern "C" int __stdcall InitiateSystemShutdownExW(wchar_t *,wchar_t *,unsigned long,int,int,unsigned long)" (?InitiateSystemShutdownExW@@$$J224YGHPA_W0KHHK@Z) referenced in function "void __clrcall SetShutdown(void)" (?SetShutdown@@$$FYMXXZ)
1>BrAdiUpsSvc.obj : error LNK2019: unresolved external symbol "extern "C" int __stdcall AdjustTokenPrivileges(void *,int,struct _TOKEN_PRIVILEGES *,unsigned long,struct _TOKEN_PRIVILEGES *,unsigned long *)" (?AdjustTokenPrivileges@@$$J224YGHPAXHPAU_TOKEN_PRIVILEGES@@K1PAK@Z) referenced in function "void __clrcall SetShutdown(void)" (?SetShutdown@@$$FYMXXZ)
1>BrAdiUpsSvc.obj : error LNK2019: unresolved external symbol "extern "C" int __stdcall LookupPrivilegeValueW(wchar_t const *,wchar_t const *,struct _LUID *)" (?LookupPrivilegeValueW@@$$J212YGHPB_W0PAU_LUID@@@Z) referenced in function "void __clrcall SetShutdown(void)" (?SetShutdown@@$$FYMXXZ)
1>BrAdiUpsSvc.obj : error LNK2019: unresolved external symbol "extern "C" int __stdcall OpenProcessToken(void *,unsigned long,void * *)" (?OpenProcessToken@@$$J212YGHPAXKPAPAX@Z) referenced in function "void __clrcall SetShutdown(void)" (?SetShutdown@@$$FYMXXZ)Kann mir jemand sagen, was dem Linker stört bzw. was ich bei einem Windows Dienst anders machen muss?
Vielen Dank im Voraus!
-
#pragma comment(lib, "Advapi32.lib")
-
Hallo,
vielen Dank, die Lib hat wirklich gefehlt. Wieso wird diese im eigentlich C++ Programm geladen und der Dienst "vergisst" drauf?