I implemented reading of the output_size and output_buffer too.  I couldn't
figure out how to actually run the CeRapiInvoke tests (my automake
experience is lacking) but I did create a separate executable that does the
same thing as those tests.  It should pass test_ping_result and
test_ping_buffer now, but not the stream test (will still return
E_NOTIMPL).  I didn't check test_last_error yet.

On Mon, Jun 29, 2009 at 11:26 AM, David Richardson <docgra...@gmail.com>wrote:

>
>
> On Mon, Jun 29, 2009 at 7:42 AM, Mark Ellis <m...@mpellis.org.uk> wrote:
>
>> On Mon, 2009-06-29 at 12:39 +0200, Mark Ellis wrote:
>> > On Fri, 2009-06-26 at 22:37 +0200, David Richardson wrote:
>> > > I called CeCreateFile("//test.txt", GENERIC_READ | GENERIC_WRITE, 0,
>> > > NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); and watched that
>> > > connection on wireshark so I had some basis for comparison.
>> > >
>> > > CeCreateFile has a command code of 0x16 and using this knowledge I
>> > > believe the command code for CeRapiInvoke is 0x4C on WM5. (Which
>> > > according to
>> > >
>> https://synce.svn.sourceforge.net/svnroot/synce/trunk/librapi2/src/rapi2/READMEis
>>  already taken by CeSetDatabaseInfoEx which is troubling, I think)
>> > >
>> > > I've attached the log of CeCreateFile in case someone wants to double
>> > > check my work or like me finds it easier to compare the two
>> > > side-by-side.
>> > >
>> > > My amateur opinion is that CeCreateFile and CeRapiInvoke look really
>> > > similar on the wire and is hopefully not hard to implement for that
>> > > reason.  I'll try my hand at it today.
>> > >
>> > >
>> > > -David Richardson
>> > >
>> >
>> > > On Fri, Jun 26, 2009 at 12:44 PM, David Richardson
>> > > <docgra...@gmail.com> wrote:
>> > >         I'm calling
>> > >
>> > >
>> > >         hr = CeRapiInvoke("\\invokeme.dll", "PingBuffer",
>> > >         PING_BUFFER_SIZE, buffer, &output_size, &output_buffer, NULL,
>> > >         0);
>> > >
>> > >
>> > >         with PING_BUFFER_SIZE = 10
>> > >
>> >
>> > David, the trace of the call sent to the device looks good. It actually
>> > looks exactly like what rapi1 invoke would send apart from the command
>> > code, which should make life easier.
>> >
>> > I can't see the data being sent back however. The data returned from the
>> > first call (packet 16) looks like this
>> >
>> > 0c 00 00 00   data len = 0x0c = 12
>> > 7e 00 00 00   error mod not found
>> > 7e 00 07 80
>> > 00 00 00 00
>> >
>> > which would suggest it can't find the dll. Is the path correct in your
>> > call ?
>>
>
> I noticed that as well.  Check out this pcap file.  I'm calling PingResult
> this time and you can actually see the data being returned. PingResult takes
> a value and returns it as a the return code.  I'm passing in 0x12345678. I'm
> trying to take it one step at a time and just trying to get the return code
> and error code to be valid before I worry about reading the output_size and
> output_buffer.  I've got that working.  You're right, its pretty much
> exactly the same as the old invoke.
>
> I'll implement the reading of output_size and buffer today and send a
> patch.  I'm not going to look into stream mode at this time, but may in the
> future.
>
> Thanks for all the help!
>
>
>> >
>> > As for code 0x4c being assigned to CeSetDatabaseInfoEx, none of the
>> > database functions for rapi2 have been implemented. Maybe David (E) can
>> > give some indication of how reliable that list is ?
>> >
>> > Mark
>> >
>>
>> Sometimes I wonder why I spend so much time writing software that deals
>> with MS rubbish :)
>>
>> Can't invoke on WM5+ because it's in 'RAPI Restricted Mode', anyone know
>> how to switch to 'Open Mode' ?
>
>
> I'm not encountering this problem.  I'm guessing its because I disabled all
> security in Visual Studio for the device.
>
>
>>
>>
>>
>> > >
>> > >         I've attached the wireshark pcap.  Ignore everything before 12
>> > >         seconds.  I called the identical invoke 3 times on the
>> > >         device.  buffer should be 10 0xDD's. output_buffer and
>> > >         output_size were uninitialized and when finished output_buffer
>> > >         is identical to buffer and output_size is 10
>> > >         (PING_BUFFER_SIZE).
>> > >
>> > >
>> > >         I'm not sending this to hand it off to you guys.  I'm still
>> > >         looking at this myself to see if I can implement it or figure
>> > >         out the command code, but I'm sure the people on this list
>> > >         have more experience doing this.
>> > >
>> > >
>> > >         Let me know if you have any questions or want me to redo with
>> > >         some changes.
>> > >
>> > >
>> > >         -David Richardson
>> > >
>> > >
>> > >
>> > >         On Thu, Jun 25, 2009 at 3:44 AM, Mark Ellis
>> > >         <m...@mpellis.org.uk> wrote:
>> > >
>> > >                 On Thu, 2009-06-25 at 00:39 +0200, David Richardson
>> > >                 wrote:
>> > >                 >
>> > >                 >
>> > >                 > On Wed, Jun 24, 2009 at 12:35 AM, Mark Ellis
>> > >                 <m...@mpellis.org.uk>
>> > >                 > wrote:
>> > >                 >         On Mon, 2009-06-22 at 22:10 +0200, David
>> > >                 Eriksson wrote:
>> > >                 >         > On Wed, 2009-06-17 at 18:07 -0700, Captain
>> > >                 Fourier wrote:
>> > >                 >         > > Hey,
>> > >                 >         > >
>> > >                 >         > > I have been trying to get CeRapiInvoke
>> > >                 to work. Just using
>> > >                 >         the unit
>> > >                 >         > > tests in the release. All I get is
>> > >                 -2147467263 as a return
>> > >                 >         result.
>> > >                 >         >
>> > >                 >         > 0x80004001 means "not implemented"
>> > >                 >         >
>> > >                 >         > > Is CeRapiInvoke implemented? Is it still
>> > >                 only Stream mode?
>> > >                 >         >
>> > >                 >         > UTSL :-)
>> > >                 >         >
>> > >                 >         > Unfortunately it has not been implemented
>> > >                 for Windows Mobile
>> > >                 >         5 or newer
>> > >                 >         > devices. Any takers on the synce-devel
>> > >                 list?
>> > >                 >         >
>> > >                 >         >
>> > >                 >         > > Thanks for your time,
>> > >                 >         > > Rob
>> > >                 >         >
>> > >                 >         >
>> > >                 >         > Best regards,
>> > >                 >         >
>> > >                 >         > David Eriksson,
>> > >                 http://www.divideandconquer.se/
>> > >                 >         >
>> > >                 >
>> > >                 >
>> > >                 >         Rob, I'll take a look at this sometime, but
>> > >                 my time is very
>> > >                 >         limited at
>> > >                 >         the moment, so I'll need three things, the
>> > >                 dll you're using on
>> > >                 >         the
>> > >                 >         device and the code you're using to call it,
>> > >                 and the command
>> > >                 >         code for
>> > >                 >         CeRapiInvoke on WM5 :)
>> > >                 >
>> > >                 > I believe Rob was trying to execute the test located
>> > >                 at
>> > >                 >
>> > >
>> http://synce.svn.sourceforge.net/viewvc/synce/trunk/librapi2/tests/CeRapiInvoke/which
>>  has a DLL with it.
>> > >                 >
>> > >
>> > >
>> > >                 Ah yes, I've never noticed that there !
>> > >
>> > >                 > If someone can briefly explain how I would go about
>> > >                 getting the
>> > >                 > command code for CeRapiInvoke on WM5, I have the
>> > >                 necessary hardware
>> > >                 > and time.
>> > >
>> > >
>> > >                 Theoretically, run a small program on a windows host
>> > >                 that just
>> > >                 RapiInit's and calls the command we're interested in,
>> > >                 and capture the
>> > >                 transmission on the network interface using eg.
>> > >                 wireshark.
>> > >
>> > >                 Of course, being MS it's rarely that straightforward,
>> > >                 and if David is
>> > >                 correct it could be a lot more complex. However, if
>> > >                 you could use the
>> > >                 test prog for CeRapiInvoke from windows and capture
>> > >                 everything over the
>> > >                 interface, we might be fortunate.
>> > >
>> > >
>> > >                 >
>> > >                 >         I don't have anything set up to generate the
>> > >                 call
>> > >                 >         on Windows to capture that code, so someone
>> > >                 will have to find
>> > >                 >         it for me.
>> > >                 >
>> > >                 >         Mark
>> > >                 >
>> > >                 >
>> > >                 >
>> > >
>> ------------------------------------------------------------------------------
>> > >                 >
>> > >                 >
>> > >                 _______________________________________________
>> > >                 >         SynCE-Devel mailing list
>> > >                 >         SynCE-Devel@lists.sourceforge.net
>> > >                 >
>> > >
>> https://lists.sourceforge.net/lists/listinfo/synce-devel
>> > >                 >
>> > >                 >
>> > >
>> > >
>> > >
>> > >
>> > >
>>
>
>
Index: src/rapi2/rapi2_api.h
===================================================================
--- src/rapi2/rapi2_api.h	(revision 3784)
+++ src/rapi2/rapi2_api.h	(working copy)
@@ -342,7 +342,7 @@
         ULONG cb,
         ULONG *pcbWritten);
 
