I have made a solution to the args problem. To review, if the latest code on 
github is used on Ubuntu, and if agreements are passed on the command line of 
the application, wxHaskell does a “getArgs” and passes them on, and then there 
is an error on the command line. On Windows with the most recent wxWidgets 
code, it pops a similar dialog.

To get around the problem, I created startExt, runExt, and argsOnInitExt so 
that I can pass a [String]. This allows me to filter out agreements not 
destined for wx.

I have attached a patch below to show what I did.

Perhaps one of the developers can give this some consideration. I can certainly 
post the patch in the bug tracker if desired, just tell me where it is. I am 
not sure if the one on source forge is in use or not, as the last date is Aug 
2014.

Mike

>From 13bd27df2e54972244a59fc38eccc7b9790a176c Mon Sep 17 00:00:00 2001
From: Michael Jones <mjo...@linear.com>
Date: Sat, 4 Apr 2015 13:10:49 -0600
Subject: [PATCH] Offer command line args passing at startup

---
 wx/src/Graphics/UI/WX.hs                        |  5 +++++
 wxcore/src/haskell/Graphics/UI/WXCore.hs        | 10 +++++++++-
 wxcore/src/haskell/Graphics/UI/WXCore/Events.hs | 14 +++++++++++++-
 3 files changed, 27 insertions(+), 2 deletions(-)

diff --git a/wx/src/Graphics/UI/WX.hs b/wx/src/Graphics/UI/WX.hs
index f310e63..7827b2f 100644
--- a/wx/src/Graphics/UI/WX.hs
+++ b/wx/src/Graphics/UI/WX.hs
@@ -17,6 +17,7 @@ functionality provided by the "Graphics.UI.WXCore" library.
 module Graphics.UI.WX
   ( -- * Functions
     start
+  , startExt
     -- * Modules
   , module Graphics.UI.WX.Types
   , module Graphics.UI.WX.Attributes
@@ -58,3 +59,7 @@ import Graphics.UI.WXCore
 start :: IO a -> IO ()
 start io
   = run (unitIO io)
+
+startExt :: [String] -> IO a -> IO ()
+startExt args io
+  = runExt args (unitIO io)
\ No newline at end of file
diff --git a/wxcore/src/haskell/Graphics/UI/WXCore.hs 
b/wxcore/src/haskell/Graphics/UI/WXCore.hs
index a6381b2..b276433 100644
--- a/wxcore/src/haskell/Graphics/UI/WXCore.hs
+++ b/wxcore/src/haskell/Graphics/UI/WXCore.hs
@@ -40,6 +40,7 @@ module Graphics.UI.WXCore
 
         -- * Run
         , run
+        , runExt
         ) where
 
 import System.Mem( performGC )
@@ -77,6 +78,13 @@ run init
        performGC
        performGC
 
-
+runExt :: [String] -> IO a -> IO ()
+runExt args init
+  = do enableGUI
+       appOnInitExt args (do wxcAppInitAllImageHandlers
+                             init
+                             return ())
+       performGC
+       performGC
 
 
diff --git a/wxcore/src/haskell/Graphics/UI/WXCore/Events.hs 
b/wxcore/src/haskell/Graphics/UI/WXCore/Events.hs
index 12ca0a3..668761a 100644
--- a/wxcore/src/haskell/Graphics/UI/WXCore/Events.hs
+++ b/wxcore/src/haskell/Graphics/UI/WXCore/Events.hs
@@ -222,6 +222,7 @@ module Graphics.UI.WXCore.Events
 
         -- * Primitive
         , appOnInit
+        , appOnInitExt
 
         -- ** Client data
         , treeCtrlSetItemClientData
@@ -2820,7 +2821,18 @@ appOnInit init
   where
     onDelete ownerDeleted
       = init
-           
+          
+appOnInitExt :: [String] -> IO () -> IO ()
+appOnInitExt args init
+  = do closure  <- createClosure (return () :: IO ()) onDelete (\ev -> return 
())   -- run init on destroy !
+       progName <- getProgName
+       argv     <- mapM newCWString (progName:args)
+       let argc = length argv
+       withArray (argv ++ [nullPtr]) $ \cargv -> wxcAppInitializeC closure 
argc cargv
+       mapM_ free argv
+  where
+    onDelete ownerDeleted
+      = init 
 
 
 
------------------------------------------------------------------------------------------
-- 
1.9.1



On Mar 28, 2015, at 7:58 PM, Michael Jones <m...@proclivis.com> wrote:

