Getting the String from LParam in SetWindowLong callback method


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Page 1 of 2 12 LastLast
Results 1 to 15 of 19

Thread: Getting the String from LParam in SetWindowLong callback method

  1. #1
    Sachin Nigam Guest

    Getting the String from LParam in SetWindowLong callback method

    I am building a small app that uses window's messages to communicate with
    other instances of the same application. So I declare a string message, get
    the unique ID for the message using RegisterWindowMessage..then hook the
    form using SetWindowLong & there do a SELECT CASE on the Msg passed, if its
    my defined msg, I process the WParam & LParam else pass it to the default
    windowProc using CallWindowProc.
    Now whenever I have to send a message to other instances of my app, I do a
    SendNotifyMessage using HWND_BROADCAST to do the broadcast...since any
    instance of my application can broadcast & all of them are "listening" on
    the same message, I pass the handle of form which is broadcasting as wParam.
    Everything goes on fine, if i pass numeric value in my lParam(this is where
    i want to pass the actual data in which other instances are interested)..but
    if i pass string , the CopyMemory is giving me some problem., I am not
    getting the string back.....here is the snippet of the code that i am
    using:-

    'declares
    Private Declare Function SendNotifyMessage Lib "user32" Alias
    "SendNotifyMessageA" (ByVal hwnd As Long, ByVal uMsg As Long, ByVal wParam
    As Long, ByVal lParam As Any) As Long

    Declare Sub RtlMoveMemory Lib "kernel32.dll" (Destination As Any, Source As
    Any, ByVal Length As Long)

    ''this is the signature of my Callback method:
    Public Function Callback(ByVal hwnd As Long, ByVal uMsg As Long, ByVal
    wParam As Long, ByVal lParam As Long) As Long

    & here is the part where i am doing CopyMemory aka RtlMoveMemory

    strMsgP = Space$(10)
    RtlMoveMemory ByVal StrPtr(strMsgP), ByVal lParam, Len(strMsgP) '- 1
    debug.Print strMsgP
    I have also tried RtlMoveMemory without the StrPtr w/o any luck

    'here is the BroadCast part
    num = "ABCDE"
    Call SendNotifyMessage(HWND_BROADCAST, WM_APP_TEST, myhWnd, ByVal num)

    ideas?
    -Sachin




  2. #2
    Jonathan Wood Guest

    Re: Getting the String from LParam in SetWindowLong callback method

    The problem is that strings in different processes (instances of your
    program) use a different memory space that cannot be accessed from other
    processes.

    The WM_COPYDATA message can be used to copy data between processes. I'd take
    a look at that.

    --
    Jonathan Wood
    SoftCircuits Programming
    http://www.softcircuits.com

    "Sachin Nigam" <sachin.nigam@orbit-e.com> wrote in message
    news:3d32d6f1@10.1.10.29...
    > I am building a small app that uses window's messages to communicate with
    > other instances of the same application. So I declare a string message,

    get
    > the unique ID for the message using RegisterWindowMessage..then hook the
    > form using SetWindowLong & there do a SELECT CASE on the Msg passed, if

    its
    > my defined msg, I process the WParam & LParam else pass it to the default
    > windowProc using CallWindowProc.
    > Now whenever I have to send a message to other instances of my app, I do a
    > SendNotifyMessage using HWND_BROADCAST to do the broadcast...since any
    > instance of my application can broadcast & all of them are "listening" on
    > the same message, I pass the handle of form which is broadcasting as

    wParam.
    > Everything goes on fine, if i pass numeric value in my lParam(this is

    where
    > i want to pass the actual data in which other instances are

    interested)..but
    > if i pass string , the CopyMemory is giving me some problem., I am not
    > getting the string back.....here is the snippet of the code that i am
    > using:-
    >
    > 'declares
    > Private Declare Function SendNotifyMessage Lib "user32" Alias
    > "SendNotifyMessageA" (ByVal hwnd As Long, ByVal uMsg As Long, ByVal wParam
    > As Long, ByVal lParam As Any) As Long
    >
    > Declare Sub RtlMoveMemory Lib "kernel32.dll" (Destination As Any, Source

    As
    > Any, ByVal Length As Long)
    >
    > ''this is the signature of my Callback method:
    > Public Function Callback(ByVal hwnd As Long, ByVal uMsg As Long, ByVal
    > wParam As Long, ByVal lParam As Long) As Long
    >
    > & here is the part where i am doing CopyMemory aka RtlMoveMemory
    >
    > strMsgP = Space$(10)
    > RtlMoveMemory ByVal StrPtr(strMsgP), ByVal lParam, Len(strMsgP) '- 1
    > debug.Print strMsgP
    > I have also tried RtlMoveMemory without the StrPtr w/o any luck
    >
    > 'here is the BroadCast part
    > num = "ABCDE"
    > Call SendNotifyMessage(HWND_BROADCAST, WM_APP_TEST, myhWnd, ByVal num)
    >
    > ideas?
    > -Sachin
    >
    >
    >




  3. #3
    Sachin Nigam Guest

    Re: Getting the String from LParam in SetWindowLong callback method

    hmmm...maybe the problem is since the two instances are created on different
    threads, the SendNotifyMessage in the calling instance doesnt wait for the
    "listener" and frees the memory before it is used & hence invalidating the
    memory location which held the ptr to the string.
    I am not too sure whether I can use a broadcast with WM_COPYDATA :-( (i need
    to broad-cast as i dont know how many instances of my app are running & dont
    want to do FindWindow & EnumWindows..as the above looks more like a cleaner
    way of doing it , very close to a Pub-Sub model)
    Now taking another look at SendNotifyMessage, if I can't pass strings etc if
    the windows/apps are created on different threads, then the use of it to me
    looks like very limited.
    -Sachin
    "Jonathan Wood" <jwood@softcircuits.com> wrote in message
    news:3d32dbbe@10.1.10.29...
    > The problem is that strings in different processes (instances of your
    > program) use a different memory space that cannot be accessed from other
    > processes.
    >
    > The WM_COPYDATA message can be used to copy data between processes. I'd

    take
    > a look at that.
    >
    > --
    > Jonathan Wood
    > SoftCircuits Programming
    > http://www.softcircuits.com
    >
    > "Sachin Nigam" <sachin.nigam@orbit-e.com> wrote in message
    > news:3d32d6f1@10.1.10.29...
    > > I am building a small app that uses window's messages to communicate

    with
    > > other instances of the same application. So I declare a string message,

    > get
    > > the unique ID for the message using RegisterWindowMessage..then hook the
    > > form using SetWindowLong & there do a SELECT CASE on the Msg passed, if

    > its
    > > my defined msg, I process the WParam & LParam else pass it to the

    default
    > > windowProc using CallWindowProc.
    > > Now whenever I have to send a message to other instances of my app, I do

    a
    > > SendNotifyMessage using HWND_BROADCAST to do the broadcast...since any
    > > instance of my application can broadcast & all of them are "listening"

    on
    > > the same message, I pass the handle of form which is broadcasting as

    > wParam.
    > > Everything goes on fine, if i pass numeric value in my lParam(this is

    > where
    > > i want to pass the actual data in which other instances are

    > interested)..but
    > > if i pass string , the CopyMemory is giving me some problem., I am not
    > > getting the string back.....here is the snippet of the code that i am
    > > using:-
    > >
    > > 'declares
    > > Private Declare Function SendNotifyMessage Lib "user32" Alias
    > > "SendNotifyMessageA" (ByVal hwnd As Long, ByVal uMsg As Long, ByVal

    wParam
    > > As Long, ByVal lParam As Any) As Long
    > >
    > > Declare Sub RtlMoveMemory Lib "kernel32.dll" (Destination As Any, Source

    > As
    > > Any, ByVal Length As Long)
    > >
    > > ''this is the signature of my Callback method:
    > > Public Function Callback(ByVal hwnd As Long, ByVal uMsg As Long, ByVal
    > > wParam As Long, ByVal lParam As Long) As Long
    > >
    > > & here is the part where i am doing CopyMemory aka RtlMoveMemory
    > >
    > > strMsgP = Space$(10)
    > > RtlMoveMemory ByVal StrPtr(strMsgP), ByVal lParam, Len(strMsgP) '- 1
    > > debug.Print strMsgP
    > > I have also tried RtlMoveMemory without the StrPtr w/o any luck
    > >
    > > 'here is the BroadCast part
    > > num = "ABCDE"
    > > Call SendNotifyMessage(HWND_BROADCAST, WM_APP_TEST, myhWnd, ByVal num)
    > >
    > > ideas?
    > > -Sachin
    > >
    > >
    > >

    >
    >




  4. #4
    Mark Alexander Bertenshaw Guest

    Re: Getting the String from LParam in SetWindowLong callback method

    "Sachin Nigam" <sachin.nigam@orbit-e.com> wrote in message
    news:3d32d6f1@10.1.10.29...
    > I am building a small app that uses window's messages to communicate with
    > other instances of the same application. So I declare a string message,

    get
    > the unique ID for the message using RegisterWindowMessage..then hook the
    > form using SetWindowLong & there do a SELECT CASE on the Msg passed, if

    its
    > my defined msg, I process the WParam & LParam else pass it to the default
    > windowProc using CallWindowProc.
    > Now whenever I have to send a message to other instances of my app, I do a
    > SendNotifyMessage using HWND_BROADCAST to do the broadcast...since any
    > instance of my application can broadcast & all of them are "listening" on
    > the same message, I pass the handle of form which is broadcasting as

    wParam.
    > Everything goes on fine, if i pass numeric value in my lParam(this is

    where
    > i want to pass the actual data in which other instances are

    interested)..but
    > if i pass string , the CopyMemory is giving me some problem., I am not
    > getting the string back.....here is the snippet of the code that i am
    > using:-
    >
    >
    > ideas?
    > -Sachin


    Sachin -

    There are two other ways that I can think of right away:

    First of all, if your strings is 255 characters or less, you could use
    GlobalAddAtom() to add the string onto the global atom table, and then pass
    the atom return value via your SendNotfyMessage() function. Each
    application would use GlobalGetAtomName() to retrieve the string.

    Secondly, you could use GlobalAlloc() to allocate memory shareable between
    processes, GlobalLock() to get a pointer to the memory, GlobalUnlock() to
    unlock the page, then send the handle via the SendNotifyMessage() function.

    In both cases, you would need a mechanism to know when to deallocate the
    memory.

    --
    Mark Alexander Bertenshaw
    Programmer/Analyst
    Chordiant Software, Inc.
    Brentford
    UK




  5. #5
    Jonathan Wood Guest

    Re: Getting the String from LParam in SetWindowLong callback method

    Sachin Nigam,

    > hmmm...maybe the problem is since the two instances are created on

    different
    > threads, the SendNotifyMessage in the calling instance doesnt wait for the
    > "listener" and frees the memory before it is used & hence invalidating the
    > memory location which held the ptr to the string.


    That may be an issue if you are deleting your string right away. However,
    again, there is a more fundemental issue: You cannot access memory from
    another process.

    > I am not too sure whether I can use a broadcast with WM_COPYDATA :-( (i

    need
    > to broad-cast as i dont know how many instances of my app are running &

    dont
    > want to do FindWindow & EnumWindows..as the above looks more like a

    cleaner
    > way of doing it , very close to a Pub-Sub model)


    I'm not sure if there is any problem using WM_COPYDATA with
    SendNotifyMessage. WM_COPYDATA makes a copy of the data in the new process
    but I'm not certain at what point it does that. If you deleted your data
    before that happened, the same problem could apply. I would still look into
    this approach further though because it'd be the simplest if it will work.

    Another approach might be to write something to the registry instead of
    sending data with your message. Listening applications could check the
    registry at that time.

    > Now taking another look at SendNotifyMessage, if I can't pass strings etc

    if
    > the windows/apps are created on different threads, then the use of it to

    me
    > looks like very limited.


    Welcome to 32-bit protected mode.

    --
    Jonathan Wood
    SoftCircuits Programming
    http://www.softcircuits.com




  6. #6
    Sachin Nigam Guest

    Re: Getting the String from LParam in SetWindowLong callback method

    Jonathan,
    Yep! seems like win-32 "protected" mode is the culprit ;-)
    I will take another look at WM_COPYDATA(seems more interesting than custom
    registerMsg)
    -Sachin
    "Jonathan Wood" <jwood@softcircuits.com> wrote in message
    news:3d3308ea@10.1.10.29...
    > Sachin Nigam,
    >
    > > hmmm...maybe the problem is since the two instances are created on

    > different
    > > threads, the SendNotifyMessage in the calling instance doesnt wait for

    the
    > > "listener" and frees the memory before it is used & hence invalidating

    the
    > > memory location which held the ptr to the string.

    >
    > That may be an issue if you are deleting your string right away. However,
    > again, there is a more fundemental issue: You cannot access memory from
    > another process.
    >
    > > I am not too sure whether I can use a broadcast with WM_COPYDATA :-( (i

    > need
    > > to broad-cast as i dont know how many instances of my app are running &

    > dont
    > > want to do FindWindow & EnumWindows..as the above looks more like a

    > cleaner
    > > way of doing it , very close to a Pub-Sub model)

    >
    > I'm not sure if there is any problem using WM_COPYDATA with
    > SendNotifyMessage. WM_COPYDATA makes a copy of the data in the new process
    > but I'm not certain at what point it does that. If you deleted your data
    > before that happened, the same problem could apply. I would still look

    into
    > this approach further though because it'd be the simplest if it will work.
    >
    > Another approach might be to write something to the registry instead of
    > sending data with your message. Listening applications could check the
    > registry at that time.
    >
    > > Now taking another look at SendNotifyMessage, if I can't pass strings

    etc
    > if
    > > the windows/apps are created on different threads, then the use of it to

    > me
    > > looks like very limited.

    >
    > Welcome to 32-bit protected mode.
    >
    > --
    > Jonathan Wood
    > SoftCircuits Programming
    > http://www.softcircuits.com
    >
    >
    >




  7. #7
    Juergen Thuemmler Guest

    Re: Getting the String from LParam in SetWindowLong callback method

    > Yep! seems like win-32 "protected" mode is the culprit ;-)
    > I will take another look at WM_COPYDATA(seems more interesting than custom
    > registerMsg)


    Const WM_COPYDATA = &H4A
    From SDK:
    Remarks to SendNotifyMessage:
    If you send a message in the range below WM_USER (= &H400) to the
    asynchronous message functions (PostMessage, SendNotifyMessage, and
    SendMessageCallback), its message parameters can not include pointers.
    Otherwise, the operation will fail. The functions will return before the
    receiving thread has had a chance to process the message and the sender will
    free the memory before it is used.

    Juergen.



  8. #8
    Sachin Nigam Guest

    Re: Getting the String from LParam in SetWindowLong callback method

    hmmm!! i thot of locking the memory...but then as you said the problem will
    be how do i know when to unlock the memory...as the one that i am trying to
    achieve is a Pub-Sub model where the broad-caster shouldnt care abt when the
    msg is recd by all the listeners & also since there can be n number of
    listeners, the broadcaster won't even know when all of them have processed
    the message.
    -Sachin
    "Mark Alexander Bertenshaw" <mark.bertenshaw@virgin.net> wrote in message
    news:3d32f2d7$1@10.1.10.29...
    > "Sachin Nigam" <sachin.nigam@orbit-e.com> wrote in message
    > news:3d32d6f1@10.1.10.29...
    > > I am building a small app that uses window's messages to communicate

    with
    > > other instances of the same application. So I declare a string message,

    > get
    > > the unique ID for the message using RegisterWindowMessage..then hook the
    > > form using SetWindowLong & there do a SELECT CASE on the Msg passed, if

    > its
    > > my defined msg, I process the WParam & LParam else pass it to the

    default
    > > windowProc using CallWindowProc.
    > > Now whenever I have to send a message to other instances of my app, I do

    a
    > > SendNotifyMessage using HWND_BROADCAST to do the broadcast...since any
    > > instance of my application can broadcast & all of them are "listening"

    on
    > > the same message, I pass the handle of form which is broadcasting as

    > wParam.
    > > Everything goes on fine, if i pass numeric value in my lParam(this is

    > where
    > > i want to pass the actual data in which other instances are

    > interested)..but
    > > if i pass string , the CopyMemory is giving me some problem., I am not
    > > getting the string back.....here is the snippet of the code that i am
    > > using:-
    > >
    > >
    > > ideas?
    > > -Sachin

    >
    > Sachin -
    >
    > There are two other ways that I can think of right away:
    >
    > First of all, if your strings is 255 characters or less, you could use
    > GlobalAddAtom() to add the string onto the global atom table, and then

    pass
    > the atom return value via your SendNotfyMessage() function. Each
    > application would use GlobalGetAtomName() to retrieve the string.
    >
    > Secondly, you could use GlobalAlloc() to allocate memory shareable between
    > processes, GlobalLock() to get a pointer to the memory, GlobalUnlock() to
    > unlock the page, then send the handle via the SendNotifyMessage()

    function.
    >
    > In both cases, you would need a mechanism to know when to deallocate the
    > memory.
    >
    > --
    > Mark Alexander Bertenshaw
    > Programmer/Analyst
    > Chordiant Software, Inc.
    > Brentford
    > UK
    >
    >
    >




  9. #9
    Sachin Nigam Guest

    Re: Getting the String from LParam in SetWindowLong callback method

    hmm....so as even WM_COPYDATA doesnt support pointers in the data structure,
    its just as good as a custom message.
    -Sachin
    "Juergen Thuemmler" <thue@gmx.de> wrote in message
    news:3d33a974@10.1.10.29...
    > > Yep! seems like win-32 "protected" mode is the culprit ;-)
    > > I will take another look at WM_COPYDATA(seems more interesting than

    custom
    > > registerMsg)

    >
    > Const WM_COPYDATA = &H4A
    > From SDK:
    > Remarks to SendNotifyMessage:
    > If you send a message in the range below WM_USER (= &H400) to the
    > asynchronous message functions (PostMessage, SendNotifyMessage, and
    > SendMessageCallback), its message parameters can not include pointers.
    > Otherwise, the operation will fail. The functions will return before the
    > receiving thread has had a chance to process the message and the sender

    will
    > free the memory before it is used.
    >
    > Juergen.
    >
    >




  10. #10
    Jonathan Wood Guest

    Re: Getting the String from LParam in SetWindowLong callback method

    No, WM_COPYDATA does not support embedded pointers but that shouldn't be
    that big of an issue.

    I don't know if you said what type of data you were transferring. If you are
    passing a string, then just pass that--no embedded pointers needed.
    Otherwise, you'll need to "flatten" your data out to a byte array or string.
    Either way, it's not that big of a deal.

    --
    Jonathan Wood
    SoftCircuits Programming
    http://www.softcircuits.com
    "Sachin Nigam" <sachin.nigam@netzero.net> wrote in message
    news:3d33b209@10.1.10.29...
    > hmm....so as even WM_COPYDATA doesnt support pointers in the data

    structure,
    > its just as good as a custom message.
    > -Sachin
    > "Juergen Thuemmler" <thue@gmx.de> wrote in message
    > news:3d33a974@10.1.10.29...
    > > > Yep! seems like win-32 "protected" mode is the culprit ;-)
    > > > I will take another look at WM_COPYDATA(seems more interesting than

    > custom
    > > > registerMsg)

    > >
    > > Const WM_COPYDATA = &H4A
    > > From SDK:
    > > Remarks to SendNotifyMessage:
    > > If you send a message in the range below WM_USER (= &H400) to the
    > > asynchronous message functions (PostMessage, SendNotifyMessage, and
    > > SendMessageCallback), its message parameters can not include pointers.
    > > Otherwise, the operation will fail. The functions will return before the
    > > receiving thread has had a chance to process the message and the sender

    > will
    > > free the memory before it is used.
    > >
    > > Juergen.
    > >
    > >

    >
    >




  11. #11
    Klaus H. Probst Guest

    Re: Getting the String from LParam in SetWindowLong callback method


    "Sachin Nigam" <sachin.nigam@netzero.net> wrote in message
    news:3d33b209@10.1.10.29...
    > hmm....so as even WM_COPYDATA doesnt support pointers in the data

    structure,
    > its just as good as a custom message.
    > -Sachin


    Like Jonathan says, not by default, no. But depending on the type of
    pointer, you might be able to use DuplicateHandle() to pass it. See MSDN for
    more info.

    .. . . . . . . . . . . . . . . . . . . . . .
    Klaus H. Probst, MVP
    http://www.vbbox.com/


    Please post/reply to the newsgroup(s)




  12. #12
    Sachin Nigam Guest

    Re: Getting the String from LParam in SetWindowLong callback method


    "Jonathan Wood" <jwood@softcircuits.com> wrote in message
    news:3d33ba89@10.1.10.29...
    > No, WM_COPYDATA does not support embedded pointers but that shouldn't be
    > that big of an issue.
    >
    > I don't know if you said what type of data you were transferring. If you

    are
    > passing a string, then just pass that--no embedded pointers needed.
    > Otherwise, you'll need to "flatten" your data out to a byte array or

    string.
    > Either way, it's not that big of a deal.

    I am for the time being just passing a string...but even aren't the strings
    passed as pointers?
    -Sachin
    >
    > --
    > Jonathan Wood
    > SoftCircuits Programming
    > http://www.softcircuits.com
    > "Sachin Nigam" <sachin.nigam@netzero.net> wrote in message
    > news:3d33b209@10.1.10.29...
    > > hmm....so as even WM_COPYDATA doesnt support pointers in the data

    > structure,
    > > its just as good as a custom message.
    > > -Sachin
    > > "Juergen Thuemmler" <thue@gmx.de> wrote in message
    > > news:3d33a974@10.1.10.29...
    > > > > Yep! seems like win-32 "protected" mode is the culprit ;-)
    > > > > I will take another look at WM_COPYDATA(seems more interesting than

    > > custom
    > > > > registerMsg)
    > > >
    > > > Const WM_COPYDATA = &H4A
    > > > From SDK:
    > > > Remarks to SendNotifyMessage:
    > > > If you send a message in the range below WM_USER (= &H400) to the
    > > > asynchronous message functions (PostMessage, SendNotifyMessage, and
    > > > SendMessageCallback), its message parameters can not include pointers.
    > > > Otherwise, the operation will fail. The functions will return before

    the
    > > > receiving thread has had a chance to process the message and the

    sender
    > > will
    > > > free the memory before it is used.
    > > >
    > > > Juergen.
    > > >
    > > >

    > >
    > >

    >
    >




  13. #13
    Dean Earley Guest

    Re: Getting the String from LParam in SetWindowLong callback method

    "Jonathan Wood" <jwood@softcircuits.com> wrote in message news:3d3308ea@10.1.10.29...
    > Sachin Nigam,
    >
    > > hmmm...maybe the problem is since the two instances are created on

    > different
    > > threads, the SendNotifyMessage in the calling instance doesnt wait for the
    > > "listener" and frees the memory before it is used & hence invalidating the
    > > memory location which held the ptr to the string.

    >
    > That may be an issue if you are deleting your string right away. However,
    > again, there is a more fundemental issue: You cannot access memory from
    > another process.


    Cant you pass an hwnd to a textbox and get teh string from there? IIRC, you can get the string as long as it isn't a password box.

    --
    Dean Earley (dean.earley@icode.co.uk)
    i-Catcher Development Team

    iCode Systems



  14. #14
    Mattias Sjögren Guest

    Re: Getting the String from LParam in SetWindowLong callback method

    Mark,

    >Secondly, you could use GlobalAlloc() to allocate memory shareable between
    >processes, GlobalLock() to get a pointer to the memory, GlobalUnlock() to
    >unlock the page, then send the handle via the SendNotifyMessage() function.


    Don't think that would work. There's nothing global about the
    Global*() functions in Win32. MSDN says

    "Win32 memory management does not provide a separate local heap and
    global heap, as 16-bit Windows does. As a result, there is no
    difference between the memory objects allocated by the GlobalAlloc and
    LocalAlloc functions. [...]

    Memory objects allocated by GlobalAlloc and LocalAlloc are in private,
    committed pages with read/write access that cannot be accessed by
    other processes. Memory allocated by using GlobalAlloc with
    GMEM_DDESHARE is not actually shared globally as it is in 16-bit
    Windows. This value has no effect and is available only for
    compatibility. Applications requiring shared memory for other purposes
    must use file-mapping objects. Multiple processes can map a view of
    the same file-mapping object to provide named shared memory. For more
    information, see File Mapping."


    Mattias

    ===
    Mattias Sjögren (VB MVP)
    mattias @ mvps.org
    http://www.msjogren.net/dotnet/

  15. #15
    Mark Alexander Bertenshaw Guest

    Re: Getting the String from LParam in SetWindowLong callback method

    "Mattias Sjögren" <mattias.dont.want.spam@mvps.org> wrote in message
    news:3d33fa0a$1@10.1.10.29...
    > Mark,
    >
    > >Secondly, you could use GlobalAlloc() to allocate memory shareable

    between
    > >processes, GlobalLock() to get a pointer to the memory, GlobalUnlock() to
    > >unlock the page, then send the handle via the SendNotifyMessage()

    function.
    >
    > Don't think that would work. There's nothing global about the
    > Global*() functions in Win32. MSDN says
    >
    > "Win32 memory management does not provide a separate local heap and
    > global heap, as 16-bit Windows does. As a result, there is no
    > difference between the memory objects allocated by the GlobalAlloc and
    > LocalAlloc functions. [...]
    >
    > Memory objects allocated by GlobalAlloc and LocalAlloc are in private,
    > committed pages with read/write access that cannot be accessed by
    > other processes. Memory allocated by using GlobalAlloc with
    > GMEM_DDESHARE is not actually shared globally as it is in 16-bit
    > Windows. This value has no effect and is available only for
    > compatibility. Applications requiring shared memory for other purposes
    > must use file-mapping objects. Multiple processes can map a view of
    > the same file-mapping object to provide named shared memory. For more
    > information, see File Mapping."
    >
    >
    > Mattias


    **** - I seemed to have missed out a few words when I read that page <g>. I
    assumed that it was global because why else go through all that fuss
    allocating blocks when using the Clipboard?

    --
    Mark Alexander Bertenshaw
    Programmer/Analyst
    Chordiant Software, Inc.
    Brentford
    UK



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center