Passing pointers to strings to API 
Author Message
 Passing pointers to strings to API

I am trying to call the CreateProcessA function (see declaration below).
I want to pass it a value for lpCurrentDirectory, which is a pointer to a string
containing the directory you want the new process to run in.
I can't find out how to pass this as all the examples I can find just pass a null
value.

Does anyone know how to create a pointer to a string in VB so that it will work
in functions such as the one below?

Any help would be very much appreciated.

Many thanks, Penny

Private 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 Long, _  <<this one
    lpStartupInfo As STARTUPINFO, lpProcessInformation As _
    PROCESS_INFORMATION) As Long



Fri, 21 Nov 2003 15:46:12 GMT  
 Passing pointers to strings to API
Penny,

Quote:
>I am trying to call the CreateProcessA function (see declaration below).

I suggest you declare it like this instead

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

Quote:
>I want to pass it a value for lpCurrentDirectory, which is a pointer to a string
>containing the directory you want the new process to run in.

Just pass the string as it is, VB will handle the conversion for you.

Mattias

====================================

http://www.msjogren.net/dotnet/

CodeHound - The Software Developer's Search Engine
http://www.codehound.com



Fri, 21 Nov 2003 17:38:41 GMT  
 Passing pointers to strings to API
Thankyou very much, I will try this.

Penny

Quote:
-----Original Message-----

Penny,

>I am trying to call the CreateProcessA function (see declaration below).

I suggest you declare it like this instead

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

>I want to pass it a value for lpCurrentDirectory, which is a pointer to a string
>containing the directory you want the new process to run in.

Just pass the string as it is, VB will handle the conversion for you.

Mattias

====================================

http://www.msjogren.net/dotnet/

CodeHound - The Software Developer's Search Engine
http://www.codehound.com
.



Fri, 21 Nov 2003 23:02:21 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Passing pointer to a pointer or pointer to a char to a dll

2. Passing fixed length string to API and is returning nulls in string

3. Pass a Pointer to a String

4. Passing pointer to string in DLL funtions

5. How to pass a string as a pointer

6. Passing Arrays Pointer To API

7. Passing NULL pointer to dll api

8. Passing a null pointer to an api call

9. Passing a null pointer to Windows API routines from Visual Basic

10. How to pass pointer to API call

11. Calling API with strucures / finding pointer to string

12. string pointer in structure for API calls

 

 
Powered by phpBB® Forum Software