Re: CreateProcessA Lib "kernel32" problem

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Randy Birch (rgb_removethis_at_mvps.org)
Date: 07/08/04


Date: Thu, 8 Jul 2004 10:34:35 -0400

The VB viewer defines some variables as the data type expected, eg As String
or As SECURITY_ATTRIBUTES (a user-defined type). Others will declare those
members As Long and will pass a memory pointer to where the string or
SECURITY_ATTRIBUTES UDT exists. For strings one uses StrPtr(sTheString). For
SECURITY_ATTRIBUTES Byval 0& is often used to indicate no
SECURITY_ATTRIBUTES are being set, meaning use the current thread's security
settings. If you want to get technical, under the hood VB passes everything
as a Long value anyway representing the memory address of the particular
variable's contents. Therefore some declares are simply defined to accept
Long values anyway.

-- 
Randy Birch
MVP Visual Basic
http://vbnet.mvps.org/
Please respond only to the newsgroups so all can benefit.
"vbVeryBeginner" <anonymous@anonymous.com> wrote in message 
news:40ecaa0c_2@news.tm.net.my...
: thanks first, zoury and gale green
:
: now, this is funny.
: i figure out how to did it but i don't really understand what going on.
: let say i am going to use the WIN32 API CreateProcess, the first step i 
will
: do is to search for that function using the VB provided API Viewer.
:
: it ask me to declare using the following statement
:
: 01>   Private Declare Function CreateProcess Lib "kernel32" Alias
: "CreateProcessA" ( _
: 02>      ByVal lpApplicationName As String, _
: 03>      ByVal lpCommandLine As String, _
: 04>      lpProcessAttributes As SECURITY_ATTRIBUTES, _
: 05>      lpThreadAttributes As SECURITY_ATTRIBUTES, _
: 06>      ByVal bInheritHandles As Long, _
: 07>      ByVal dwCreationFlags As Long, _
: 08>      lpEnvironment As Any, _
: 09>      ByVal lpCurrentDriectory As String, _
: 10>      lpStartupInfo As STARTUPINFO, _
: 11>      lpProcessInformation As PROCESS_INFORMATION) As Long
:
: and after much desperate tries to figure out what went wrong, i try
: downloading some other example code and to my astonishment, they use a
: DIFFERENT declaration!
:
: 01>   Private Declare Function CreateProcessA Lib "kernel32" ( _
: 02>      ByVal lpApplicationName As Long, _
: 03>      ByVal lpCommandLine As String, _
: 04>      ByVal lpProcessAttributes As Long, _
: 05>      ByVal lpThreadAttributes As Long, _
: 06>      ByVal bInheritHandles As Long, _
: 07>      ByVal dwCreationFlags As Long, _
: 08>      ByVal lpEnvironment As Long, _
: 09>      ByVal lpCurrentDirectory As Long, _
: 10>      lpStartupInfo As STARTUPINFO, _
: 11>      lpProcessInformation As PROCESS_INFORMATION) As Long
:
: the differences are
: #2
: ByVal lpApplicationName As String (VB API Declaration)
: ByVal lpApplicationName As Long (Their Declaration)
:
: #4
: lpProcessAttributes As SECURITY_ATTRIBUTES (VB)
: ByVal lpProcessAttributes As Long (Their)
:
: #5
: lpThreadAttributes As SECURITY_ATTRIBUTES (VB)
: ByVal lpThreadAttributes As Long (Their)
:
: #8
: lpEnvironment As Any (VB)
: ByVal lpEnvironment As Long (Their)
:
: #9
: ByVal lpCurrentDriectory As String (VB)
: ByVal lpCurrentDirectory As Long (Their)
:
: i have NO LUCK using the VB provided API Viewer but able to start the
: notepad.exe using THEIR declaration. now, why the VB declaration can't 
run!
: because i thought the VB API Viewer should be the official resource of API
: declaration. Should i trust the VB API Viewer anymore?
:
: i also have an PSDK august 2001 edition.
:
: BOOL CreateProcess(
:   LPCTSTR lpApplicationName,                 // name of executable module
:   LPTSTR lpCommandLine,                      // command line string
:   LPSECURITY_ATTRIBUTES lpProcessAttributes, // SD
:   LPSECURITY_ATTRIBUTES lpThreadAttributes,  // SD
:   BOOL bInheritHandles,                      // handle inheritance option
:   DWORD dwCreationFlags,                     // creation flags
:   LPVOID lpEnvironment,                      // new environment block
:   LPCTSTR lpCurrentDirectory,                // current directory name
:   LPSTARTUPINFO lpStartupInfo,               // startup information
:   LPPROCESS_INFORMATION lpProcessInformation // process information
: );
:
: according to this API, the declaration provided by the VB API Viewer 
SHOULD
: be correct, but WHY it can't runs ???
:
: as a vbVeryBeginner, i hope this won't discourage me...:)
: sincerely hope somebody here in NG would love to explain to me...WHY...
: thanks
:
:
:
:
:
: 


Relevant Pages

  • Re: CreateProcessA Lib "kernel32" problem
    ... do is to search for that function using the VB provided API Viewer. ... 02> ByVal lpApplicationName As String, ... 04> lpProcessAttributes As SECURITY_ATTRIBUTES, _ ... ByVal lpApplicationName As String (VB API Declaration) ...
    (microsoft.public.vb.winapi)
  • Re: Is C99 the final C? (some suggestions)
    ... >> defined a function that returns an image string for a value of your ... >> need to decide how and whether the user can define precedence for the ... > of declaration. ... "parenthesize, parenthesize, parenthesize". ...
    (comp.lang.c)
  • Re: curious about array initialization.
    ... understanding that its through the variable declaration that we ... By "inline string", I assume you mean a string literal. ... more than that you have implicit storage. ... Its a concept from computer programming. ...
    (comp.lang.c)
  • Re: DhcpRequestParams from dhcpcsvc.dll
    ... it is because I do think that my own vb declaration is wrong, ... string to Unicode with StrConv and pass that as a string. ... Dim sendParams As DHCPAPI_PARAMS ...
    (microsoft.public.vb.winapi)
  • Re: curious about array initialization.
    ... understanding that its through the variable declaration that we ... By "inline string", I assume you mean a string literal. ... more than that you have implicit storage. ...
    (comp.lang.c)