Click here to Skip to main content
14,608,096 members
Rate this:
Please Sign up or sign in to vote.
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
Rate this:
Please Sign up or sign in to vote.

Solution 1

Try this:
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:
typedef struct _SERVICE_TABLE_ENTRYW {
  LPWSTR                   lpServiceName;
  LPSERVICE_MAIN_FUNCTIONW lpServiceProc;
} SERVICE_TABLE_ENTRYW, *LPSERVICE_TABLE_ENTRYW;

It should have probably been
LCPWSTR lpServiceName

Setting a string with the service name makes it non-const and the compiler should not complain any more.
   
Comments
Sandeep Mewara 29-Jul-20 2:04am
   
+5
CPallini 29-Jul-20 2:05am
   
5.
Rate this:
Please Sign up or sign in to vote.

Solution 2

Write in the header:
extern const wchar_t *testit_name;
//in the cpp files
const wchar_t *testit_name = TEXT("testit");
   

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




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100