exitprocess using kernel32

Posted on 2011-10-12
Medium Priority
Last Modified: 2012-08-13
In my program I used to use the below function

Call ExitProcess(retVal)

here retval is long and I declared exitprocess as below

Private Declare Sub ExitProcess Lib "KERNEL32" _
  (ByVal uExitCode As Long)

but now i want to return string, i made the same call
Call ExitProcess(retVal)

but my decalration is different
Private Declare Sub ExitProcess Lib "KERNEL32" (ByVal uExitCode As String)

is this correct ? can i use it in this way...because i heard we can just have uExitCOde as Long.
Question by:shragi

Expert Comment

ID: 36959368
Hi shragi,
Input parameter can be long or string,since you need to return a string you can keep like this.

Private Declare Sub ExitProcess Lib "KERNEL32" _
  (ByVal uExitCode As Long)
string x=uExitCode.tostring()
end sub
LVL 75

Accepted Solution

käµfm³d   👽 earned 1000 total points
ID: 36959396
Per the documentation uExitCode is defined to be a uInt, which may be compatible with a long but I haven't checked, so be sure to confirm compatibility. Using a string would not work.

As a side not, the comments on pinvoke.net regarding this function indicate that its use is dangerous. Please be sure you know what you are doing when using this function  = )
LVL 86

Assisted Solution

by:Mike Tomlinson
Mike Tomlinson earned 1000 total points
ID: 36959417
For VB.Net you'd use Integer...but why?

.Net has wrapped it for you already via the Environment.ExitCode property:

    "This property can be used to return a success code from an application. For example, it can be used to control the execution of a set of applications invoked in a script. If the value of this property is not set by an application, zero is returned"

To return a string, write to Standard Out from your application.
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

ID: 36959507
Private Declare Sub ExitProcess Lib "KERNEL32" (ByVal uExitCode As String)

is this possible or not...

can the API take string if not is there any other options i have
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 36959513
No...it takes an Integer:

    Private Declare Sub ExitProcess Lib "KERNEL32" (ByVal uExitCode As Integer)

*Not necessary though as I pointed out previously.

What are you trying to do?...

Expert Comment

ID: 36960339
I think @kaufmed gave you the correct answer already.  Operating system exit codes are inherently numeric by nature, for now (No, you won't be able to return a string).  You can try writing the string to the standard out before exit, and any monitoring processes might be able to catch/parse that.  But for now you are limited to using Integer or Long.  That is not to say that you couldn't have a specific meaning reserved for each numeric value.  Typically, processes return 0(zero) when successful, and !0 (not zero) otherwise.

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question