Parameters for CreateProcess API call are giving type mismatch

I'm trying to use CreateProcess to spawn an application.
For some reason, one of the arguments for it is giving me a type mismatch error.  I have checked and double checked and I can find no mismatch.  Further, VB doesn't tell me which argument is yielding the type mismatch, it just highlights the entire API call.  If you could tell me why CreateProcess won't buy this, I would appreciate it.

Here are my type declarations, api declarations, and the offending line:

The offending line:
CreateProcessA(0&, strCommandLine, 0&, 0&, 1&, _
"high_priority_class", 0, 0&, usrStartupInfo, _ usrProcessInfo)

The API declaration:
Declare Function CreateProcessA Lib "kernel32" _
    (ByVal lpApplicationName As Long, _
     ByVal lpCommandLine As String, _
     ByVal lpProcessAttributes As Long, _
     ByVal lpThreadAttributes As Long, _
     ByVal bInheritHandles As Long, _
     ByVal dwCreationFlags As Long, _
     ByVal lpEnvironment As Long, _
     ByVal lpCurrentDirectory As String, _
     lpStartupInfo As StartupInfo, _
     lpProcessInformation As PROCESS_INFORMATION) _
     As Long _

And the variable declarations

 Dim strCommandLine As String
 Dim usrStartupInfo As StartupInfo        

 Dim lonCProcRTN As Long                  
 Dim strStartupDir As String
Who is Participating?

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

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.

Private Declare Function CreateProcess Lib "kernel32" Alias _
      "CreateProcessA" (ByVal lpApplicationName As String, ByVal _
      lpCommandLine As String, lpProcessAttributes As Any, _
      lpThreadAttributes As Any, ByVal bInheritHandles As Long, _
      ByVal dwCreationFlags As Long, lpEnvironment As Any, ByVal _
      lpCurrentDriectory As String, lpStartupInfo As STARTUPINFO, _
      lpProcessInformation As PROCESS_INFORMATION) As Long

marimba, you can use the vb API viewer to check you API declaration, If you have VB5 professional or enterprise version.
In Win95/WinNT, goto Start/Program/Microsoft VB5/API text viewer, and when the viewer show up, open the file WinAPI32.txt, select the API fuction you want, the declaration will appear, then you can just copy it to your VB code.
This is what I copied:
Declare Function CreateProcess Lib "kernel32" Alias "CreateProcessA" (ByVal lpApplicationName As String, ByVal lpCommandLine As String, lpProcessAttributes As SECURITY_ATTRIBUTES, lpThreadAttributes As SECURITY_ATTRIBUTES, ByVal bInheritHandles As Long, ByVal dwCreationFlags As Long, lpEnvironment As Any, ByVal lpCurrentDriectory As String, lpStartupInfo As STARTUPINFO, lpProcessInformation As PROCESS_INFORMATION) As Long

Just a reminder, the STARTUPINFO must be defined.

   hProcess As Long
   hThread As Long
   dwProcessId As Long
   dwThreadId As Long
End Type

   cb As Long
   lpReserved As String
   lpDesktop As String
   lpTitle As String
   dwX As Long
   dwY As Long
   dwXSize As Long
   dwYSize As Long
   dwXCountChars As Long
   dwYCountChars As Long
   dwFillAttribute As Long
   dwFlags As Long
   wShowWindow As Integer
   cbReserved2 As Integer
   lpReserved2 As Long
   hStdInput As Long
   hStdOutput As Long
   hStdError As Long
End Type

If it doesn't work out, please add to comments.

Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

marimba, I hope you reject Dalin's proposed answer because your declaration is fine.

The problem is that the dwCreationFlags argument must be passed a long value. HIGH_PRIORITY_CLASS is a constant and has a value of &H80 (decimal 128).  Your declaration is correct although you probably should delete the underscore at the end (see note below).  Place the path & filename in strCommandLine, add the HIGH_PRIORITY_CLASS constant declaration and call CreateProcess as follows:


