Quantcast
Channel: .NET Framework Class Libraries forum
Viewing all articles
Browse latest Browse all 8156

Not getting the Handler for the Process using ShellExecuteEx !!!

$
0
0

Hi Team,

I am printing my pdf file using ShellExcuteInfo through my OutOfBrowser Silverlgiht App. And since it doesnt offer to use Process class I engaged in PInoke way . Here 's the code : 

     [DllImport("shell32.dll", CharSet = CharSet.Auto, SetLastError = true, EntryPoint = "ShellExecuteEx")]
        static extern bool ShellExecuteEx(ref SHELLEXECUTEINFO lpExecInfo);

    [DllImport("kernel32.dll") ]
        private static extern int GetProcessId(IntPtr ptr);

  [StructLayout(LayoutKind.Sequential)]
        public struct SHELLEXECUTEINFO
        {
            public int cbSize;
            public uint fMask;
            public IntPtr hwnd;
            [MarshalAs(UnmanagedType.LPTStr)]
            public string lpVerb;
            [MarshalAs(UnmanagedType.LPTStr)]
            public string lpFile;
            [MarshalAs(UnmanagedType.LPTStr)]
            public string lpParameters;
            [MarshalAs(UnmanagedType.LPTStr)]
            public string lpDirectory;
            public int nShow;
            public IntPtr hInstApp;
            public IntPtr lpIDList;
           // [MarshalAs(UnmanagedType.LPTStr)]
            public string lpClass;
            public IntPtr hkeyClass;
            public uint dwHotKey;
            public IntPtr hIcon;
            public IntPtr hProcess;
        }

Now I invoke the ShellExecute through this function 

 public void PrintPDFAndFreeProcess()
        {
            //IntPtr processID = PrintPDF();
            //IntPtr Acrohandle = OpenProcess(ProcessAccessFlags.QueryInformation, false, processID.ToInt32());
            //CloseHandle(processID);
            //shellExInfo.cbSize = sizeof(SHELLEXECUTEINFO);
                const uint SEE_MASK_INVOKEIDLIST = 12;
                string str = "C:\\~Code\\";
                SHELLEXECUTEINFO info = new SHELLEXECUTEINFO();
                info.cbSize = System.Runtime.InteropServices.Marshal.SizeOf(info);
                info.lpVerb = "print";
                info.lpFile = "LCA.pdf";
                info.lpDirectory = str;
                info.hProcess = IntPtr.Zero;
                info.nShow = (int)ShowCommands.SW_SHOWMINNOACTIVE;
                info.fMask = SEE_MASK_INVOKEIDLIST;
                ShellExecuteEx(ref info);
                int pointer = GetProcessId(info.hProcess);

        }

All I wanted that to get the proessesID and then get the Handle and close it. As the acrobat opens up after printing. I want to close acroabat reader. Why I always get it 0.  I cant use Process.Start as its SIlveright in Out of Browser mode. 

Regards,

Arunjith


Viewing all articles
Browse latest Browse all 8156

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>