none
Windows Embedded Compact 2013, launch a C# application at OS startup RRS feed

  • Question

  • HI all,

    I've a problem when trying to launch a C# application at WEC2013 OS startup from a SD Card.

    If the SD Card is formatted in FAT, the application is started.

    If the SD Card is formatted in FAT32, the application Doesn't start.

    The Platform Builder OSDesign.reg contains this entry to launch my application :

    [HKEY_LOCAL_MACHINE\init]
    	"Launch80"="\\Storage Card\\Deepstar\\DeepStar.exe"
    	"Depend80"=hex:1E,00, 3C,00		; Dépendances à servicesStart.exe, gwes.dll, etc.
    

    Perhaps, the FAT is faster than the FAT32 and .Net has enough time to start before application is started by the OS ?

    Thank you for your help.

    Best regards


    Friday, January 6, 2017 9:40 AM

Answers

  • dati01

    You need to write a small native application (C/C++) to start your C# application(s).  The system isn't ready yet to start your C# app when the Init key is processed.  You may need to wait for some APIs to become ready before starting the C# app.



    Bruce Eitman (eMVP)
    Senior Engineer
    Bruce.Eitman AT Eurotech DOT com
    My BLOG http://geekswithblogs.net/bruceeitman
    I work for Eurotech

    • Marked as answer by dati01 Friday, January 6, 2017 3:17 PM
    Friday, January 6, 2017 1:37 PM
    Moderator

All replies

  • dati01

    You need to write a small native application (C/C++) to start your C# application(s).  The system isn't ready yet to start your C# app when the Init key is processed.  You may need to wait for some APIs to become ready before starting the C# app.



    Bruce Eitman (eMVP)
    Senior Engineer
    Bruce.Eitman AT Eurotech DOT com
    My BLOG http://geekswithblogs.net/bruceeitman
    I work for Eurotech

    • Marked as answer by dati01 Friday, January 6, 2017 3:17 PM
    Friday, January 6, 2017 1:37 PM
    Moderator
  • Thank you Bruce for the clue.

    I found answers following your recommandation :

    The SD Card Filesystem was not ready to launch applications from SD Card (FAT32 is slower than FAT).

    I made a small program included into the OS that is launched by the OS. This program check that some API are ready to be used.

    In C# :

    [DllImport("coredll.dll", CharSet = CharSet.Unicode, EntryPoint = "WaitForAPIReady")]
    private static extern int WaitForAPIReady(int dwAPISlotIndex, int dwTimeout);
    
    
    	class Pkfuncs
    	{
    		public const int SH_WIN32 = 0;
    		public const int SH_CURTHREAD    = 1;
    		public const int SH_CURPROC      = 2;
    		public const int SH_CURTOKEN     = 3;
    		public const int HT_EVENT        = 4;  // Event handle type
    		public const int HT_MUTEX        = 5;  // Mutex handle type
    		public const int HT_APISET       = 6;  // kernel API set handle type
    		public const int HT_FILE         = 7;  // open file handle type
    		public const int HT_FIND         = 8;  // FindFirst handle type
    		public const int HT_DBFILE       = 9;  // open database handle type
    		public const int HT_DBFIND       = 10; // database find handle type
    		public const int HT_SOCKET       = 11; // WinSock open socket handle type
    		public const int HT_CRITSEC      = 12; // Critical section
    		public const int HT_SEMAPHORE    = 13; // Semaphore handle type
    		public const int HT_FSMAP        = 14; // mapped files
    		public const int HT_WNETENUM     = 15; // Net Resource Enumeration
    		public const int HT_AFSVOLUME    = 16; // file system volume handle type
    
    		public const int SH_FIRST_OS_API_SET = 80;      // 1st OS non-handle based API set
    		public const int SH_LAST_NOTIFY = SH_FIRST_OS_API_SET;    // Last set notified on Thread/Process Termination
    
    		public const int SH_GDI			 = (SH_LAST_NOTIFY + 0);
    		public const int SH_WMGR         = (SH_LAST_NOTIFY+1) ;
    		public const int SH_WNET         = (SH_LAST_NOTIFY+2) ;  // WNet APIs for network redirector
    		public const int SH_COMM         = (SH_LAST_NOTIFY+3) ;  // Communications not "COM"
    		public const int SH_FILESYS_APIS = (SH_LAST_NOTIFY+4) ;  // File system APIS
    		public const int SH_SHELL        = (SH_LAST_NOTIFY+5) ;
    		public const int SH_DEVMGR_APIS  = (SH_LAST_NOTIFY+6) ;  // File system device manager
    		public const int SH_TAPI         = (SH_LAST_NOTIFY+7) ;
    		public const int SH_CPROG        = (SH_LAST_NOTIFY+8) ;  // Cprog APIS
    		public const int SH_SERVICES     = (SH_LAST_NOTIFY+10);
    		public const int SH_DDRAW        = (SH_LAST_NOTIFY+11);
    		public const int SH_D3DM         = (SH_LAST_NOTIFY+12);
    		public const int SH_GWEUSER      = (SH_LAST_NOTIFY+13);
    		public const int SH_CONNMGR_LEGAC= (SH_LAST_NOTIFY+14);  // ConnMgr legacy API
    		public const int SH_DMSRV        = (SH_LAST_NOTIFY+15);  // Device Management APIs
    		public const int SH_INPUT        = (SH_LAST_NOTIFY+16);  // Input API
    		public const int SH_COMPOSITOR   = (SH_LAST_NOTIFY+17);  // Window Composition
    		public const int SH_NETCF        = (SH_LAST_NOTIFY+18);  // .NET Compact Framework sever
    	}
    
    
    // Waits that some Windows essentials APIs are ready
    // See WaitForAPIReady (Compact 2013) API on the Web
    int API_TIMEOUT = 20 * 1000;  // In ms
    bool ret = true;
    ret &= WaitForAPIReady(Pkfuncs.HT_WNETENUM, API_TIMEOUT) == WAIT_OBJECT_0;      // Net Resource Enumeration
    ret &= WaitForAPIReady(Pkfuncs.HT_AFSVOLUME, API_TIMEOUT) == WAIT_OBJECT_0;     // file system volume handle type
    ret &= WaitForAPIReady(Pkfuncs.SH_COMM, API_TIMEOUT) == WAIT_OBJECT_0;          // Communications not "COM"
    ret &= WaitForAPIReady(Pkfuncs.SH_FILESYS_APIS, API_TIMEOUT) == WAIT_OBJECT_0;  // File system APIS
    ret &= WaitForAPIReady(Pkfuncs.SH_DEVMGR_APIS, API_TIMEOUT) == WAIT_OBJECT_0;   // File system device manager
    ret &= WaitForAPIReady(Pkfuncs.SH_NETCF, API_TIMEOUT) == WAIT_OBJECT_0;         // .NET Compact Framework sever
    
    // Start process on the SD Card
    Process.Start(@"\Storage Card\MyProgram.exe", null);
    Hope this will be useful.

    Best regards

    Friday, January 6, 2017 3:32 PM