CreateProcessA 0, strCommandLine, 0, 0, 1, _
HIGH_PRIORITY_CLASS , 0, 0, usrStartupInfo, usrProcessInfo

Note: The underscore at the end of the declaration tells VB that the next line is part of the declaration... and since that line is blank... it works out.  I would remove that underscore.  You're call to CreateProcessA also had an underscore character in with usrProcessInfo - this underscore shouldn't be there.
Thank you for your comments, mrmick.
Also thanks to cliffABB for his contribution.

marimba, When an API call gives you a mismatch error, you either declared wrong or passed a paramenter with the wrong type.

when I first see your question, I saw you delcared ApplicationName as Long. So I thought I will post the standard VB declaration first, so that you can check your parameters against it, and I will then follow up.  When I come back a few minute late, cliffABB already posted his comments to point out the wrong time in "high_priority_class". So I did not repeat that, instead, I give you a general method of get the right declaration, and was hoping if you have further problem after taking into consideration of the comments from me and cliffABB.

One thing on the API is that these API fuctions are writting in a language other than VB. So some of the types may not be the original type for various reason. So sometimes even a seemly wrong type may work.

Anyway, how is your program goes?  I hope our comments helped. If you have anymore problems, please let us know.

My main goal is to offer help. I will do my best in getting a solution for the questions I answer.  If you feel that my answer and comments did not help, you can reject my answer as mrmick suggested.  Either way, as long as you get your probelem solved, I will be happy. I enjoyed the experience and looking forward to work with you in to get the best solution for this problem or any other you may have in the further.

Best wishes.


You may be trying to help find the solution, but assuming that you do know what you're doing... do you recognize that (clifABB noticed the problem) I posted the solution?  And if your goal is really just to help... why are you still trying to get credit for this question knowing that you didn't provide the solution?  In fact, you’re the cause of marimba having to wait several days for a solution because you locked this question and took it out of the "Questions Awaiting Answers" list.

Probably the best think you can do in helping others Darlin is this: If you don't know the answer to a question, post anything you may have to say as a comment.  Post only SOLUTIONS as answers to questions.  I (and probably others) would have noticed the problem and posted the solution on the same day this question was posted had it been in the "Questions Awaiting Answers" list.


Thank you again for your comments and critism. It is a good suggestion to me and others to post comments when they don't think they can provide a good solution. I will certainly do my best for that.

Please forgive me if I made any mistakes in understanding what the procedure is for this site.  I am now here and certainly make a mistake on my first try.

One thing I do want to clearify is that I am not so concerned about the credit, at least not yet, becuase I don't see the importance to me yet.  I am doing what you suggestted to do (obviously not enough), is to post comments when I don't believe I can give the solution.  In some cases even I had the solution I onlt post as comments when I was the first one to show in the question. When I get an answer, I will post it regardless of it's open status. If I make a mistake, I sincerely apologize.  You may check the following questions to see what I am saying:
1. Run Simulteneousely  by X factor, still open
2. CommandButtom by mroh, Locked
3. Capture Screen from VB, you had a comments on it.

You have the right to believe that I am just try to get credit.  I can understand.   But I am confident that you will change your mind when time goes on.  

Thanks again, and  I do respect you from my heart.


Dalin, I was just frustrated by several questions that I found to be locked without an answer.  I felt that you made a stab in the dark because you didn't obviously have any idea what was causing the problem at the time you locked the question.  Granted, you may have realized 10 minutes later but not when you locked the question.  I just wanted to make a point with you partially because I had seen comments you had made in another question suggesting that someone else had wrongfully done this.  I'd be happy to continue this discussion VIA email.  My address is:

Gentlemen:  I appreciate your help.  Being that this was a 3 day weekend for me, I have not yet had time to test all the solutions.  But I will do so first thing tomorrow.

However, I did get to look at the first two portions before I left on Friday.  Dalin, I appreciate your help, but this was a 300 point question, and cutting and pasting an API declaration as well as the type definitions are not 300 point answer material.  I cut and pasted it myself, it's not like I pulled it from memory and needed someone to check my recall.  The expertise in knowing API calls is what each argument is and how it is passed, and that is why I am confessing ignorance about that here in this forum.  

