alex yi
alex yi

Reputation: 11

C++ Compiling windows service with visual studio

hope you could help me. I got a C++ source for my service based on Microsoft example, still i get linker error compiling it:

error LNK2019: unresolved external symbol _main referenced in function "int __cdecl invoke_main(void)" (?invoke_main@@YAHXZ)

as the entry point for windows services is int _tmain(int argc, TCHAR* argv[])

In my case it's void __cdecl _tmain(int argc, TCHAR* argv[]) { ... }

There are 1 header and 1 cpp files with a class used by the service and main.cpp contaning entry point and c style service related code. Subsystem is console without any custom entry point set. Still if i add classic int main(...) to the code project compiles yet the service does not start from windows service manager returning error.

Please advise how to compile this using _tmain.

Upvotes: 0

Views: 243

Answers (1)

alex yi
alex yi

Reputation: 11

Ok, still no luck with _tmain. Unfortunately i haven't tried to define WINAPI WinMain entry point.

Still if you proceed with wmain program entry point and add code mentioned by Richard Critten for a service startup SCManager performs just fine. For a complete service sample refer to MS doc.wmain will force you to use Unicode yet it shouldn't be such a problem in 2020.

Subsystem should be set as supposed to your needs and no need to set custom entry point.

Thanks to everyone commented.

UPD You have to include tchar.h in order to use _tmain, so all types of entry points will work fine.

Upvotes: 1

Related Questions