Click here to Skip to main content
16,006,531 members
Home / Discussions / C#
   

C#

 
GeneralRe: Capture STDIO from DLL Pin
leppie7-Feb-05 21:53
leppie7-Feb-05 21:53 
GeneralRe: Capture STDIO from DLL Pin
Larsenal7-Feb-05 22:01
Larsenal7-Feb-05 22:01 
GeneralRe: Capture STDIO from DLL Pin
leppie7-Feb-05 22:25
leppie7-Feb-05 22:25 
GeneralRe: Capture STDIO from DLL Pin
Anonymous8-Feb-05 6:16
Anonymous8-Feb-05 6:16 
GeneralRe: Capture STDIO from DLL Pin
leppie8-Feb-05 6:37
leppie8-Feb-05 6:37 
GeneralRe: Capture STDIO from DLL Pin
Larsenal8-Feb-05 10:17
Larsenal8-Feb-05 10:17 
GeneralGetting system icons Pin
Luis Alonso Ramos7-Feb-05 7:40
Luis Alonso Ramos7-Feb-05 7:40 
GeneralRe: Getting system icons Pin
Heath Stewart7-Feb-05 9:33
protectorHeath Stewart7-Feb-05 9:33 
Sorry about the vote of 1. I wasn't thinking and clicked the wrong link.

For questions like this you really should consult the header. If you look at the definition for the MAKEINTRESOURCE in Winuser.h (which is documented as the header in which it's declared in the Platform SDK documentation), you'd see:
#define MAKEINTRESOURCEA(i) (LPSTR)((ULONG_PTR)((WORD)(i)))
#define MAKEINTRESOURCEW(i) (LPWSTR)((ULONG_PTR)((WORD)(i)))
#ifdef UNICODE
#define MAKEINTRESOURCE  MAKEINTRESOURCEW
#else
#define MAKEINTRESOURCE  MAKEINTRESOURCEA
#endif // !UNICODE
What's going on here? Well, certain APIs like LoadIcon want a string, and since an integer isn't a string you need to pack the integer into a string which the API will handle.

To declare a similar macro (or, rather, a method) in C# isn't nearly as straight forward, since a short (same as a WORD) isn't a string.

To get around this, declare LoadIcon like the following in order to pass a parameter of the correct size (size of a pointer):
[DllImport("user32.dll", SetLastError=true)]
static extern IntPtr LoadIcon(IntPtr hInstance, IntPtr lpIconName);
 
public IntPtr LoadIcon(short id)
{
  IntPtr i new IntPtr((int)id);
  return LoadIcon(hInstance, i);
}
If you need to overload LoadIcon to pass a string you can still do that. SendMessage, for example, is overloaded many different ways in the .NET BCL assemblies where it's used. So long as the parameter size is still the same (which is why you simply can't overload it and pass a short) you're fine, so long as the right data is passed as that parameter.

Once you have the IntPtr return you can use Bitmap.FromHicon to load the icon into memory.

This posting is provided "AS IS" with no warranties, and confers no rights.

Software Design Engineer
Developer Division Sustained Engineering
Microsoft

[My Articles] [My Blog]
GeneralRe: Getting system icons Pin
Luis Alonso Ramos7-Feb-05 10:18
Luis Alonso Ramos7-Feb-05 10:18 
GeneralRe: Getting system icons Pin
Heath Stewart7-Feb-05 10:28
protectorHeath Stewart7-Feb-05 10:28 
GeneralNotify Message Problem Pin
joy_priyank7-Feb-05 1:27
joy_priyank7-Feb-05 1:27 
GeneralRe: Notify Message Problem Pin
leppie7-Feb-05 2:20
leppie7-Feb-05 2:20 
GeneralRe: Notify Message Problem Pin
joy_priyank7-Feb-05 3:36
joy_priyank7-Feb-05 3:36 
GeneralRe: Notify Message Problem Pin
leppie7-Feb-05 3:47
leppie7-Feb-05 3:47 
GeneralRe: Notify Message Problem Pin
joy_priyank7-Feb-05 17:26
joy_priyank7-Feb-05 17:26 
GeneralCenter MessageBox over a given window Pin
dabs7-Feb-05 0:43
dabs7-Feb-05 0:43 
GeneralRe: Center MessageBox over a given window Pin
Heath Stewart7-Feb-05 9:43
protectorHeath Stewart7-Feb-05 9:43 
Generalproblem with XML Pin
Ahmed Galal7-Feb-05 0:22
Ahmed Galal7-Feb-05 0:22 
GeneralRe: problem with XML Pin
J4amieC7-Feb-05 1:01
J4amieC7-Feb-05 1:01 
GeneralRe: problem with XML Pin
Ahmed Galal7-Feb-05 3:10
Ahmed Galal7-Feb-05 3:10 
GeneralRe: problem with XML Pin
leppie7-Feb-05 2:46
leppie7-Feb-05 2:46 
GeneralRe: problem with XML Pin
Ahmed Galal7-Feb-05 3:13
Ahmed Galal7-Feb-05 3:13 
GeneralRe: problem with XML Pin
leppie7-Feb-05 3:41
leppie7-Feb-05 3:41 
GeneralRe: problem with XML Pin
MyThread7-Feb-05 5:58
MyThread7-Feb-05 5:58 
GeneralRe: problem with XML Pin
MyThread7-Feb-05 5:59
MyThread7-Feb-05 5:59 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.