May 18, 2010 at 2:36 PM


i am hooking the documentpropertiesW API but i cant extract the structure data properly i can get the devicename and it all works like a charm, i have created a stack<IntPtr>, i seem to get the values back i then marshal it into the devmode structure but i get chinese back and all sorts of funny things here is my code

  this is the structure

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
    public struct DEVMODE
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
        public string dmDeviceName;
        public short dmSpecVersion;
        public short dmDriverVersion;
        public short dmSize;
        public short dmDriverExtra;
        public int dmFields;
        public short dmOrientation;
        public short dmPaperSize;
        public short dmPaperLength;
        public short dmPaperWidth;
        public short dmScale;
        public short dmCopies;
        public short dmDefaultSource;
        public short dmPrintQuality;
        public short dmColor;
        public short dmDuplex;
        public short dmYResolution;
        public short dmTTOption;
        public short dmCollate;
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
        public string dmFormName;
        public short dmUnusedPadding;
        public short dmBitsPerPel;
        public int dmPelsWidth;
        public int dmPelsHeight;
        public int dmDisplayFlags;
        public int dmDisplayFrequency;

this is the oncreatefile callback

public class DemoInterface : MarshalByRefObject

        public void ReportError(
            Int32 InClientPID,
            Exception e)
            MessageBox.Show(e.ToString(), "A client process (" + InClientPID + ") has reported an error...", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
        public void Ei(String Data)
        public bool Ping(Int32 InClientPID)
            return true;

        public void OnCreateFile(Int32 InClientPID,IntPtr[] data)
            //something happened
            MessageBox.Show(" " + InClientPID);

            int i = data.Length;

            for (i = 0; i < data.Length; i++)
                IntPtr Data1;
                DEVMODE dev = new DEVMODE();
                Data1 = Marshal.AllocHGlobal(data[i]);

                //Marshal.PtrToStructure(Data1, dev);

                dev = (DEVMODE)Marshal.PtrToStructure(Data1, typeof(DEVMODE));



o yes am i right in saying that by me getting the devicename from my Api hook that i am hooking the Documentproperties just allocating the data wrong into the structure

May 18, 2010 at 2:38 PM

sorry this might help as well

static int CreateDCA_Hooked(
            IntPtr hwnd,
            IntPtr hPrinter,
            String pDeviceName,
            IntPtr pDevModeOutput,
            IntPtr pDevModeInput,
            int fMode)

            DemoInjection This = (DemoInjection)HookRuntimeInfo.Callback;


                lock (This.Queue1)
                    if (This.Queue1.Count < 1000)




                //This.Queue.Push("ops, erro");

            // call original API...
            return DocumentProperties(


thanks in advance