If statement question part 2

Hi All,

I have the following 2 problems in code, so can someone please tell me what exactly I am doing wrong in them:

A)
var
   SCM, SCH: SC_HANDLE;
begin
   SCM := OpenSCManager(Nil, Nil, SC_MANAGER_ALL_ACCESS);

   if SCM <> Nil then

In the above block of code I always get an error:
[Error] Unit1.pas(175): Operator not applicable to this operand type

So can someone please tell me what exactly I am doing wrong here?

B)
if ChangeServiceConfig(SCH, SERVICE_NO_CHANGE, SERVICE_AUTO_START,SERVICE_NO_CHANGE,Nil,Nil,Nil,Nil,Nil,Nil,PChar(ServiceName) ) <> 0 then

I always get Error: [Error] Unit1.pas(180): Incompatible types

So can someone please tell me what exactly I am doing wrong here?
GiantMatrixAsked:
Who is Participating?
 
Russell LibbySoftware Engineer, Advisory Commented:

1.) SC_HANDLE is not a pointer type, its defined as :

SC_HANDLE = THandle;

so, check (SC_HANDLE <> 0);

2.) The ChangeServiceConfig returns a BOOL (longbool) type, so checking against <> 0 is incorrect. It should be:

 if ChangeServiceConfig(SCH, SERVICE_NO_CHANGE, SERVICE_AUTO_START, SERVICE_NO_CHANGE, nil, nil, nil, nil, nil, nil, PChar(ServiceName)) then
 begin


 end;


Regards,
Russell
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.