#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2009
    Posts
    6
    Rep Power
    0

    WindowsCE 5.0 small console application !


    Hi !

    Can anyone help me?

    I'm writting a small console application for Embedded Windows CE 5.0 PNA device with NET Compact Framework 1.0 installed.

    Because the device is low on memory, I couldn't install NET Compact Framework 2.0 or above.

    Application should only have the task to open "desktop.msc" script which should be located in the same folder (on the device) as the application.

    Here is the code I wrote using C#:
    ------------------------------
    using System.Diagnostics;
    class Program
    {
    static void Main()
    {
    Process myProc;
    myProc = Process.Start("desktop.mscr");
    myProc.Kill();
    }
    }
    ------------------------------

    The code is succesfully compiled in Visual Studio 2008, but the VS2008 is not supporting NET Comact Framework v1.0 developing, so I had to install Visual Studio 2003.


    When I compile a code in VS2003, I got this errors:

    1. The type or namespace name 'Process' could not be found (are you missing a using directive or an assembly reference?);

    2. The name 'myProc' does not exist in the class or namespace 'Program';

    3. The type or namespace name 'myProc' could not be found (are you missing a using directive or an assembly reference?)


    I just need this code to work on WinCE with NET Compact Framework v1.0.


    thx in advance !!!
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Mar 2009
    Posts
    837
    Rep Power
    527
    You need to p/invoke the CreateProcess API.

    The System.Process assemblies aren't available in CF 1.0.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2009
    Posts
    6
    Rep Power
    0
    Originally Posted by MadDogBrown
    You need to p/invoke the CreateProcess API.

    The System.Process assemblies aren't available in CF 1.0.
    I'm novice with that.

    If someone can give me some directions, or write example code.

    Language is not important, only that it support WinCE and CF 1.0 !


    thx
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Mar 2009
    Posts
    837
    Rep Power
    527
    Originally Posted by Beky.yB*
    I'm novice with that.

    If someone can give me some directions, or write example code.

    Language is not important, only that it support WinCE and CF 1.0 !


    thx
    http://community.opennetcf.com/forums/t/80.aspx
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2009
    Posts
    6
    Rep Power
    0
    Hello again.

    Thanks MadDogBrown on that example.

    Because I'm not good with C#, I didn't manage to figure out the principle.

    I think it is very simple for someone who knows C# very well.


    Is there anyone who could write this few lines for me, cause I really don't know.


    Thx in advance !
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Mar 2009
    Posts
    837
    Rep Power
    527
    Originally Posted by Beky.yB*
    Hello again.

    Thanks MadDogBrown on that example.

    Because I'm not good with C#, I didn't manage to figure out the principle.

    I think it is very simple for someone who knows C# very well.


    Is there anyone who could write this few lines for me, cause I really don't know.


    Thx in advance !
    There's an example already written in that link I gave you.

    Here:
    Code:
    public class ProcessInfo 
            { 
                public IntPtr hProcess; 
                public IntPtr hThread; 
                public Int32 dwProcessId; 
                public Int32 dwThreadId; 
            }; 
    [DllImport("CoreDll", SetLastError=true)]
            private extern static int CreateProcess( String imageName
                , String cmdLine
                , IntPtr lpProcessAttributes
                , IntPtr lpThreadAttributes
                , Int32 boolInheritHandles
                , Int32 dwCreationFlags
                , IntPtr lpEnvironment
                , IntPtr lpszCurrentDir
                , IntPtr si
                , ProcessInfo pi );
    
    
            public static bool CreateProcess( String ExeName, String CmdLine)
            {
                ProcessInfo pi = new ProcessInfo();
    
                return CreateProcess(ExeName
                    , CmdLine
                    , IntPtr.Zero
                    , IntPtr.Zero
                    , 0
                    , 0
                    , IntPtr.Zero
                    , IntPtr.Zero
                    , IntPtr.Zero
                    , pi) != 0;
            }
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2009
    Posts
    6
    Rep Power
    0
    Originally Posted by MadDogBrown
    There's an example already written in that link I gave you.

    Here:
    Code:
    public class ProcessInfo 
            { 
                public IntPtr hProcess; 
                public IntPtr hThread; 
                public Int32 dwProcessId; 
                public Int32 dwThreadId; 
            }; 
    [DllImport("CoreDll", SetLastError=true)]
            private extern static int CreateProcess( String imageName
                , String cmdLine
                , IntPtr lpProcessAttributes
                , IntPtr lpThreadAttributes
                , Int32 boolInheritHandles
                , Int32 dwCreationFlags
                , IntPtr lpEnvironment
                , IntPtr lpszCurrentDir
                , IntPtr si
                , ProcessInfo pi );
    
    
            public static bool CreateProcess( String ExeName, String CmdLine)
            {
                ProcessInfo pi = new ProcessInfo();
    
                return CreateProcess(ExeName
                    , CmdLine
                    , IntPtr.Zero
                    , IntPtr.Zero
                    , 0
                    , 0
                    , IntPtr.Zero
                    , IntPtr.Zero
                    , IntPtr.Zero
                    , pi) != 0;
            }

    Like I said, I'm a novice.

    I just need to run "desktop.mscr" script with that code.

    I copied all the code and tried to edit this line:

    return CreateProcess(desktop.mscr)

    ???

    I get this build errors:

    "Expected class, delegate, enum, interface, or struct"

    ???
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Mar 2009
    Posts
    837
    Rep Power
    527
    Originally Posted by Beky.yB*
    Like I said, I'm a novice.

    I just need to run "desktop.mscr" script with that code.

    I copied all the code and tried to edit this line:

    return CreateProcess(desktop.mscr)

    ???

    I get this build errors:

    "Expected class, delegate, enum, interface, or struct"

    ???
    You need to paste that code into a class declaration.

    I understand you're a novice, but I highly recommend that you get a basic understanding of your C# environment ASAP, or you will not get very far with any endeavor.

    If you've created a console application, the IDE should have generated a class for you, containing a function "main".

    Paste the code into that class declaration.
  16. #9
  17. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2009
    Posts
    6
    Rep Power
    0
    Originally Posted by MadDogBrown
    You need to paste that code into a class declaration.

    I understand you're a novice, but I highly recommend that you get a basic understanding of your C# environment ASAP, or you will not get very far with any endeavor.

    If you've created a console application, the IDE should have generated a class for you, containing a function "main".

    Paste the code into that class declaration.
    I copy all the code in the class {}.

    I got one building error:

    The type or namespace name 'DllImport' could not be found (are you missing a using directive or an assembly reference?)

    Then, I deleted:

    [DllImport("CoreDll", SetLastError=true)]

    ... and compiling finished without errors ....


    Now I have to start my process in the main function:

    static void Main(string[] args)
    {
    //How to start process -- what is a command for starting process ???
    }



    Thanks and sorry for questions like that, but I'm not a programmer :)
  18. #10
  19. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Mar 2009
    Posts
    837
    Rep Power
    527
    Originally Posted by Beky.yB*
    The type or namespace name 'DllImport' could not be found (are you missing a using directive or an assembly reference?)

    Then, I deleted:

    [DllImport("CoreDll", SetLastError=true)]
    If you have a smart device app in C#, you should have a reference to system.core: this assembly exposes windows CE API's, one of which is CreateProcess.

    Read the msdn for DLLImport here:
    http://msdn.microsoft.com/en-us/library/system.runtime.interopservices.dllimportattribute.aspx

    Then just call the function the same way you'd call any other c# function (something you absolutely MUST know how to do if you're to have any chance of writing an application on a win CE device)

    Thanks and sorry for questions like that, but I'm not a programmer
    Well, you are now. :D
  20. #11
  21. Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Jun 2005
    Posts
    5,964
    Rep Power
    4852
    And Lord preserve us.
    Write no code whose complexity leaves you wondering what the hell you did.
    Politically Incorrect DaWei on Pointers Grumpy on Exceptions
  22. #12
  23. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Mar 2009
    Posts
    837
    Rep Power
    527
    Originally Posted by sizablegrin
    And Lord preserve us.
    :D

    Windows CE programming is NOT suited for novices, that's for sure.

    I love how the MSDN documentation avoids culpability by stating:

    "The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements."

    It's difficult to write a non-trivial CF 1.x app without some form of PInvoke becoming necessary.

    I wonder what kind of device it is that doesn't have sufficient memory for CF 2.x?

    I've got a symbol 9060 right here on my desk that has both CF 1.1 and 3.5 loaded on it, as well as 4 custom-developed apps, and it still has memory to spare.
  24. #13
  25. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2009
    Posts
    6
    Rep Power
    0
    I finally done it. Thanks everyone ;)

    Reason for this output:

    "The type or namespace name 'DllImport' could not be found (are you missing a using directive or an assembly reference?)"

    ... is cause I didn't write this "using" directive:

    using System.Runtime.InteropServices;

    It's difficult to write a non-trivial CF 1.x app without some form of PInvoke becoming necessary.
    I realize that ;)

    I wonder what kind of device it is that doesn't have sufficient memory for CF 2.x?
    lol --> some old Personal Navigation Assistant. It doesn't have enough ROM memory, and it is not allowed to install CF on Flash memory (3MB is more required to install CF v2.0 ;D).


    Thanks guys again ;)

    ::cheers::

IMN logo majestic logo threadwatch logo seochat tools logo