[Haskell-beginners] How do I marshall a pointer over SendMessage LPARAM or WPARAM?

Sylvain HENRY hsyl20 at gmail.com
Wed Jul 18 17:56:43 CEST 2012


Hi,

[As I've just registered to the list, I don't have the original message. 
That's why I answer to Brent insted of Simon]

By using "withCWString", your CWString may be freed before the message 
is sent. Use "newCWString" instead and "free" in your receiving code.

Cheers
Sylvain

Le 18/07/2012 17:47, Brent Yorgey a écrit :
> Hi,
>
> Just a meta-comment: this doesn't seem like a beginner question to
> me. =) Perhaps someone on this list will know the answer (and there's
> nothing wrong with asking), but for such a specific question you may
> have better luck posting to haskell-cafe or StackOverflow.
>
> -Brent
>
> On Wed, Jul 18, 2012 at 03:14:46PM +0200, Simon Peter Nicholls wrote:
>> I'm new to Haskell, and have had some good success with FFI so far,
>> but using Win32's sendMessage to send a pointer in LPARAM or WPARAM is
>> resulting in access violations at the other end.
>>
>> Is there some issue with my pointer conversions? Am I hitting some
>> restriction, or missing some compiler options?
>>
>>
>>   It's driving me pretty crazy, after a very nice start to using Haskell.
>>
>> 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
>>
>> The string will not be seen.
>>
>> Some extra notes:
>>
>> I can get wndProc messages and integral data generally.
>> The pointer values match textually at both ends when "shown" to stdout.
>> At the sending side I can pass the CWString to a regular FFI function
>> call just fine, and castUINTToPtr will give me back a functioning Ptr
>> for that call.
>>
>>   I have also tried sending to & receiving from a working C++ program,
>> without success. Access violations are reported when receiving, though
>> again the address matches up. Silence from Haskell as before, when C++
>> is sending.
>>
>> I found someone else having an issue here:
>> http://osdir.com/ml/haskell-cafe@haskell.org/2009-11/msg00731.html but
>> no solution unfortunately.
>>
>> _______________________________________________
>> Beginners mailing list
>> Beginners at haskell.org
>> http://www.haskell.org/mailman/listinfo/beginners
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners





More information about the Beginners mailing list