Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

WriteFile

Status
Not open for further replies.

Ladyhawk

Programmer
Jan 22, 2002
534
AU
How do you use the WriteFile API to write a text string to a named pipe?

Ladyhawk. [idea]
** ASP/VB/Java Programmer **
 
Ladyhawk

Hey, I am playing with Named Pipes at the moment - sort of had some success! What problems are you having?

Pretty much what I did was to create a NP at the server and set it to connect

ie CreateNamedPipe to get handle to pipe
then
ConnectNamedPipe to wait for connection (blocking call) Once connected
ReadFile using pipe handle

At the client end,
CreateFile to get handle to pipe

WriteFile to put data on to pipe.

What language are you using (me C++) but the same principles apply.

If this doesn't help much - I am sorry but post some more info and I'll offer some more assistance.

I am still working on overlapping IO and stuff, so it maybe you can help me!



Take Care

Matt
If at first you don't succeed, skydiving is not for you.
 
It seems that named pipes isn't quite what I want. I needed to have some information available about an app while it is running but I wanted the info destroyed if the app was killed.

I decided to use shared memory and I sort of have it working. I am using VB. If I have refreshly opened the VB IDE and run the app which create the file it works, but if I close the app and restart the app it returns a file handle of -1.

This is the code I am using the create the file.

With m_saSecurity
.nLength = Len(m_saSecurity)
.lpSecurityDescriptor = 0
.bInheritHandle = True
End With

' create new file, read write access, exclusive use
m_lFileHandle = CreateFile(mc_sScenarioSharedMemFileName, GENERIC_READ Or GENERIC_WRITE, 0, m_saSecurity, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL Or FILE_FLAG_SEQUENTIAL_SCAN, 0)

lError = GetLastError
If m_lFileHandle = -1 Then
MsgBox "Can't create file - " & lError
m_lFileHandle = 0
Exit Sub
End If

When I close the app I run this code..

If m_lFileHandle <> 0 Then
Call CloseHandle(m_lFileHandle)
m_lFileHandle = 0
End If

Any ideas?

Ladyhawk. [idea]
** ASP/VB/Java Programmer **
 
I think this behaviour might be the VB IDE not letting go of things that the app has. Seems to work ok as an executable.

Ladyhawk. [idea]
** ASP/VB/Java Programmer **
 
Hi,

I am sorry, I can't offer much more than this!

What is the error code that is returned when you get a handle of -1 (i.e. value of err.lastdllerror)

This may give you more ideas as to why the handle isn't being created.

Sorry can't bre more use!


Take Care

Matt
If at first you don't succeed, skydiving is not for you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top