33. Windows Service - Part-3 - Windows System Programming in C/C++

preview_player
Показать описание
In This Tutorial, I have covered the 3rd part of video Tutorial.
I have covered following function:
4. void ServiceReportStatus (DWORD dwCurrentState,
DWORD dwWin32ExitCode, DWORD dwWaitHint);
5. void ServiceInit (DWORD dwArgc, LPTSTR *lpArgv );
or Type Google Plus Search Bar
ASystemProgramming Channel.
Рекомендации по теме
Комментарии
Автор

If any doubt just drop your comment here, i will help you out!!!

ASystemProgrammingChannel
Автор

Google plus link is not accessible could you please share it once again. Also could you please share the document used for explanation.

vamseekrishna
Автор

Hi, there is a problem I can't find a solution for:
E0144 a value of type "const wchar_t *" cannot be used to initialize an entity of type "LPWSTR"

it appears for SERVICE_NAME in the main function, under STEP-1:

SERVICE_TABLE_ENTRY DispatchTable[] =
{
{SERVICE_NAME, (LPSERVICE_MAIN_FUNCTION)ServiceMain},
{ NULL, NULL }
};

I notice that some other of your followers are having the same problem. Could you help us, beginners, solve this, please?

#1 EDIT:
I found what about the problem was. SERVICE_TABLE_ENTRY required LPWSTR definition of which is long pointer string buffer (=expected wchar_t) but I was putting there LPCWSTR (long pointer CONSTANT string buffer). So all I needed is to convert const wchar_t to non-const wchar_t. I made by the following code.
To local variable definition in the main function I added:
//New array which is non-constant. Expecting 10 symbols because of SERVICE_NAME is "ASPService"
wchar_t servicename[9];


/*Thanks to function wcspy I can copy a const wchar_t SERVICE_NAME to the non-constant wchar_t servicename.*/
wcscpy(servicename, SERVICE_NAME);

Then I edited the SERVICE_TABLE_ENTRY argument from:
{SERVICE_NAME, (LPSERVICE_MAIN_FUNCTION)ServiceMain},
to:
{servicename, (LPSERVICE_MAIN_FUNCTION)ServiceMain},

Note: I didn't try this code, just got rid of errors. I am just a beginner and all I wrote in this section may be wrong.

vlado.erdman