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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.