Problem migrating ConnectNamedPipe() from XP to Win 7

▼魔方 西西 提交于 2019-12-25 08:38:04

问题


We developed an XP application that uses ConnectNamedPipe() in blocking mode.

When testing on Win 7, the application behaves as if it is unblocked: ConnectNamedPipe() returns before its VBS client connects. An exception is raised ("Waiting for a process to open the other end of pipe") when calling StreamReader.ReadLine(). When running with the debugger, this does not occur even in Win 7!

These are the functions that we are using: [

DllImport("kernel32.dll", SetLastError = true)]
public static extern SafeFileHandle CreateNamedPipe(
String pipeName,
uint dwOpenMode,
uint dwPipeMode,
uint nMaxInstances,
uint nOutBufferSize,
uint nInBufferSize,
uint nDefaultTimeOut,
IntPtr lpSecurityAttributes);
[DllImport("kernel32.dll", SetLastError = true)]
public static extern int ConnectNamedPipe(
SafeFileHandle hNamedPipe,
IntPtr lpOverlapped); 

After we wrote this, we found an MS example from the CodePlex All-In-One Code Framework Samples that does this: (we are trying this now)

[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
            public static extern SafePipeHandle CreateNamedPipe(string pipeName,
                PipeOpenMode openMode, PipeMode pipeMode, int maxInstances,
                int outBufferSize, int inBufferSize, uint defaultTimeout,
                SECURITY_ATTRIBUTES securityAttributes);
            [return: MarshalAs(UnmanagedType.Bool)]
            [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
            public static extern bool ConnectNamedPipe(SafePipeHandle hNamedPipe,
                IntPtr overlapped);

Does anyone have an idea for a direction? Could it be security related? Thanks.


回答1:


The code sample provided by MS All-In-One Code Framework (C# named-pipe server for IPC (CSNamedPipeServer)) shows the correct way how to do this and it works on Win 7.



来源:https://stackoverflow.com/questions/7228254/problem-migrating-connectnamedpipe-from-xp-to-win-7

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!