Printing Excel using Interop

In order to print, you can make use of the Worksheet.PrintOut() method. You can omit any or all of the optional arguments by passing in Type.Missing. If you omit all of them, it will default to printing out one copy from your active printer. But you can make use of the arguments to set the … Read more

Send message to a Windows process (not its main window)

Here’s how I’ve done this: using System; using System.Runtime.InteropServices; using System.Threading; using System.Windows.Forms; public partial class MainForm : Form { #region Dll Imports private const int HWND_BROADCAST = 0xFFFF; private static readonly int WM_MY_MSG = RegisterWindowMessage( “WM_MY_MSG” ); [DllImport( “user32” )] private static extern bool PostMessage(IntPtr hwnd, int msg, IntPtr wparam, IntPtr lparam); [DllImport( “user32” … Read more

Should cookie values be URL encoded?

Yes. While it’s not required per the spec, the following is mentioned in RFC6265 (emphasis is in the original document, not added) To maximize compatibility with user agents, servers that wish to store arbitrary data in a cookie-value SHOULD encode that data, for example, using Base64 [RFC4648]. In my experience, most web frameworks and libraries … Read more

Understanding the Running Object Table

are you running another instance elevated? are you running the exe elevated? When you are a process running as a standard user, you can only see processes/etc that belong to you. So you wouldn’t see processes that are running as administrator. When running with escalated priviliges, you can see all processes belonging to all users. … Read more

How to call managed code from unmanaged code?

Look at this solution: https://sites.google.com/site/robertgiesecke/Home/uploads/unmanagedexports The solution allows to call C# function from C by decorating your function with [DllExport] attribute (opposite of P/Invoke DllImport). Exmaple: C# code class Test { [DllExport(“add”, CallingConvention = CallingConvention.StdCall)] public static int Add(int left, int right) { return left + right; } } C code: extern “C” int add(int, … Read more

Using SetWindowPos in C# to move windows around

Just take out your Control.FromHandle and the form == null check. You should be able to just do: IntPtr handle = process.MainWindowHandle; if (handle != IntPtr.Zero) { SetWindowPos(handle, 0, 0, 0, 0, 0, SWP_NOZORDER | SWP_NOSIZE | SWP_SHOWWINDOW); } If you add SWP_NOSIZE, it will not resize the window, but will still reposition it. If … Read more