-HRESULT _NotImplementedCeRapiInvoke2(
+HRESULT _CeRapiInvoke2(
         LPCWSTR pDllPath,
         LPCWSTR pFunctionName,
         DWORD cbInput,
@@ -352,7 +352,7 @@
         IRAPIStream **ppIRAPIStream,
         DWORD dwReserved);
 
-HRESULT _NotImplementedCeRapiInvokeA2(
+HRESULT _CeRapiInvokeA2(
         LPCSTR pDllPath,
         LPCSTR pFunctionName,
         DWORD cbInput,
Index: src/rapi2/invoke2.c
===================================================================
--- src/rapi2/invoke2.c	(revision 3784)
+++ src/rapi2/invoke2.c	(working copy)
@@ -35,24 +35,123 @@
   return hr;
 }/*}}}*/
 
+static HRESULT CeRapiInvokeCommon2(
+    RapiContext* context,
+    LPCWSTR pDllPath,
+    LPCWSTR pFunctionName,
+    DWORD cbInput,
+    const BYTE *pInput,
+    DWORD dwReserved,
+    BOOL inRapiStream
+    )
+{
+  if (cbInput)
+    if (!pInput)
+      return E_INVALIDARG;
 
-HRESULT _NotImplementedCeRapiInvoke2( /*{{{*/
+  rapi_context_begin_command(context, 0x4c);
+  rapi_buffer_write_uint32(context->send_buffer, dwReserved);
+  rapi2_buffer_write_string(context->send_buffer, pDllPath);
+  rapi2_buffer_write_string(context->send_buffer, pFunctionName);
+  rapi_buffer_write_uint32(context->send_buffer, cbInput);
+  if (cbInput)
+    rapi_buffer_write_data  (context->send_buffer, pInput, cbInput);
+  rapi_buffer_write_uint32(context->send_buffer, inRapiStream);
+
+  return S_OK;
+}
+
+static HRESULT CeRapiInvokeBuffers(
     LPCWSTR pDllPath,
     LPCWSTR pFunctionName,
     DWORD cbInput,
     const BYTE *pInput,
     DWORD *pcbOutput,
     BYTE **ppOutput,
+    DWORD dwReserved)
+{
+  RapiContext* context = rapi_context_current();
+  HRESULT return_value = E_UNEXPECTED;
+  HRESULT hr;
+  uint32_t unknown;
+  unsigned bytes_left;
+  unsigned output_size;
+  uint32_t last_error;
+
+  synce_trace("begin");
+  
+  hr = CeRapiInvokeCommon2(
+      context,
+      pDllPath,
+      pFunctionName,
+      cbInput,
+      pInput,
+      dwReserved,
+      FALSE);
+  if (FAILED(hr))
+  {
+    synce_error("CeRapiInvokeCommon2 failed");
+    return hr;
+  }
+
+  if ( !rapi2_context_call(context) )
+  {
+    synce_error("rapi2_context_call failed");
+    hr = E_FAIL;
+    return hr;
+  }
+  synce_trace("pInput: 0x%08x", pInput);
+  rapi_buffer_read_uint32(context->recv_buffer, &context->last_error);
+  synce_trace("last error: 0x%08x", context->last_error);
+  rapi_buffer_read_uint32(context->recv_buffer, &return_value);
+  synce_trace("return_value: 0x%08x", return_value);
+  rapi_buffer_read_uint32(context->recv_buffer, &output_size);
+  synce_trace("output_size: 0x%08x", output_size);
+  if (output_size > 0 && ppOutput)
+  {
+    *ppOutput = malloc(output_size);
+    if(!*ppOutput)
+    {
+      return E_OUTOFMEMORY;
+    }
+    if (!rapi_buffer_read_data(context->recv_buffer, *ppOutput, output_size))
+    {
+      synce_error("Failed to read output data");
+      hr = E_FAIL;
+    }
+    else
+    {
+      synce_trace("output_buffer: 0x%0x", ppOutput);
+    }
+  }
+
+  if (SUCCEEDED(hr))
+    return return_value;
+  else
+    return hr;
+}
+
+HRESULT _CeRapiInvoke2( /*{{{*/
+    LPCWSTR pDllPath,
+    LPCWSTR pFunctionName,
+    DWORD cbInput,
+    const BYTE *pInput,
+    DWORD *pcbOutput,
+    BYTE **ppOutput,
     IRAPIStream **ppIRAPIStream,
     DWORD dwReserved)
 {
-  RapiContext* context = rapi_context_current();
-  context->rapi_error = E_NOTIMPL;
-  context->last_error = ERROR_CALL_NOT_IMPLEMENTED;
-  return E_NOTIMPL;
+  if (ppIRAPIStream)
+  {
+    synce_error("Stream mode is not implemented");
+    return E_NOTIMPL;
+  }
+  else
+    return CeRapiInvokeBuffers(pDllPath, pFunctionName, cbInput, pInput,
+        pcbOutput, ppOutput, dwReserved);
 }/*}}}*/
 
-HRESULT _NotImplementedCeRapiInvokeA2( /*{{{*/
+HRESULT _CeRapiInvokeA2( /*{{{*/
     LPCSTR pDllPath,
     LPCSTR pFunctionName,
     DWORD cbInput,
@@ -62,9 +161,21 @@
     IRAPIStream **ppIRAPIStream,
     DWORD dwReserved)
 {
-  RapiContext* context = rapi_context_current();
-  context->rapi_error = E_NOTIMPL;
-  context->last_error = ERROR_CALL_NOT_IMPLEMENTED;
-  return E_NOTIMPL;
+  HRESULT hr;
+  WCHAR* wide_dll_path      = wstr_from_current(pDllPath);
+  WCHAR* wide_function_name = wstr_from_current(pFunctionName);
+
+  if ((!wide_dll_path) || (!wide_function_name)) {
+          wstr_free_string(wide_dll_path);
+          wstr_free_string(wide_function_name);
+          return E_INVALIDARG;
+  }
+
+  hr = CeRapiInvoke( wide_dll_path, wide_function_name, cbInput, pInput,
+      pcbOutput, ppOutput, ppIRAPIStream, dwReserved);
+
+  wstr_free_string(wide_dll_path);
+  wstr_free_string(wide_function_name);
+
+  return hr;
 }
-
Index: src/rapi2.c
===================================================================
--- src/rapi2.c	(revision 3784)
+++ src/rapi2.c	(working copy)
@@ -105,7 +105,7 @@
         _NotImplementedIRAPIStream_Read2,  /* IRAPIStream_Read */
         _NotImplementedIRAPIStream_Write2, /* IRAPIStream_Write */
         /* IRAPIStream_GetRawSocket, */   /* IRAPIStream_GetRawSocket */
-        _NotImplementedCeRapiInvoke2,     /* CeRapiInvoke */
-        _NotImplementedCeRapiInvokeA2,    /* CeRapiInvokeA */
+        _CeRapiInvoke2,     /* CeRapiInvoke */
+        _CeRapiInvokeA2,    /* CeRapiInvokeA */
 #endif /* SWIG */
 };
------------------------------------------------------------------------------
_______________________________________________
SynCE-Devel mailing list
SynCE-Devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/synce-devel

Reply via email to