Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 15th, 2012  |  syntax: None  |  size: 1.91 KB  |  hits: 17  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. DllImport ERROR_MORE_DATA UNMANAGED Call C   in C#
  2. DWORD OREnumKey(
  3.       __in         ORHKEY Handle,
  4.       __in         DWORD dwIndex,
  5.       __out        PWSTR lpName,
  6.       __inout      PDWORD lpcName,
  7.       __out_opt    PWSTR lpClass,
  8.       __inout_opt  PDWORD lpcClass,
  9.       __out_opt    PFILETIME lpftLastWriteTime
  10.     );
  11.        
  12. [DllImport("offreg.dll", CharSet = CharSet.Unicode, SetLastError = true)]
  13. public static extern uint OREnumKey(IntPtr Handle, IntPtr dwIndex, [MarshalAs(UnmanagedType.LPWStr)]out StringBuilder lpName, ref IntPtr lpcName, [MarshalAs(UnmanagedType.LPWStr)]out StringBuilder lpClass, ref IntPtr lpcClass, out System.Runtime.InteropServices.ComTypes.FILETIME lpftLastWriteTime);
  14.  IntPtr myKey = hiveid;
  15.     IntPtr dwindex=(IntPtr)0;
  16.     StringBuilder lpName=new StringBuilder("",255);
  17.     IntPtr lpcName = (IntPtr)0;
  18.     StringBuilder  lpClass=new StringBuilder("",255);
  19.     IntPtr lpcClass = (IntPtr)11;
  20.     System.Runtime.InteropServices.ComTypes.FILETIME lpftLastWriteTime;
  21.     uint ret3 = OREnumKey(myKey, dwindex, out lpName, ref lpcName, out lpClass, ref lpcClass, out lpftLastWriteTime);
  22.        
  23. [DllImport("offreg.dll", CharSet = CharSet.Unicode, SetLastError = true)]
  24. public static extern uint OREnumKey(
  25.     IntPtr Handle,
  26.     int dwIndex,
  27.     StringBuilder lpName,
  28.     ref int lpcName,
  29.     StringBuilder lpClass,
  30.     ref int lpcClass,
  31.     out System.Runtime.InteropServices.ComTypes.FILETIME lpftLastWriteTime);
  32.  
  33.     ...  
  34.     StringBuilder lpName=new StringBuilder("",255);
  35.     int nameSize = lpName.Capacity;
  36.     StringBuilder  lpClass=new StringBuilder("",255);
  37.     int classSize = lpClass.Capacity;
  38.     System.Runtime.InteropServices.ComTypes.FILETIME lpftLastWriteTime;
  39.     uint ret3 = OREnumKey(hiveid, 0, lpName, ref nameSize, lpClass, ref classSize, out lpftLastWriteTime);
  40.     if (ret3 != 0) throw new Exception("kaboom");
  41.     string name = lpName.ToString();
  42.     string className = lpClass.ToString();