marimbaAuthor Commented:
marimba.  Thank you for your comments.
Sorry I did not fully understand your problem before I post the answer and I sincerely appologize to you and other viewers.
If you have any further questions, please let us know.
If it work out, mrmick and cliffABB deserved all the credits.
Best wishes.
marimba, I think you will find that the solution I posted is what you're looking for.

Dalin, I think your participation here is good and I hope I haven't discouraged you.

MrMick you are correct sir.  It was indeed the value of the lpProcessInformation flag was not passed correctly.

Could I beg one more related question...

I know that a lot of these API's ask for a wide variety of constants such as the one you described.  If I had known where to find the constant for the high priority class, I might have stumbled across the answer on my own.  I didn't find this list in the Win32 SDK nor in Appleman's Win32 API book, can you tell me where I can find a list of these constants?

Thanks again,

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
marimbaAuthor Commented:
Also gentlemen, I have found an error in this which we all should be aware of, and nobody has yet caught.  This did not affect me because I was passing this value as 0 anyway, but if I were using this parameter, it would have been a problem.

There's a misspelling in the declaration found in the API text viewer.  It is for the definition of lpCurrentDirectory, this is cut-and-pasted straight from the API Text viewer as-is:

Declare Function CreateProcess Lib "kernel32" Alias "CreateProcessA" (ByVal lpApplicationName As String, ByVal lpCommandLine As String, lpProcessAttributes As SECURITY_ATTRIBUTES, lpThreadAttributes As SECURITY_ATTRIBUTES, ByVal bInheritHandles As Long, ByVal dwCreationFlags As Long, lpEnvironment As Any, ByVal lpCurrentDriectory As String, lpStartupInfo As STARTUPINFO, lpProcessInformation As PROCESS_INFORMATION) As Long
marimbaAuthor Commented:
miramba, the names of ALL the passed parameters could be misspelled and the function would still work.  They mean nothing to the compiler.  Those names are only for you're benefit.  Try it, change all the names by copying the function definition, commenting out the good one, change all the names of the parameters on the uncommented one, and run your app.  It will still work fine.  The names that matter are the alias name (in the above posts you weren't using alias so in that case the function name) and the library name ("kernal32").  In fact, the function name (alias since you're using it here) is case sensitive.

Constant declarations are available in the API Viewer.  When you open the API file, the default API Type is "Declares" in the dropdown combo box.  Change the value to "Constants".  You can get the definitions of the structures like SECURITY_ATTRIBUTES or STARTUPINFO or PROCESS_INFORMATION also by changing the API Type to: "Types"

The constants definitions are not available in the Win32 SDK; however, they are shipped with it.  In the same root path as the infoviewer (usually MSTools) there is an "Include" folder.  Inside this folder are C header files.  You can sometimes determine the correct header file by deriving it from the library name, but usually you can get it form the "Quick Info" button in the Win32 API function reference.  In this case the quick info displays "kernel32" as the library and "winbase.h" as the header file.  The "winbase.h" header file defines the following (among many other definitions):

#define NORMAL_PRIORITY_CLASS       0x00000020
#define IDLE_PRIORITY_CLASS         0x00000040
#define HIGH_PRIORITY_CLASS         0x00000080
#define REALTIME_PRIORITY_CLASS     0x00000100

The VB translation looks like this:

The "0x" at the beginning of a number in a C header file means hexadecimal.  In the VB definitions, the "&" means Long Integer Value and the "H" means Hexadecimal.  The Win32 SDK lists the above possible constant names for dwCreationFlags parameter.  Notice the "dw" in "dwCreationFlags".  This indicates a "Double Word" which equals two words each consisting of two bytes; thus, 4 bytes.  Constants are normally expressed in ALL CAPS.

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
Visual Basic Classic

From novice to tech pro — start learning today.