I decided to use named pipes. So I created this test program to make sure my understanding of how it works is sound. Unfortunately it doesn't work as expected. See the code below:
Code:
Private Declare Function CreateNamedPipe Lib "kernel32.dll" Alias "CreateNamedPipeA" (ByVal lpName As String, ByVal dwOpenMode As Long, ByVal dwPipeMode As Long, ByVal nMaxInstances As Long, ByVal nOutBufferSize As Long, ByVal nInBufferSize As Long, ByVal nDefaultTimeOut As Long, ByRef lpSecurityAttributes As SECURITY_ATTRIBUTES) As Long
Private Declare Function WriteFile Lib "kernel32.dll" (ByVal hFile As Long, ByRef lpBuffer As Any, ByVal nNumberOfBytesToWrite As Long, ByRef lpNumberOfBytesWritten As Long, ByRef lpOverlapped As OVERLAPPED) As Long
Private Declare Function ReadFile Lib "kernel32.dll" (ByVal hFile As Long, ByRef lpBuffer As Any, ByVal nNumberOfBytesToRead As Long, ByRef lpNumberOfBytesRead As Long, ByRef lpOverlapped As OVERLAPPED) As Long
Private Declare Function CloseHandle Lib "kernel32.dll" (ByVal hObject As Long) As Long

Private Type SECURITY_ATTRIBUTES
    nLength As Long
    lpSecurityDescriptor As Long
    bInheritHandle As Long
End Type

Private Type OVERLAPPED
    ternal As Long
    ternalHigh As Long
    offset As Long
    OffsetHigh As Long
    hEvent As Long
End Type



Private Sub Form_Load()
Dim NPipeHandle As Long
Dim OL As OVERLAPPED 'I'm going to leave this blank so defaults are used
Dim Sec As SECURITY_ATTRIBUTES 'I'm going to leave this blank so defaults are used
Dim a As Long
Dim b As Long


a = 12345

NPipeHandle = CreateNamedPipe("\\.\pipe\MyPipe", 3, 0, 1, 4, 4, 50, Sec) 'it is configured to work duplex, have no more than one instance, have 4 byte input and 4 byte output buffers, and have a 50ms waiting time.
Print NPipeHandle

z = 0
Print WriteFile(NPipeHandle, a, 4, z, OL)
Print z

z = 0
Print ReadFile(NPipeHandle, b, 4, z, OL)
Print z
Print b

CloseHandle NPipeHandle
End Sub
The first print statement shows a number, indicating the handle of the named pipe.
The print statements after that all show 0, indicating a complete failing of the rest of the program.

Please tell me why this isn't working.