Click here to Skip to main content
15,887,915 members
Home / Discussions / C#
   

C#

 
AnswerRe: Get name of system folder [using C#] Pin
DaveyM696-May-11 20:52
professionalDaveyM696-May-11 20:52 
AnswerRe: Get name of system folder [using C#] Pin
DaveyM696-May-11 21:25
professionalDaveyM696-May-11 21:25 
QuestionCan't publish a project even though no build errors Pin
Nathan D Cook6-May-11 9:31
Nathan D Cook6-May-11 9:31 
AnswerRe: Can't publish a project even though no build errors Pin
AspDotNetDev6-May-11 9:39
protectorAspDotNetDev6-May-11 9:39 
Questionpass a Size object to sendmessage Pin
manchukuo6-May-11 7:37
manchukuo6-May-11 7:37 
AnswerRe: pass a Size object to sendmessage Pin
DaveyM696-May-11 8:05
professionalDaveyM696-May-11 8:05 
GeneralRe: pass a Size object to sendmessage Pin
manchukuo6-May-11 8:12
manchukuo6-May-11 8:12 
GeneralRe: pass a Size object to sendmessage Pin
DaveyM696-May-11 8:27
professionalDaveyM696-May-11 8:27 
You should NOT pass an int directly as I explained - an int is 4 bytes but on a 64 bit system the function requires 8 bytes.
If you really need to pass a value directly you should create an IntPtr from it:
new IntPtr(yourInt)

By the way, the return value should also be an IntPtr.
Don't forget you can overload the method, so long as the size of the parameters are correct it won't fail.
C#
// NativeMethods.cs

using System;
using System.Drawing;
using System.Runtime.InteropServices;

internal static class NativeMethods
{
    // http://msdn.microsoft.com/en-us/library/ms644950(v=vs.85).aspx
    /*
LRESULT WINAPI SendMessage(
__in  HWND hWnd,
__in  UINT Msg,
__in  WPARAM wParam,
__in  LPARAM lParam
);*/
    [DllImport("User32.dll", SetLastError = true)]
    public static extern IntPtr SendMessage(
        IntPtr hWnd, int Msg, IntPtr wParam, IntPtr lParam);
    [DllImport("User32.dll", SetLastError = true)]
    public static extern IntPtr SendMessage(
        IntPtr hWnd, int Msg, IntPtr wParam, ref Size lParam);
}

Now you need to work out how to get the size back out once you receive the message, and you may need to pin the Size parameter in memory so it doesn't get moved or go out of scope and get collected...
Dave

Binging is like googling, it just feels dirtier.
Please take your VB.NET out of our nice case sensitive forum.
Astonish us. Be exceptional. (Pete O'Hanlon)

BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)



GeneralRe: pass a Size object to sendmessage [modified] Pin
manchukuo6-May-11 8:30
manchukuo6-May-11 8:30 
GeneralRe: pass a Size object to sendmessage [modified] Pin
DaveyM696-May-11 9:26
professionalDaveyM696-May-11 9:26 
GeneralRe: pass a Size object to sendmessage Pin
DaveyM696-May-11 10:13
professionalDaveyM696-May-11 10:13 
GeneralRe: pass a Size object to sendmessage Pin
DaveyM696-May-11 11:11
professionalDaveyM696-May-11 11:11 
GeneralRe: pass a Size object to sendmessage Pin
manchukuo6-May-11 11:14
manchukuo6-May-11 11:14 
QuestionRandom numbers [modified] Pin
meet_ssr6-May-11 2:46
meet_ssr6-May-11 2:46 
AnswerRe: Random numbers Pin
PIEBALDconsult6-May-11 2:52
mvePIEBALDconsult6-May-11 2:52 
GeneralRe: Random numbers PinPopular
David19876-May-11 2:56
David19876-May-11 2:56 
AnswerRe: Random numbers Pin
Luc Pattyn6-May-11 3:06
sitebuilderLuc Pattyn6-May-11 3:06 
GeneralRe: Random numbers PinPopular
David19876-May-11 3:45
David19876-May-11 3:45 
AnswerRe: Random numbers Pin
Luc Pattyn6-May-11 3:52
sitebuilderLuc Pattyn6-May-11 3:52 
GeneralRe: Random numbers PinPopular
David19876-May-11 3:57
David19876-May-11 3:57 
GeneralRe: Random numbers Pin
PIEBALDconsult6-May-11 16:19
mvePIEBALDconsult6-May-11 16:19 
GeneralRe: Random numbers Pin
David19876-May-11 21:41
David19876-May-11 21:41 
AnswerRe: Random numbers Pin
Orcun Iyigun6-May-11 8:37
Orcun Iyigun6-May-11 8:37 
AnswerRe: Random numbers Pin
Prasanta_Prince6-May-11 15:32
Prasanta_Prince6-May-11 15:32 
GeneralRe: Random numbers Pin
meet_ssr6-May-11 22:30
meet_ssr6-May-11 22:30 

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.