C# saving a bitmap results in generic GDI+ error

If you save a bitmap the following exception can pop up: System.Runtime.InteropServices.ExternalException (0x80004005): A generic error occurred in GDI+. at System.Drawing.Image.Save(String filename, ImageCodecInfo encoder, EncoderParameters encoderParams) Possible causes: You tried to save the file with an invalid filename or in a directory that doesn’t exist You constructed a bitmap from a memorystream that has been […]

C# Scale bitmap

The following code scales a bitmap from the filesystem to a defined width: private static void ResizeBitmap(string filename) { using (Bitmap source = new Bitmap(filename)) { const int width = 1024; int height = (int) (((double)width/source.Width)*source.Height); using (Bitmap result = new Bitmap(width, height)) { using (Graphics g = Graphics.FromImage(result)) { g.CompositingQuality = CompositingQuality.HighQuality; g.PixelOffsetMode = […]

PInvokeStackImbalance Excpetion

If you get a PInvokeStackImbalance exception it could be: One parameter has a wrong type (p. x. int changed to long) The CallingConvention of the DllImport. Change it in the declaration: [DllImport(“user32.dll”, EntryPoint=”SetWindowLongA”, SetLastError=true)] private static extern long SetWindowLong (IntPtr hwnd, int nIndex, long dwNewLong); for example to [DllImport(“user32.dll”, EntryPoint=”SetWindowLongA”, SetLastError=true, CallingConvention = CallingConvention.Cdecl)] private […]

Run .NET Applications in 32-Bit Mode under 64-Bit Windows

Sometimes it is necessary to run .NET applications in 32-Bit mode. One example is the usage of Adobe Reader Interop Libraries which will crash if they run in 64-Bit mode. cd C:\Windows\Microsoft.NET\Framework64\v2.0.50727 ldr64 setwow This will force all .NET applications to be run in 32-Bit mode.

MSI Install Errror with CustomAction to execute a VBS-Script

The following error: "There is a problem with this Windows Installer package. A script required for this install to complete could not be run. Contact your support personnel or package vendor" Usually results from using the line: Set WShell = WScript.CreateObject("WScript.Shell") instead of Set WShell = CreateObject("WScript.Shell") this is caused because inside a MSI vbs-Scripts […]

Show PDF-Documents in a C# WPF Application

The easiest way to do this is to display the Adobe Reader Browser Plugin. This can be done with a UserControl which can be hosted in a WindowsFormsHost control in a WPF Form. You require a reference to the dlls AxInterop.AcroPDFLib.dll and Interop.AcroPDFLib.dll which you can find in the Reader SDK on the Adobe Developer Homepage. […]