LoadImage (user32)
Last changed: -178.73.49.127

.
Summary

C# Signature:

[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
static extern IntPtr LoadImage(IntPtr hinst, string lpszName, uint uType,
   int cxDesired, int cyDesired, uint fuLoad);

VB Signature:

<DllImport("user32.dll", SetLastError:=True)> _
Private Shared Function LoadImage(ByVal hInst As IntPtr, ByVal lpszName As String, ByVal uType As UInt32, _
ByVal cxDesired As Integer, ByVal cyDesired As Integer, ByVal fuLoad As UInt32) As IntPtr
End Function

C++/CLI Signature:

[DllImportAttribute("user32.dll", SetLastError = true, CharSet = CharSet::Auto)]
extern "C" int LoadImage(int hinst, int lpszName, unsigned int uType, int cxDesired, int cyDesired, unsigned int fuLoad);

User-Defined Types:

None.

User-Defined Constants:

IMAGE_

LR_

Notes:

C++/CLI: This solution allows you to load an image from an unmanaged resource in the assembly. In my case I added a .cur file to my .rc. The cursor had an ID of 101. After loading the cursor I assigned it to the Forms::Cursor.

Tips & Tricks:

To use integer resource ID instead of string, and avoid using MAKEINTRESOURCE, prepend the integer with '#'. For example, to use resource ID 32512, enter "#32512" for lpszName.

To load application icons of different sizes, use cxDesired and cyDesired (see the example).

Sample Code:

Please add some!

C++/CLI Example

using namespace System::Runtime::InteropServices;
using namespace System::Windows::Forms;
using namespace System::Reflection;

int a = LoadImage(Marshal::GetHINSTANCE(Assembly::GetExecutingAssembly()->GetModules()[0]).ToInt32(),101,2,0,0,0);
this->Cursor = gcnew ::Cursor(IntPtr(a));

Alternative Managed API:

System.Drawing.Image.FromFile

- or to load an image from a managed resource (dll):

System.Drawing.Bitmap.FromResource

Documentation