On Wed, 2012-07-18 at 18:22 +0200, Simon Peter Nicholls wrote:

> Some "sending" code:
> 
>             Foreign.C.String.withCWString "frustrator" $ \s -> do
>                 let wParam = System.Win32.Types.castPtrToUINT s ::
> System.Win32.Types.WPARAM
>                 Graphics.Win32.sendMessage wnd Graphics.Win32.wM_APP wParam 0
> 
> wndProc "receiving" code:
> 
>     | wmsg == Graphics.Win32.wM_APP = do
>         s <- peekCWString $ System.Win32.Types.castUINTToPtr wParam
>         putStrLn s
>         return 0
> 

>From the docs
( 
http://hackage.haskell.org/packages/archive/base/4.5.1.0/doc/html/Foreign-C-String.html#v:withCWString
 ):

> the memory is freed when the subcomputation terminates (either
normally or via an exception), so the pointer to the temporary storage
must not be used after this

I'm noy a windows guru, but I assume that `sendMessage` just puts the
message into a queue and exits. So, you receive a pointer to already
deallocated memory.


_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to