将 ConnectNamedPipe() 从 XP 迁移到 Win 7 时出现问题

发布于 2024-12-01 18:56:53 字数 1421 浏览 2 评论 0原文

我们开发了一个 XP 应用程序,该应用程序在阻塞模式下使用 ConnectNamedPipe()。

在 Win 7 上进行测试时,应用程序的行为就像未受阻止一样:ConnectNamedPipe() 在其 VBS 客户端连接之前返回。调用 StreamReader.ReadLine() 时会引发异常(“等待进程打开管道的另一端”)。当使用调试器运行时,即使在 Win 7 中也不会发生这种情况!

这些是我们正在使用的函数: [

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); 

在我们写完这篇文章之后,我们从 CodePlex 一体式代码框架示例中找到了一个 MS 示例,该示例执行此操作:(我们现在正在尝试此操作)

[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);

有人对方向有想法吗?可能与安全有关吗?谢谢。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

林空鹿饮溪 2024-12-08 18:56:53

MS All-In-One Code Framework 提供的代码示例(用于 IPC 的 C# 命名管道服务器 (CSNamedPipeServer) )显示了执行此操作的正确方法,并且它适用于 Win 7。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文