It is currently Mon Dec 17, 2018 10:44 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: RegisterServiceCtrlHandlerEx_ is not a function
PostPosted: Sun Feb 09, 2014 1:29 am 
Offline
User
User

Joined: Sun Feb 09, 2014 1:22 am
Posts: 11
Hello all,

I want to use the Windows-API-function RegisterServiceCtrlHandlerEx (http://msdn.microsoft.com/en-us/library ... 85%29.aspx) which has the same parameters as RegisterServiceCtrlHandler (http://msdn.microsoft.com/en-us/library ... 85%29.aspx) except the last optional parameter.

However, when using
Code:
hStatus = RegisterServiceCtrlHandlerEx_(#MyService_Name, @Service_CtrlHandler())
PureBasic always says: RegisterServiceCtrlHandlerEx_() is not a function, array, macro or linkedlist.
When changing RegisterServiceCtrlHandlerEx_ to RegisterServiceCtrlHandler_ everything is okay.

Any ideas what I am doing wrong here?

Thanks


Top
 Profile  
Reply with quote  
 Post subject: Re: RegisterServiceCtrlHandlerEx_ is not a function
PostPosted: Sun Feb 09, 2014 1:54 am 
Offline
Addict
Addict
User avatar

Joined: Wed Aug 31, 2005 11:09 pm
Posts: 3669
Location: Italy
Hi, not all the API are pre-imported by PB.
That one is missing, you have to use openlibrary() and import the function from Advapi32.dll by yourself.

_________________
Philosophy is questions that may never be answered. Religion is answers that must never be questioned.

[ My little PureBasic review ]


Top
 Profile  
Reply with quote  
 Post subject: Re: RegisterServiceCtrlHandlerEx_ is not a function
PostPosted: Sun Feb 09, 2014 2:26 am 
Offline
PureBasic Bullfrog
PureBasic Bullfrog
User avatar

Joined: Wed Jul 06, 2005 5:42 am
Posts: 7986
Location: Fort Nelson, BC, Canada
You have to choose the ascii or unicode version. Sample for ascii:
Code:
Prototype RegisterServiceCtrlHandlerEx( lpservicename.l, lphandlerproc.l, lpcontext.l)

lib = OpenLibrary(#PB_Any, "advapi32.dll")

Global RegisterServiceCtrlHandlerEx_.RegisterServiceCtrlHandlerEx = GetFunction(lib, "RegisterServiceCtrlHandlerExA") ; For ascii version

Use W for the unicode version. With this snippet at the top of your code you can use RegisterServiceCtrlHandlerEx_() seamlessly as though it were already imported.

_________________
Veni, vidi, vici.


Top
 Profile  
Reply with quote  
 Post subject: Re: RegisterServiceCtrlHandlerEx_ is not a function
PostPosted: Sun Feb 09, 2014 1:51 pm 
Offline
User
User

Joined: Sun Feb 09, 2014 1:22 am
Posts: 11
Thank you very much netmaestro and luis! :D
I wasn't aware that the API-functions have to be pre-imported, so maybe the error-message for unknown functions with underscore at the end should better be "... is not imported or is not a function, array, macro or linkedlist."

The last parameter of RegisterServiceCtrlHandlerEx is optional so I adapted the code a little bit, also extended it with unicode-support:
Code:
Prototype RegisterServiceCtrlHandlerEx( lpservicename.l, lphandlerproc.l, lpcontext.l=0)
lib = OpenLibrary(#PB_Any, "advapi32.dll")
CompilerIf #PB_Compiler_Unicode
  Global RegisterServiceCtrlHandlerEx_.RegisterServiceCtrlHandlerEx = GetFunction(lib, "RegisterServiceCtrlHandlerExW")
CompilerElse
  Global RegisterServiceCtrlHandlerEx_.RegisterServiceCtrlHandlerEx = GetFunction(lib, "RegisterServiceCtrlHandlerExA")
CompilerEndIf


Top
 Profile  
Reply with quote  
 Post subject: Re: RegisterServiceCtrlHandlerEx_ is not a function
PostPosted: Sun Feb 09, 2014 2:20 pm 
Offline
Always Here
Always Here
User avatar

Joined: Thu Jun 24, 2004 2:44 pm
Posts: 5746
Location: Berlin - Germany
Here, a bit shorter, with Unicode/ASCII support and x86/x64 support:
Code:
Prototype RegisterServiceCtrlHandlerEx( lpservicename.p-Unicode, lphandlerproc.i, lpcontext.i = 0)
lib = OpenLibrary(#PB_Any, "advapi32.dll")
Global RegisterServiceCtrlHandlerEx_.RegisterServiceCtrlHandlerEx = GetFunction(lib, "RegisterServiceCtrlHandlerExW")

_________________
PureBasic 5.70 | SpiderBasic 2.10 | Windows 10 Pro (x64) | Linux Mint 19.0 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image


Top
 Profile  
Reply with quote  
 Post subject: Re: RegisterServiceCtrlHandlerEx_ is not a function
PostPosted: Sun Feb 09, 2014 7:35 pm 
Offline
User
User

Joined: Sun Feb 09, 2014 1:22 am
Posts: 11
Good idea ts-soft, thanks!

And you are using integer-parameters instead of long-parameters because of 64-bit compiler, right?


Top
 Profile  
Reply with quote  
 Post subject: Re: RegisterServiceCtrlHandlerEx_ is not a function
PostPosted: Sun Feb 09, 2014 7:47 pm 
Offline
Always Here
Always Here
User avatar

Joined: Thu Jun 24, 2004 2:44 pm
Posts: 5746
Location: Berlin - Germany
Yes, is right, the parameters a pointers, so integer or pointer is the right type to support 32 and 64-bit.

_________________
PureBasic 5.70 | SpiderBasic 2.10 | Windows 10 Pro (x64) | Linux Mint 19.0 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye