Click here to Skip to main content
15,881,938 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Could somebody help me ?

I had declared a constant and I need that be global

#define SVCNAME TEXT("testit")
...
SERVICE_TABLE_ENTRY DispatchTable[] =
{
{ SVCNAME, (LPSERVICE_MAIN_FUNCTION) testit },
{ NULL, NULL }
};

and I got:

Error C2440 'inicializando': no se puede realizar la conversión de 'const wchar_t [7]' a 'LPWSTR' easyDB C:\Software\test1\test2\dllmain.cpp 60
.

What I have tried:

I tried some ways of declare a global constant, also that be LPWSTR at time of the declaration. 
Posted
Updated 28-Jul-20 20:25pm

Try this:
C++
wchar_t testit_name[] = "testit";
SERVICE_TABLE_ENTRY DispatchTable[] =
{
{ testit_name, (LPSERVICE_MAIN_FUNCTION) testit },
{ NULL, NULL }
};


For some reason (probably this definition hasn't been updated in many years)
SERVICE_TABLE_ENTRY is defined as:
C++
typedef struct _SERVICE_TABLE_ENTRYW {
  LPWSTR                   lpServiceName;
  LPSERVICE_MAIN_FUNCTIONW lpServiceProc;
} SERVICE_TABLE_ENTRYW, *LPSERVICE_TABLE_ENTRYW;

It should have probably been
C++
LCPWSTR lpServiceName

Setting a string with the service name makes it non-const and the compiler should not complain any more.
 
Share this answer
 
Comments
Sandeep Mewara 29-Jul-20 2:04am    
+5
CPallini 29-Jul-20 2:05am    
5.
Write in the header:
C++
extern const wchar_t *testit_name;
//in the cpp files
const wchar_t *testit_name = TEXT("testit");
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900