Hi again,

I forgot to add a new file to the patch.  Here it is attached.
It contains definitions for functions not found yet on the rapi.h header from Cygwin (w32api), among
other compatibility things.

Cheers,
Pedro Alves

Pedro Alves escreveu:
Hi guys,

The CeGCC project [1] has a need for a consistent set of rapi tools
across linux and windows hosts.  I took a stab at porting the
librapi2/tools to Cygwin, and the attached patch is the result.  The
biggest change, is that I made the tools dir independent of its
parent dir autoconf wise.  Ideally it would be moved to the root dir,
or somewhere  else not directly under librapi2.  This also has the
advantage of having an example of an app that is ported to native
rapi.dll and to the synce api, without much effort.
I would be happy to clean this patch up before inclusion.  I am seeking
for opinions from the maintainers to understand if such a port
would be accepted.

I have been using this port for over two months to run the gdb testsuite
against MSFT's WinCE emulator. The testsuite copies (pcp) and runs (prun)
a few thousand apps in a single run in series without problems.

Cheers,
Pedro Alves

P.S.: Is this list still appropriate?  Seem like SynCE-windowsmobile2005
list has much more traffic these days.  Also, should I rebase my patch
against any branch?  I'm confused as to where is the main development
going on these days. (Granted; I didn't look enough, I'm lazy :) )

[1] http://cegcc.sourceforge.net

------------------------------------------------------------------------

Index: prm.c
===================================================================
--- prm.c       (revision 2623)
+++ prm.c       (working copy)
@@ -1,7 +1,9 @@
 /* $Id$ */
 #include "pcommon.h"
 #include <rapi.h>
+#ifndef WIN32
 #include <synce_log.h>
