exitprocess using kernel32

Posted on 2011-10-12
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
    LVL 1

    Expert Comment

    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 74

    Accepted Solution

    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 regarding this function indicate that its use is dangerous. Please be sure you know what you are doing when using this function  = )
    LVL 85

    Assisted Solution

    by:Mike Tomlinson
    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.

    Author Comment

    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 85

    Expert Comment

    by:Mike Tomlinson 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?...
    LVL 7

    Expert Comment

    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.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Is Threat Intelligence?

    Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

    Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
    International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
    This video discusses moving either the default database or any database to a new volume.
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    737 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

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now