FREE Subscription to Dr. Dobb’s Digest: Same Great Content, New Digital Edition
Site Archive (Complete)
Dobbs M-Dev
Email
Print
Reprint

add to:
Del.icio.us
Digg
Google
Furl
Slashdot
Y! MyWeb
Blink
December 01, 2003

In Search of Robust, Secure IPC for .NET

(Page 5 of 7)
In Search of Robust, Secure IPC for .NET

Listing 2 P/Invoke declarations for accessing DDE


using System;
using System.Runtime.InteropServices;

namespace Jitsu.Dde
{
  internal sealed class Win32
  {
    private Win32()
    {} // suppress default public ctor for static class

    //
    // Managed wrappers for Win32 functions

    public static ushort GlobalAddAtom(string s)
    {
      ushort r = PInvoke.GlobalAddAtom(s);
      if (r == 0) throw new System.ComponentModel.Win32Exception();
      return r;
    }

    public static void UnpackDDElParam(         int msg, IntPtr lParam, out IntPtr loword, out IntPtr hiword)
    {
      bool b = PInvoke.UnpackDDElParam(msg,lParam,out loword, out hiword);
      if (!b) throw new DdeException("UnpackDDElParam failed.");
    }

    public static void FreeDDElParam(int msg, IntPtr lParam)
    {
      bool b = PInvoke.FreeDDElParam(msg,lParam);
      if (!b) throw new DdeException("FreeDDElParam failed.");
    }

    public static void PostMessage(         IntPtr hwnd, Message msg, IntPtr wParam, IntPtr lParam)
    {
      bool b = PInvoke.PostMessage(hwnd,(int)msg,wParam,lParam);
      if (!b) throw new System.ComponentModel.Win32Exception();
    }

    //
    // Nested class for extern Win32 declarations





    [SuppressUnmanagedCodeSecurity]     public sealed class Pinvoke
    {
      private PInvoke()       {} // suppress default public ctor for static class

      [DllImport("User32.dll")]
      public static extern bool IsWindowUnicode(IntPtr hwnd);

      [DllImport("Kernel32.dll", SetLastError=true)]
      public static extern ushort GlobalAddAtom(string s);

      [DllImport("Kernel32.dll")]
      public static extern void GlobalDeleteAtom(ushort atom);

      [DllImport("User32.dll")]
      public static extern IntPtr PackDDElParam(           int msg, IntPtr loword, IntPtr hiword);

      [DllImport("User32.dll", SetLastError=false)]
      public static extern bool UnpackDDElParam(           int msg, IntPtr lParam, out IntPtr pLo, out IntPtr pHi);

      [DllImport("User32.dll", SetLastError=false)]
      public static extern bool FreeDDElParam(int msg, IntPtr lParam);

      [DllImport("User32.dll")]
      public static extern IntPtr SendMessage(           IntPtr hwnd,int msg, IntPtr wParam, IntPtr lParam);

      [DllImport("User32.dll", SetLastError=true)]
      public static extern bool PostMessage(           IntPtr hwnd,int msg, IntPtr wParam, IntPtr lParam);
    }

    //
    // Supporting types

    public enum Message
    {
      DdeInitiate = 0x03E0,
      DdeAck = 0x03E4,
      DdeExecute = 0x03E8,
      DdeTerminate = 0x03E1
    }
  }
}

Previous Page | 1 | 2 | 3 | 4 | 5 | 6 | 7 Next Page
TOP 5 ARTICLES
No Top Articles.



MICROSITES
FEATURED TOPIC

ADDITIONAL TOPICS

INFO-LINK