+#endif
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -69,14 +71,17 @@ static bool handle_parameters(int argc, int main(int argc, char** argv)
 {
        int result = 1;
-        char* path = NULL;
-        RapiConnection* connection = NULL;
+       char* path = NULL;
+#ifndef WIN32
+       RapiConnection* connection = NULL;
+#endif
        HRESULT hr;
        WCHAR* wide_path = NULL;
        
        if (!handle_parameters(argc, argv, &path))
                goto exit;
+#ifndef WIN32
         if ((connection = rapi_connection_from_path(devpath)) == NULL)
         {
fprintf(stderr, "%s: Could not find configuration at path '%s'\n", @@ -85,6 +90,7 @@ int main(int argc, char** argv)
           goto exit;
         }
         rapi_connection_select(connection);
+#endif
        hr = CeRapiInit();
if (FAILED(hr))
Index: pls.c
===================================================================
--- pls.c       (revision 2623)
+++ pls.c       (working copy)
@@ -1,7 +1,9 @@
 /* $Id$ */
 #include "pcommon.h"
 #include <rapi.h>
+#ifndef WIN32
 #include <synce_log.h>
+#endif
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -227,14 +229,16 @@ bool list_directory(WCHAR* directory)
 int main(int argc, char** argv)
 {
        int result = 1;
-        RapiConnection* connection = NULL;
+#ifndef WIN32
+       RapiConnection* connection = NULL;
+#endif
        char* path = NULL;
        WCHAR* wide_path = NULL;
        HRESULT hr;
        
        if (!handle_parameters(argc, argv, &path))
                goto exit;
-
+#ifndef WIN32
         if ((connection = rapi_connection_from_path(devpath)) == NULL)
         {
fprintf(stderr, "%s: Could not find configuration at path '%s'\n", @@ -243,6 +247,7 @@ int main(int argc, char** argv)
           goto exit;
         }
         rapi_connection_select(connection);
+#endif
        hr = CeRapiInit();
if (FAILED(hr))
Index: pmv.c
===================================================================
--- pmv.c       (revision 2623)
+++ pmv.c       (working copy)
@@ -1,7 +1,9 @@
 /* $Id$ */
 #include "pcommon.h"
 #include <rapi.h>
+#ifndef WIN32
 #include <synce_log.h>
+#endif
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -70,7 +72,9 @@ static bool handle_parameters(int argc, int main(int argc, char** argv)
 {
        int result = 1;
-        RapiConnection* connection = NULL;
+#ifndef WIN32
+       RapiConnection* connection = NULL;
+#endif
        char* source = NULL;
        char* dest = NULL;
        HRESULT hr;
@@ -80,6 +84,7 @@ int main(int argc, char** argv)
        if (!handle_parameters(argc, argv, &source, &dest))
                goto exit;
+#ifndef WIN32
         if ((connection = rapi_connection_from_path(devpath)) == NULL)
         {
fprintf(stderr, "%s: Could not find configuration at path '%s'\n", @@ -88,6 +93,7 @@ int main(int argc, char** argv)
           goto exit;
         }
         rapi_connection_select(connection);
+#endif
        hr = CeRapiInit();
if (FAILED(hr))
Index: pstatus.c
===================================================================
--- pstatus.c   (revision 2623)
+++ pstatus.c   (working copy)
@@ -1,6 +1,9 @@
 /* $Id$ */
+#include "pcommon.h"
 #include <rapi.h>
+#ifndef WIN32
 #include <synce_log.h>
+#endif
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -210,7 +213,14 @@ void print_battery_status(const char* na
 int main(int argc, char** argv)
 {
   int result = 1;
+#ifndef WIN32
   RapiConnection* connection = NULL;
+#else
+  typedef BOOL __stdcall (*CeGetSystemMemoryDivision_t)( LPDWORD, LPDWORD, 
LPDWORD);
+  HINSTANCE rapidll = LoadLibrary ("rapi.dll");
+  CeGetSystemMemoryDivision_t CeGetSystemMemoryDivision
+      = (CeGetSystemMemoryDivision_t)GetProcAddress(rapidll, (LPCSTR)19);
+#endif
   HRESULT hr;
   CEOSVERSIONINFO version;
   SYSTEM_INFO system;
@@ -221,6 +231,7 @@ int main(int argc, char** argv)
   if (!handle_parameters(argc, argv))
     goto exit;
+#ifndef WIN32
   if ((connection = rapi_connection_from_path(devpath)) == NULL)
   {
fprintf(stderr, "%s: Could not find configuration at path '%s'\n", @@ -229,6 +240,7 @@ int main(int argc, char** argv)
     goto exit;
   }
   rapi_connection_select(connection);
+#endif
   hr = CeRapiInit();
if (FAILED(hr))
@@ -334,9 +346,21 @@ int main(int argc, char** argv)
   }
   else
   {
- fprintf(stderr, "%s: Failed to get battery status: %s\n", - argv[0],
-        synce_strerror(CeGetLastError()));
+       DWORD err = CeGetLastError();
+       if (err == ERROR_SERVICE_DOES_NOT_EXIST)
+       {
+           printf(
+               "Power\n"
+               "=====\n"
+               );
+           printf("Not supported\n\n");
+       }
+       else
+       {
+ fprintf(stderr, "%s: Failed to get battery status: %s\n", + argv[0],
+                synce_strerror(err));
+       }
   }
/*
@@ -378,6 +402,10 @@ int main(int argc, char** argv)
exit:
   CeRapiUninit();
+#ifndef WIN32
   rapi_connection_destroy(connection);
+#else
+  FreeLibrary(rapidll);
+#endif
   return result;
 }
Index: pkillall.c
===================================================================
--- pkillall.c  (revision 2623)
+++ pkillall.c  (working copy)
@@ -1,5 +1,8 @@
+#include "pcommon.h"
 #include <rapi.h>
+#ifndef WIN32
 #include <synce_log.h>
+#endif
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -57,12 +60,19 @@ static bool handle_parameters(int argc, int main(int argc, char** argv)
 {
   int result = 0;
+#ifndef WIN32
   RapiConnection* connection = NULL;
+#else
+  typedef BOOL __stdcall (*CeKillAllApps_t) (void);
+  HINSTANCE rapidll = LoadLibrary ("rapi.dll");
+  CeKillAllApps_t CeKillAllApps = (CeKillAllApps_t)GetProcAddress(rapidll, 
(LPCSTR)24);
+#endif
   HRESULT hr;
if (!handle_parameters(argc, argv))
     goto exit;
+#ifndef WIN32
   if ((connection = rapi_connection_from_path(devpath)) == NULL)
   {
fprintf(stderr, "%s: Could not find configuration at path '%s'\n", @@ -71,6 +81,7 @@ int main(int argc, char** argv)
     goto exit;
   }
   rapi_connection_select(connection);
+#endif
   hr = CeRapiInit();
   if (FAILED(hr))
   {
@@ -90,7 +101,10 @@ int main(int argc, char** argv)
exit:
   CeRapiUninit();
+#ifndef WIN32
   rapi_connection_destroy(connection);
-
+#else
+  FreeLibrary(rapidll);
+#endif
   return result;
 }
Index: pcommon.c
===================================================================
--- pcommon.c   (revision 2623)
+++ pcommon.c   (working copy)
@@ -1,12 +1,100 @@
 /* $Id$ */
 #include "pcommon.h"
-#include "rapi.h"
-#include <synce_log.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#if !defined (WIN32)
+#include "rapi.h"
+#include <synce_log.h>
+#else
+
+static void
+_wce_strerror (char *buf, DWORD error)
+{
+    WCHAR* msgbuf;
+    DWORD chars = FormatMessageW (
+                FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
+                NULL,
+                error,
+                0, /* Default language */
+                (LPVOID)&msgbuf,
+                0,
+                NULL);
+    if (chars == 0)
+      {
+ /* Handle a few important cases ourselves when the + device doesn't support them (like mine). */
+          switch (error)
+          {
+          case WSAECONNRESET:
+              sprintf (buf, "WSAECONNRESET (%ld)", error);
+              break;
+          default:
+              sprintf (buf, "unknown error (%ld)", error);
+          }
+      }
+    else
+      {
+        /* There is an \r\n appended; Kill it.  */
+        if (chars >= 2)
+          msgbuf[chars - 2] = 0;
+        wcstombs(buf, msgbuf, chars + 1);
+        LocalFree (msgbuf);
+      }
+}
+
+const char *
+synce_strerror (DWORD err)
+{
+  static char buf[1024];
+  sprintf (buf, "err: %u, ", (int)err);
+  char* b = buf + strlen (buf);
+  _wce_strerror (b, err);
+  size_t len = strlen (b);
+  b[len] = '\n';
+  b[len + 1] = 0;
+  return buf;
+}
+
+WCHAR* wstr_from_current(const char* str)
+{
+    size_t count = strlen (str) + 1;
+    WCHAR* wstr = malloc (count * 2);
+    mbstowcs(wstr, str, count);
+    return wstr;
+}
+
+char* wstr_to_current(const WCHAR* wstr)
+{
+    size_t count = wcslen (wstr) + 1;
+    char* str = malloc (count);
+    wcstombs(str, wstr, count);
+    return str;
+}
+
+WCHAR* win32_wcsdup(const WCHAR* org)
+{
+    size_t count = wcslen (org) + 1;
+    WCHAR* cpy = malloc (count * 2);
+    wcscpy(cpy, org);
+    return cpy;
+}
+
+
+static int log_level;
+void synce_log_set_level(int level)
+{
+    log_level = level;
+}
+
+#endif
+
+#if !defined (WIN32)
 #define WIDE_BACKSLASH   htole16('\\')
+#else
+#define WIDE_BACKSLASH   '\\'
+#endif
void convert_to_backward_slashes(char* path)
 {
@@ -81,12 +169,12 @@ static void anyfile_remote_close(AnyFile
static bool anyfile_remote_read(AnyFile* file, unsigned char* buffer, size_t bytes, size_t* bytesAccessed)
 {
-       return CeReadFile(file->handle.remote, buffer, bytes, bytesAccessed, 
NULL);
+       return CeReadFile(file->handle.remote, buffer, bytes, 
(DWORD*)bytesAccessed, NULL);
 }
static bool anyfile_remote_write(AnyFile* file, unsigned char* buffer, size_t bytes, size_t* bytesAccessed)
 {
-       return CeWriteFile(file->handle.remote, buffer, bytes, bytesAccessed, 
NULL);
+       return CeWriteFile(file->handle.remote, buffer, bytes, 
(DWORD*)bytesAccessed, NULL);
 }
static void anyfile_local_close(AnyFile* file)
@@ -157,16 +245,17 @@ static AnyFile* anyfile_local_open(const
        switch (access)
        {
case READ: - file->handle.local = fopen(filename, "r");
+                       file->handle.local = fopen(filename, "rb");
                        break;
case WRITE: - file->handle.local = fopen(filename, "w");
+                       file->handle.local = fopen(filename, "wb");
                        break;
        }
        
        if (NULL == file->handle.local)
        {
+        perror("open file error\n");
                free(file);
                file = NULL;
        }
Index: pcommon.h
===================================================================
--- pcommon.h   (revision 2623)
+++ pcommon.h   (working copy)
@@ -1,7 +1,12 @@
 #ifndef __pcommon_h__
 #define __pcommon_h__
+#if !defined (WIN32) && !defined (__CYGWIN__)
 #include <synce.h>
+#else
+#include <windows.h>
+#include "wincompat.h"
+#endif
#ifdef __cplusplus
 extern "C"
Index: rapiconfig.c
===================================================================
--- rapiconfig.c        (revision 2623)
+++ rapiconfig.c        (working copy)
@@ -1,7 +1,10 @@
 /* $Id$ */
+#include "pcommon.h"
 #include <rapi.h>
+#ifndef WIN32
 #include <synce.h>
 #include <synce_log.h>
+#endif
 #include <errno.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -104,7 +107,13 @@ int main(int argc, char** argv)
   long bytes_left;
   LPWSTR config = NULL;
   LPWSTR reply = NULL;
+#ifndef WIN32
   RapiConnection* connection = NULL;
+#else
+  typedef HRESULT __stdcall (*CeProcessConfig_t) (LPCWSTR, DWORD, LPWSTR*);
+  HINSTANCE rapidll = LoadLibrary ("rapi.dll");
+  CeProcessConfig_t CeProcessConfig = 
(CeProcessConfig_t)GetProcAddress(rapidll, (LPCSTR)25);
+#endif
/*
      Initialization
@@ -171,7 +180,7 @@ int main(int argc, char** argv)
/* Do the bossanova
    */
-
+#ifndef WIN32
         if ((connection = rapi_connection_from_path(devpath)) == NULL)
         {
fprintf(stderr, "%s: Could not find configuration at path '%s'\n", @@ -180,6 +189,7 @@ int main(int argc, char** argv)
           goto exit;
         }
         rapi_connection_select(connection);
+#endif
        hr = CeRapiInit();
if (FAILED(hr))
@@ -203,6 +213,9 @@ int main(int argc, char** argv)
exit:
   CeRapiUninit();
+#ifdef WIN32
+  FreeLibrary(rapidll);
+#endif
if (buffer)
     free(buffer);
Index: pcp.c
===================================================================
--- pcp.c       (revision 2623)
+++ pcp.c       (working copy)
@@ -1,20 +1,28 @@
 /* $Id$ */
 #include "pcommon.h"
 #include <rapi.h>
+
+#if !defined (WIN32)
 #include <synce_log.h>
+#else
+#include "wincompat.h"
+#endif
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
+#include <time.h>
char* devpath = NULL;
+bool verbose = false;
static void show_usage(const char* name)
 {
        fprintf(stderr,
                        "Syntax:\n"
                        "\n"
-                       "\t%s [-d LEVEL] [-p DEVPATH] [-h] SOURCE DESTINATION\n"
+                       "\t%s [-d LEVEL] [-p DEVPATH] [-h] [-v] SOURCE 
DESTINATION\n"
                        "\n"
                        "\t-d LEVEL     Set debug log level\n"
                        "\t                 0 - No logging (default)\n"
@@ -22,7 +30,8 @@ static void show_usage(const char* name)
                        "\t                 2 - Errors and warnings\n"
                        "\t                 3 - Everything\n"
                        "\t-h           Show this help message\n"
-                        "\t-p DEVPATH   Device path\n"
+            "\t-v           Verbose\n"
+                       "\t-p DEVPATH   Device path\n"
                        "\tSOURCE       The source filename\n"
                        "\tDESTINATION  The destination filename\n",
                        name);
@@ -34,7 +43,7 @@ static bool handle_parameters(int argc, int path_count;
        int log_level = SYNCE_LOG_LEVEL_LOWEST;
- while ((c = getopt(argc, argv, "d:hp:")) != -1)
+       while ((c = getopt(argc, argv, "d:hvp:")) != -1)
        {
                switch (c)
                {
@@ -46,6 +55,9 @@ static bool handle_parameters(int argc, devpath = optarg;
                                 break;
                        
+                       case 'v':
+                verbose = true;
+                break;
                        case 'h':
                        default:
                                show_usage(argv[0]);
@@ -72,7 +84,16 @@ static bool handle_parameters(int argc, static bool remote_copy(const char* ascii_source, const char* ascii_dest)
 {
+#ifndef WIN32
        return CeCopyFileA(ascii_source, ascii_dest, false);
+#else
+       WCHAR* src = wstr_from_current(ascii_source);
+       WCHAR* dest = wstr_from_current(ascii_dest);
+       bool ret = CeCopyFile(src, dest, false);
+       wstr_free_string(src);
+       wstr_free_string(dest);
+       return ret;
+#endif
 }
#define ANYFILE_BUFFER_SIZE (4*1024)
@@ -158,17 +179,17 @@ exit:
 int main(int argc, char** argv)
 {
        int result = 1;
-        RapiConnection* connection = NULL;
+#ifndef WIN32
+       RapiConnection* connection = NULL;
+#endif
        char* source = NULL;
        char* dest = NULL;
        HRESULT hr;
-       time_t start;
-       time_t duration;
        size_t bytes_copied = 0;
        
        if (!handle_parameters(argc, argv, &source, &dest))
                goto exit;
-
+#ifndef WIN32
         if ((connection = rapi_connection_from_path(devpath)) == NULL)
         {
fprintf(stderr, "%s: Could not find configuration at path '%s'\n", @@ -177,6 +198,7 @@ int main(int argc, char** argv)
           goto exit;
         }
         rapi_connection_select(connection);
+#endif
        hr = CeRapiInit();
if (FAILED(hr))
@@ -264,22 +286,25 @@ int main(int argc, char** argv)
        }
        else
        {
-               start = time(NULL);
+                time_t start;
+               if (verbose)
+                       start = time(NULL);
- /*
+               /*
                 * At least one is local, Use the AnyFile functions
                 */
                if (!anyfile_copy(source, dest, argv[0], &bytes_copied))
                        goto exit;
- duration = time(NULL) - start;
-
-               if (0 == duration)
-                       printf("File copy took less than one second!\n");
-               else
-                       printf("File copy of %i bytes took %li minutes and %li 
seconds, that's %li bytes/s.\n",
-                                       bytes_copied, duration / 60, duration % 
60, bytes_copied / duration);
-
+               if (verbose)
+               {
+                        time_t duration = time(NULL) - start;
+                       if (0 == duration)
+                               printf("File copy took less than one 
second!\n");
+                       else
+                               printf("File copy of %i bytes took %li minutes and 
%li seconds, that's %li bytes/s.\n",
+                                       bytes_copied, duration / 60, duration % 
60, bytes_copied / duration);
+               }
        }
result = 0;
@@ -291,6 +316,7 @@ exit:
        if (dest)
                free(dest);
- CeRapiUninit();
+       if (!FAILED(hr))
+               CeRapiUninit();
        return result;
 }
Index: synce-list-programs.c
===================================================================
--- synce-list-programs.c       (revision 2623)
+++ synce-list-programs.c       (working copy)
@@ -1,6 +1,9 @@
 /* $Id$ */
+#include "pcommon.h"
 #include <rapi.h>
+#ifndef WIN32
 #include <synce_log.h>
+#endif
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -57,7 +60,9 @@ static bool handle_parameters(int argc, int main(int argc, char** argv)
 {
        int return_value = 1;
+#ifndef WIN32
         RapiConnection* connection = NULL;
+#endif
        HRESULT hr;
        LONG result;
        HKEY parent_key;
@@ -69,6 +74,7 @@ int main(int argc, char** argv)
        if (!handle_parameters(argc, argv))
                goto exit;
+#ifndef WIN32
         if ((connection = rapi_connection_from_path(devpath)) == NULL)
         {
fprintf(stderr, "%s: Could not find configuration at path '%s'\n", @@ -77,6 +83,7 @@ int main(int argc, char** argv)
           goto exit;
         }
         rapi_connection_select(connection);
+#endif
        hr = CeRapiInit();
if (FAILED(hr))
Index: prun.c
===================================================================
--- prun.c      (revision 2623)
+++ prun.c      (working copy)
@@ -1,7 +1,9 @@
 /* $Id$ */
 #include "pcommon.h"
-#include "rapi.h"
+#include <rapi.h>
+#ifndef WIN32
 #include <synce_log.h>
+#endif
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -42,9 +44,9 @@ static bool handle_parameters(int argc, log_level = atoi(optarg);
                                break;
                        
-                        case 'p':
-                                devpath = optarg;
-                                break;
+                       case 'p':
+                               devpath = optarg;
+                               break;
case 'h':
                        default:
@@ -64,8 +66,31 @@ static bool handle_parameters(int argc,
        *program = strdup(argv[optind++]);
- if (optind < argc)
-               *parameters = strdup(argv[optind]);
+    {
+               size_t len = 0;
+               int i;
+               for(i = optind; i < argc; i++)
+                       len += strlen(argv[i]) + 1;
+               if (len)
+               {
+                       char* p = malloc(len);
+                       char* o = p;
+                       *p = '\0';
+                       for(; optind < argc; optind++)
+                       {
+                               strcat(p, argv[optind]);
+                               p += strlen(argv[optind]);
+                               *p = ' ';
+                               p++;
+                       }
+                       *p = '\0';
+                       *parameters = o;
+               }
+               else
+               {
+                       *parameters = 0;
+               }
+       }
return true;
 }
@@ -73,7 +98,9 @@ static bool handle_parameters(int argc, int main(int argc, char** argv)
 {
        int result = 1;
-        RapiConnection* connection = NULL;
+#ifndef WIN32
+       RapiConnection* connection = NULL;
+#endif
        char* program = NULL;
        char* parameters = NULL;
        HRESULT hr;
@@ -84,6 +111,7 @@ int main(int argc, char** argv)
        if (!handle_parameters(argc, argv, &program, &parameters))
                goto exit;
+#ifndef WIN32
         if ((connection = rapi_connection_from_path(devpath)) == NULL)
         {
fprintf(stderr, "%s: Could not find configuration at path '%s'\n", @@ -92,6 +120,7 @@ int main(int argc, char** argv)
           goto exit;
         }
         rapi_connection_select(connection);
+#endif
        hr = CeRapiInit();
if (FAILED(hr))
@@ -135,15 +164,16 @@ int main(int argc, char** argv)
        result = 0;
exit:
-       wstr_free_string(wide_program);
-       wstr_free_string(wide_parameters);
-
+        if (wide_program)
+               wstr_free_string(wide_program);
+        if (wide_parameters)
+               wstr_free_string(wide_parameters);
        if (program)
                free(program);
-
        if (parameters)
                free(parameters);
- CeRapiUninit();
+        if (!FAILED(hr))
+               CeRapiUninit();
        return result;
 }
Index: pmkdir.c
===================================================================
--- pmkdir.c    (revision 2623)
+++ pmkdir.c    (working copy)
@@ -1,7 +1,9 @@
 /* $Id$ */
 #include "pcommon.h"
 #include <rapi.h>
+#ifndef WIN32
 #include <synce_log.h>
+#endif
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -69,7 +71,9 @@ static bool handle_parameters(int argc, int main(int argc, char** argv)
 {
        int result = 1;
-        RapiConnection* connection = NULL;
+#ifndef WIN32
+       RapiConnection* connection = NULL;
+#endif
        char* path = NULL;
        HRESULT hr;
        WCHAR* wide_path = NULL;
@@ -77,6 +81,7 @@ int main(int argc, char** argv)
        if (!handle_parameters(argc, argv, &path))
                goto exit;
+#ifndef WIN32
         if ((connection = rapi_connection_from_path(devpath)) == NULL)
         {
fprintf(stderr, "%s: Could not find configuration at path '%s'\n", @@ -85,6 +90,7 @@ int main(int argc, char** argv)
           goto exit;
         }
         rapi_connection_select(connection);
+#endif
        hr = CeRapiInit();
if (FAILED(hr))
Index: oidinfo.c
===================================================================
--- oidinfo.c   (revision 2623)
+++ oidinfo.c   (working copy)
@@ -1,12 +1,17 @@
 /* $Id$ */
+#include "pcommon.h"
 #include <rapi.h>
+#ifndef WIN32
 #include <synce_log.h>
+#endif
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
+#ifndef WIN32
 char* devpath = NULL;
+#endif
static void show_usage(const char* name)
 {
@@ -40,7 +45,9 @@ static bool handle_parameters(int argc, break;
                        
                         case 'p':
+#ifndef WIN32
                                 devpath = optarg;
+#endif
                                 break;
case 'h':
@@ -70,11 +77,14 @@ int main(int argc, char** argv)
        HRESULT hr;
        CEOID oid = 0;
        CEOIDINFO info;
+#ifndef WIN32
         RapiConnection* connection = NULL;
+#endif
        
        if (!handle_parameters(argc, argv, &oid))
                goto exit;
+#ifndef WIN32
         if ((connection = rapi_connection_from_path(devpath)) == NULL)
         {
fprintf(stderr, "%s: Could not find configuration at path '%s'\n", @@ -83,6 +93,7 @@ int main(int argc, char** argv)
           goto exit;
         }
         rapi_connection_select(connection);
+#endif
        hr = CeRapiInit();
if (FAILED(hr))
Index: synce-registry.c
===================================================================
--- synce-registry.c    (revision 2623)
+++ synce-registry.c    (working copy)
@@ -1,7 +1,9 @@
 /* $Id$ */
+#include "pcommon.h"
 #include <rapi.h>
+#ifndef WIN32
 #include <synce_log.h>
-#include <pcommon.h>
+#endif
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -435,10 +437,33 @@ int write_val(HKEY key, LPCWSTR value_na
   return 0;
 }
+#ifdef WIN32
+/* This function is exported by synce, but
+ rapi.dll only has the wide version. */ +bool rapi_reg_open_key(HKEY parent, const char* name, HKEY* key)
+{
+    WCHAR* name_wide = wstr_from_current(name);
+
+    LONG result = CeRegOpenKeyEx(
+        parent,
+        name_wide,
+        0,
+        0,
+        key
+        );
+
+    wstr_free_string(name_wide);
+
+    return ERROR_SUCCESS == result;
+}
+#endif
+
 int main(int argc, char** argv)
 {
   int result = 1;
+#ifndef WIN32
   RapiConnection* connection = NULL;
+#endif
   char* parent_str  = NULL;
   char* key_name          = NULL;
   char* value_name  = NULL;
@@ -478,6 +503,7 @@ int main(int argc, char** argv)
     goto exit;
   }
+#ifndef WIN32
   if ((connection = rapi_connection_from_path(devpath)) == NULL)
   {
fprintf(stderr, "%s: Could not find configuration at path '%s'\n", @@ -486,6 +512,7 @@ int main(int argc, char** argv)
     goto exit;
   }
   rapi_connection_select(connection);
+#endif
   if (S_OK != (hr = CeRapiInit()))
   {
fprintf(stderr, "%s: Unable to initialize RAPI: %s\n", Index: Makefile.am
===================================================================
--- Makefile.am (revision 2623)
+++ Makefile.am (working copy)
@@ -1,12 +1,11 @@
-AM_CFLAGS = @LIBSYNCE_CFLAGS@
-AM_LDFLAGS = @LIBSYNCE_LIBS@
+AM_CFLAGS = $(TOOLS_CFLAGS)
+AM_LDFLAGS = $(TOOLS_LDFLAGS)
-INCLUDES = -I$(top_srcdir)/src -I$(top_srcdir)/src/support
-LDADD = ../src/librapi.la
+INCLUDES = +LDADD = noinst_PROGRAMS = oidinfo
-
-oidinfo_SOURCES = oidinfo.c
+oidinfo_SOURCES = pcommon.c oidinfo.c
bin_PROGRAMS = pcp pls pmkdir pmv prm prmdir prun pstatus rapiconfig pkillall pshortcut psettime \
        synce-list-programs synce-registry
@@ -18,14 +17,14 @@ pmv_SOURCES    = pcommon.c pmv.c
 prm_SOURCES    = pcommon.c prm.c
 prmdir_SOURCES = pcommon.c prmdir.c
 prun_SOURCES   = pcommon.c prun.c
-pstatus_SOURCES= pstatus.c
-pkillall_SOURCES=pkillall.c
-pshortcut_SOURCES=pcommon.c pshortcut.c
-psettime_SOURCES=psettime.c
+pstatus_SOURCES= pcommon.c pstatus.c
+pkillall_SOURCES = pcommon.c pkillall.c
+pshortcut_SOURCES = pcommon.c pshortcut.c
+psettime_SOURCES = pcommon.c psettime.c
-rapiconfig_SOURCES = rapiconfig.c
+rapiconfig_SOURCES = pcommon.c rapiconfig.c
-synce_list_programs_SOURCES = synce-list-programs.c
+synce_list_programs_SOURCES = pcommon.c synce-list-programs.c
 synce_registry_SOURCES = synce-registry.c pcommon.c
SUBDIRS = man
Index: psettime.c
===================================================================
--- psettime.c  (revision 2623)
+++ psettime.c  (working copy)
@@ -1,5 +1,8 @@
+#include "pcommon.h"
 #include <rapi.h>
+#ifndef WIN32
 #include <synce_log.h>
+#endif
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -57,12 +60,15 @@ static bool handle_parameters(int argc, int main(int argc, char** argv)
 {
   int result = 0;
+#ifndef WIN32
   RapiConnection* connection = NULL;
+#endif
   HRESULT hr;
if (!handle_parameters(argc, argv))
     goto exit;
+#ifndef WIN32
   if ((connection = rapi_connection_from_path(devpath)) == NULL)
   {
fprintf(stderr, "%s: Could not find configuration at path '%s'\n", @@ -71,6 +77,7 @@ int main(int argc, char** argv)
     goto exit;
   }
   rapi_connection_select(connection);
+#endif
   hr = CeRapiInit();
   if (FAILED(hr))
   {
@@ -81,16 +88,24 @@ int main(int argc, char** argv)
     goto exit;
   }
+#ifdef WIN32
+  typedef BOOL __stdcall (*CeSyncTimeToPc_t) (void);
+  HINSTANCE rapidll = LoadLibrary ("rapi.dll");
+  /* 13 or 16, or? */
+  CeSyncTimeToPc_t CeSyncTimeToPc = (CeSyncTimeToPc_t)GetProcAddress(rapidll, 
(LPCSTR)13);
+#endif
   if (!CeSyncTimeToPc())
   {
     fprintf(stderr,"%s: CeSyncTimeToPc failed\n",argv[0]);
     result = 2;
     goto exit;
   }
-
  exit:
   CeRapiUninit();
+#ifndef WIN32
   rapi_connection_destroy(connection);
-
+#else
+  FreeLibrary(rapidll);
+#endif
   return result;
 }
Index: pshortcut.c
===================================================================
--- pshortcut.c (revision 2623)
+++ pshortcut.c (working copy)
@@ -1,6 +1,8 @@
 #include "pcommon.h"
 #include <rapi.h>
+#ifndef WIN32
 #include <synce_log.h>
+#endif
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -70,9 +72,12 @@ static bool handle_parameters(int argc, int main(int argc, char** argv)
 {
   int result = 0;
+#ifndef WIN32
   RapiConnection* connection = NULL;
+#endif
   HRESULT hr;
-  char *shortcut, *target;
+  char *shortcut = NULL;
+  char *target = NULL;
   WCHAR* wide_shortcut = NULL;
   WCHAR* wide_target = NULL;
   WCHAR *tmp, *tmp_quote;
@@ -80,7 +85,7 @@ int main(int argc, char** argv)
if (!handle_parameters(argc, argv, &shortcut, &target))
     goto exit;
-
+#ifndef WIN32
   if ((connection = rapi_connection_from_path(devpath)) == NULL)
   {
fprintf(stderr, "%s: Could not find configuration at path '%s'\n", @@ -89,6 +94,7 @@ int main(int argc, char** argv)
     goto exit;
   }
   rapi_connection_select(connection);
+#endif
   hr = CeRapiInit();
if (FAILED(hr))
@@ -144,7 +150,9 @@ int main(int argc, char** argv)
     free(target);
CeRapiUninit();
+#ifndef WIN32
   rapi_connection_destroy(connection);
+#endif
return result;
 }
Index: prmdir.c
===================================================================
--- prmdir.c    (revision 2623)
+++ prmdir.c    (working copy)
@@ -1,7 +1,9 @@
 /* $Id$ */
 #include "pcommon.h"
 #include <rapi.h>
+#ifndef WIN32
 #include <synce_log.h>
+#endif
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -69,7 +71,9 @@ static bool handle_parameters(int argc, int main(int argc, char** argv)
 {
        int result = 1;
+#ifndef WIN32
         RapiConnection* connection = NULL;
+#endif
        char* path = NULL;
        HRESULT hr;
        WCHAR* wide_path = NULL;
@@ -77,6 +81,7 @@ int main(int argc, char** argv)
        if (!handle_parameters(argc, argv, &path))
                goto exit;
+#ifndef WIN32
         if ((connection = rapi_connection_from_path(devpath)) == NULL)
         {
fprintf(stderr, "%s: Could not find configuration at path '%s'\n", @@ -85,6 +90,7 @@ int main(int argc, char** argv)
           goto exit;
         }
         rapi_connection_select(connection);
+#endif
        hr = CeRapiInit();
if (FAILED(hr)) ------------------------------------------------------------------------

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier.
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
------------------------------------------------------------------------

_______________________________________________
Synce-devel mailing list
Synce-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/synce-devel

#ifndef WINCOMPAT_H
#define WINCOMPAT_H

#include <rapi.h>

typedef DWORD CEOID;
typedef CEOID *PCEOID;
typedef DWORD CEPROPID;
typedef CEPROPID *PCEPROPID;

#define CEDB_MAXDBASENAMELEN 32
#define CEDB_MAXSORTORDER 4

typedef struct _SORTORDERSPEC {
    CEPROPID propid;
    DWORD dwFlags;
} SORTORDERSPEC; 

typedef struct _CEDBASEINFO {
    DWORD dwFlags; 
    WCHAR szDbaseName[CEDB_MAXDBASENAMELEN];
    DWORD dwDbaseType;
    WORD wNumRecords;
    WORD wNumSortOrder;
    DWORD dwSize;
    FILETIME ftLastModified;
    SORTORDERSPEC rgSortSpecs[CEDB_MAXSORTORDER];
} CEDBASEINFO;

typedef struct _CEFILEINFO {
    DWORD dwAttributes; 
    CEOID oidParent; 
    WCHAR szFileName[MAX_PATH]; 
    FILETIME ftLastChanged; 
    DWORD dwLength; 
} CEFILEINFO; 

typedef struct _CEDIRINFO {
    DWORD dwAttributes; 
    CEOID oidParent; 
    WCHAR szDirName[MAX_PATH]; 
} CEDIRINFO; 

typedef struct _CERECORDINFO {
    CEOID oidParent; 
} CERECORDINFO; 

typedef struct _CEOIDINFO { 
    WORD wObjType;
    WORD wPad;
    union {
        CEFILEINFO infFile;
        CEDIRINFO infDirectory;
        CEDBASEINFO infDatabase;
        CERECORDINFO infRecord;
    } u;
} CEOIDINFO; 

typedef struct _CE_FIND_DATA {
    DWORD    dwFileAttributes;
    FILETIME ftCreationTime;
    FILETIME ftLastAccessTime;
    FILETIME ftLastWriteTime;
    DWORD    nFileSizeHigh;
    DWORD    nFileSizeLow;
    DWORD    dwOID;
    WCHAR    cFileName[MAX_PATH];
} CE_FIND_DATA, *LPCE_FIND_DATA;
typedef CE_FIND_DATA** LPLPCE_FIND_DATA;

typedef struct _CEOSVERSIONINFO{
    DWORD dwOSVersionInfoSize; 
    DWORD dwMajorVersion; 
    DWORD dwMinorVersion; 
    DWORD dwBuildNumber; 
    DWORD dwPlatformId; 
    WCHAR szCSDVersion[ 128 ]; 
} CEOSVERSIONINFO, *LPCEOSVERSIONINFO;


typedef struct _SYSTEM_POWER_STATUS_EX {
    BYTE ACLineStatus;
    BYTE BatteryFlag;
    BYTE BatteryLifePercent;
    BYTE Reserved1;
    DWORD BatteryLifeTime;
    DWORD BatteryFullLifeTime;
    BYTE Reserved2;
    BYTE BackupBatteryFlag;
    BYTE BackupBatteryLifePercent;
    BYTE Reserved3;
    DWORD BackupBatteryLifeTime;
    DWORD BackupBatteryFullLifeTime;
} SYSTEM_POWER_STATUS_EX, *PSYSTEM_POWER_STATUS_EX, *LPSYSTEM_POWER_STATUS_EX;

typedef struct STORE_INFORMATION {
    DWORD dwStoreSize;
    DWORD dwFreeSize;
} STORE_INFORMATION, *LPSTORE_INFORMATION;

STDAPI_(DWORD) CeGetSpecialFolderPath(int nFolder, DWORD nBufferLength, LPWSTR 
lpBuffer);
STDAPI_(BOOL) CeReadFile(HANDLE hFile, LPVOID lpBuffer, DWORD 
nNumberOfBytesToRead, LPDWORD lpNumberOfBytesRead, LPOVERLAPPED lpOverlapped);
STDAPI_(BOOL) CeCopyFile(LPCWSTR lpExistingFileName, LPCWSTR lpNewFileName, 
BOOL bFailIfExists);
STDAPI_(BOOL) CeFindAllFiles(LPCWSTR, DWORD, LPDWORD, LPLPCE_FIND_DATA);
STDAPI CeRapiFreeBuffer(LPVOID);
STDAPI_(BOOL) CeMoveFile(LPCWSTR, LPCWSTR);
STDAPI_(BOOL) CeDeleteFile(LPCWSTR);
STDAPI_(BOOL) CeRemoveDirectory(LPCWSTR);
STDAPI_(BOOL) CeGetVersionEx(LPCEOSVERSIONINFO);
STDAPI_(VOID) CeGetSystemInfo(LPSYSTEM_INFO);
STDAPI_(BOOL) CeGetSystemPowerStatusEx(PSYSTEM_POWER_STATUS_EX, BOOL);
STDAPI_(BOOL) CeGetStoreInformation(LPSTORE_INFORMATION);
STDAPI_(BOOL) CeSHCreateShortcut(LPCWSTR lpszShortcut,LPCWSTR lpszTarget);
STDAPI_(LONG) CeRegCreateKeyEx(HKEY hKey, LPCWSTR lpszSubKey, DWORD Reserved, 
LPWSTR lpszClass, DWORD ulOptions, REGSAM samDesired, LPSECURITY_ATTRIBUTES 
lpSecurityAttributes, PHKEY phkResult, LPDWORD lpdwDisposition);
STDAPI_(LONG) CeRegOpenKeyEx(HKEY hKey, LPCWSTR lpszSubKey, DWORD ulOptions, 
REGSAM samDesired, PHKEY phkResult);
STDAPI_(LONG) CeRegCloseKey(HKEY hKey);
STDAPI_(LONG) CeRegQueryInfoKey(HKEY hKey, LPWSTR lpClass, LPDWORD lpcbClass, 
LPDWORD lpReserved, LPDWORD lpcSubKeys, LPDWORD lpcbMaxSubKeyLen, LPDWORD 
lpcbMaxClassLen, LPDWORD lpcValues, LPDWORD lpcbMaxValueNameLen, LPDWORD 
lpcbMaxValueLen, LPDWORD lpcbSecurityDescriptor, PFILETIME lpftLastWriteTime);
STDAPI_(LONG) CeRegQueryValueEx(HKEY hKey, LPCWSTR lpValueName, LPDWORD 
lpReserved, LPDWORD lpType, LPBYTE lpData, LPDWORD lpcbData);
STDAPI_(LONG) CeRegEnumValue(HKEY hKey, DWORD dwIndex, LPWSTR lpszValueName, 
LPDWORD lpcbValueName, LPDWORD lpReserved, LPDWORD lpType, LPBYTE lpData, 
LPDWORD lpcbData);
STDAPI_(LONG) CeRegEnumKeyEx(HKEY hKey, DWORD dwIndex, LPWSTR lpName, LPDWORD 
lpcbName, LPDWORD lpReserved, LPWSTR lpClass, LPDWORD lpcbClass, PFILETIME 
lpftLastWriteTime);
STDAPI_(LONG) CeRegSetValueEx(HKEY hKey, LPCWSTR lpValueName, DWORD Reserved, 
DWORD dwType, const BYTE *lpData, DWORD cbData);
STDAPI_(BOOL) CeOidGetInfo(CEOID, CEOIDINFO*);


/* Undocumented, but trial and error shows that it is exported with ordinal 19. 
 */
STDAPI_(BOOL) CeGetSystemMemoryDivision(LPDWORD, LPDWORD, LPDWORD);

/* Undocumented, but trial and error shows that it is exported with ordinal 24. 
 */
STDAPI_(BOOL) CeKillAllApps (void);

/* Undocumented, but trial and error shows that it is exported with ordinal 25. 
 */
STDAPI_(HRESULT) CeProcessConfig(LPCWSTR, DWORD, LPWSTR*);

#define OBJTYPE_INVALID     0
#define OBJTYPE_FILE        1
#define OBJTYPE_DIRECTORY   2
#define OBJTYPE_DATABASE    3
#define OBJTYPE_RECORD      4
/* 
* returned by CeOidGetInfo() for an ActiveSync notification when
* an object has been deleted. 
*/
#define OBJTYPE_DELETED     8

#define CSIDL_PERSONAL           0x0005

#define FILE_ATTRIBUTE_INROM 0x00000040
#define FILE_ATTRIBUTE_ROMMODULE    0x00002000
#define FAF_ATTRIBUTES      ((DWORD) 0x01)
#define FAF_CREATION_TIME   ((DWORD) 0x02)
#define FAF_LASTACCESS_TIME ((DWORD) 0x04)
#define FAF_LASTWRITE_TIME  ((DWORD) 0x08)
#define FAF_SIZE_HIGH       ((DWORD) 0x10)
#define FAF_SIZE_LOW        ((DWORD) 0x20)
#define FAF_OID             ((DWORD) 0x40)
#define FAF_NAME            ((DWORD) 0x80)
#define FAF_FLAG_COUNT      ((UINT)  8)
#define FAF_ATTRIB_CHILDREN ((DWORD)                    0x01000)
#define FAF_ATTRIB_NO_HIDDEN ((DWORD)                   0x02000)
#define FAF_FOLDERS_ONLY    ((DWORD)                    0x04000)
#define FAF_NO_HIDDEN_SYS_ROMMODULES ((DWORD)   0x08000)
#define FAF_GETTARGET       ((DWORD)                    0x10000)

#define FAD_OID             ((WORD) 0x01)
#define FAD_FLAGS           ((WORD) 0x02)
#define FAD_NAME            ((WORD) 0x04)
#define FAD_TYPE            ((WORD) 0x08)
#define FAD_NUM_RECORDS     ((WORD) 0x10)
#define FAD_NUM_SORT_ORDER  ((WORD) 0x20)

#define PROCESSOR_STRONGARM    2577
#define PROCESSOR_MIPS_R4000   4000
#define PROCESSOR_HITACHI_SH3 10003

#define VER_PLATFORM_WIN32_CE 3

#define CONFIG_PROCESS_DOCUMENT   1
#define CONFIG_RETURN_METADATA    2

#include <string.h>

/* pcommon.c */
extern WCHAR* win32_wcsdup(const WCHAR* wstr);
extern const char* synce_strerror(DWORD err);
extern WCHAR* wstr_from_current(const char* str);
extern char* wstr_to_current(const WCHAR* wstr);
extern void synce_log_set_level(int);

#define wstr_to_ascii wstr_to_current
#define wstr_append wcsncat
#define wstr_free_string free
#define wstrdup win32_wcsdup
#define wstr_strlen wcslen
#define wstrlen wcslen
#define wstrcpy wcscpy

size_t __cdecl wcslen (const wchar_t *);
wchar_t * __cdecl wcscpy(wchar_t *, const wchar_t *);
wchar_t __cdecl* wcsncat (wchar_t *, const wchar_t *, size_t);

#define synce_trace_wstr(STR) do ; while (0)
#define synce_error printf

#define SYNCE_LOG_LEVEL_LOWEST 1

typedef int bool;
#define false 0
#define true 1

static inline int filetime_to_unix_time(FILETIME* pt)
{
    (void)pt;
    return 0;
}

#endif
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier.
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Synce-devel mailing list
Synce-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/synce-devel

Reply via email to