CreateNamedPipe() - Invalid memory access.

Windows specific forum
User avatar
SimpleMind
Enthusiast
Enthusiast
Posts: 112
Joined: Sun May 18, 2003 12:40 pm
Location: Netherlands

CreateNamedPipe() - Invalid memory access.

Post by SimpleMind »

Hi,

I keep getting an "Invalid memory access" error when executing CreateNamedPipe() function. I looked at other examples and checked the parameters but can't find what I'm doing wrong here.

Code: Select all

; Program to create a named pipe and call the pipe with CallNamedPipe().

#BUFSIZE = 1024

lpszPipeName.s = "\\.\pipe\mynamedpipe"
CallDebugger
hPipe.l = CreateNamedPipe_(lpszPipename, #PIPE_ACCESS_DUPLEX, #PIPE_TYPE_MESSAGE | #PIPE_READMODE_MESSAGE | #PIPE_WAIT, #PIPE_UNLIMITED_INSTANCES, #BUFSIZE, #BUFSIZE, 20000, #Null)

If hPipe = #INVALID_HANDLE_VALUE
    End
EndIf

DefType.b CallResult

;Using API function.
;BOOL CallNamedPipe(
;  LPCTSTR lpNamedPipeName,
;  LPVOID lpInBuffer,
;  DWORD nInBufferSize,
;  LPVOID lpOutBuffer,
;  DWORD nOutBufferSize,
;  LPDWORD lpBytesRead,
;  DWORD nTimeOut
;);

lpInBuffer.s = "This is a message from PureBasic."
nInBufferSize.l = Len(lpInBuffer)
lpOutBuffer.s = Space(#BUFSIZE)
lpBytesRead.l = 0

; Keep getting an invalid Memory access on the mext line. What am I doing wrong?
CallResult = CallNamedPipe_(hPipe, lpInBuffer, nInBufferSize, lpOutBuffer, #BUFSIZE, @lpBytesRead, #NMPWAIT_USE_DEFAULT_WAIT)

End ; Of main program
Give me books, fruit, french wine, fine weather and a little music.
John Keats
User avatar
SimpleMind
Enthusiast
Enthusiast
Posts: 112
Joined: Sun May 18, 2003 12:40 pm
Location: Netherlands

Re: CreateNamedPipe() - Invalid memory access.

Post by SimpleMind »

I read the information again, and again, and saw that I call the function with a handle, that's wrong I must call it with the string name.

lpNamedPipeName
[in] Pointer to a null-terminated string specifying the pipe name.

Regards,

SimpleMind
Give me books, fruit, french wine, fine weather and a little music.
John Keats
Post Reply