> 
> I also notice that if I use the git repo:head for wxHaskell on Linux, I get a 
> similar error + Usage as windows, but on the command line. The version of 
> wxHaskell that cabal fetches does not have this problem.
> 
> On windows, I took the repo:head because the released wxHaskell that cabal 
> downloads had a compile failure for a ‘long long’
> 
> So perhaps there something that has changed in wxHaskell that causes a 
> generic problem.
> 
> 
> 
> On Mar 28, 2015, at 7:40 PM, Michael Jones <m...@proclivis.com> wrote:
> 
>> There is a response from wxWidgets trac
>> 
>> #16935:
>> http://trac.wxwidgets.org/ticket/16935#comment:1
>> 
>> On Mar 28, 2015, at 5:12 PM, Henk-Jan van Tuyl <hjgt...@chello.nl> wrote:
>> 
>>> On Wed, 25 Mar 2015 22:57:12 +0100, Michael Jones <m...@proclivis.com>
>>> wrote:
>>> 
>>>> On Win 7...
>>>> 
>>>> The latest code on github seems to result in a wxWidgets call to LPTSTR 
>>>> WINAPI GetCommandLine(void);
>>>> 
>>>> This results in popping a dialog complaining about command options. On 
>>>> Linux this does not happen. Looks like wxWidgets is trying to use this 
>>>> call to deal with unicode, but it unfortunately bypasses the Haskell 
>>>> argument mechanism and grabs everything including +/-RTS and passes it to 
>>>> wxWidgets for consideration. Perhaps wxHaskell should manage the arguments 
>>>> and strip off any arguments that are not destined for wxWidgets, or at 
>>>> least let the Haskell code intercept and manage the problem.
>>>> 
>>>> Is there some way to effect the wxHaskell initialization so that it 
>>>> prevents this call, so that an wxHaskell application running on Windows 7 
>>>> can accept command line arguments properly?
>>>> 
>>>> I handling initialization with a start call within Haskell. Perhaps there 
>>>> is an alternate approach I am unaware of.
>>> 
>>> I am trying to change the internal representation of the command line, but 
>>> it is likely to fail. The best thing would to let the wxWidgets people 
>>> change the behavior of wxWidgets to let it be the same in Windows as in 
>>> Linux. You could write a ticket for this[0]. To be sure this problems isn't 
>>> forgotten, you should also write a wxHaskell ticket[1], preferably linking 
>>> to the wxWidgets ticket.
>>> 
>>> The message about the unexpected parameter stems from 
>>> wxWidgets\src\common\cmdline.cpp , method wxCmdLineParser::Parse(bool 
>>> showUsage) . Maybe it is possible to specify a wxCmdLineParser, that 
>>> handles the +RTS parameters correctly, in wxHaskell.
>>> 
>>> Regards,
>>> Henk-Jan van Tuyl
>>> 
>>> 
>>> [0] http://trac.wxwidgets.org/
>>> [1] http://sourceforge.net/p/wxhaskell/_list/tickets
>>> 
>>> -- 
>>> Folding@home
>>> What if you could share your unused computer power to help find a cure? In
>>> just 5 minutes you can join the world's biggest networked computer and get
>>> us closer sooner. Watch the video.
>>> http://folding.stanford.edu/
>>> 
>>> 
>>> http://Van.Tuyl.eu/
>>> http://members.chello.nl/hjgtuyl/tourdemonad.html
>>> Haskell programming
>>> --
>> 
>> 
>> 
>> ------------------------------------------------------------------------------
>> Dive into the World of Parallel Programming The Go Parallel Website, 
>> sponsored
>> by Intel and developed in partnership with Slashdot Media, is your hub for 
>> all
>> things parallel software development, from weekly thought leadership blogs to
>> news, videos, case studies, tutorials and more. Take a look and join the 
>> conversation now. http://goparallel.sourceforge.net/
>> _______________________________________________
>> wxhaskell-users mailing list
>> wxhaskell-users@lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/wxhaskell-users
> 
> 
> 
> ------------------------------------------------------------------------------
> Dive into the World of Parallel Programming The Go Parallel Website, sponsored
> by Intel and developed in partnership with Slashdot Media, is your hub for all
> things parallel software development, from weekly thought leadership blogs to
> news, videos, case studies, tutorials and more. Take a look and join the 
> conversation now. http://goparallel.sourceforge.net/
> _______________________________________________
> wxhaskell-users mailing list
> wxhaskell-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/wxhaskell-users



------------------------------------------------------------------------------
Dive into the World of Parallel Programming The Go Parallel Website, sponsored
by Intel and developed in partnership with Slashdot Media, is your hub for all
things parallel software development, from weekly thought leadership blogs to
news, videos, case studies, tutorials and more. Take a look and join the 
conversation now. http://goparallel.sourceforge.net/
_______________________________________________
wxhaskell-users mailing list
wxhaskell-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wxhaskell-users

Reply via email to