Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 399
  • Last Modified:

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?
0
GiantMatrix
Asked:
GiantMatrix
1 Solution
 
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

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now