[wx-dev] IPC issues

Brian Vanderburg II BrianVanderburg2 at aim.com
Sat Dec 1 06:38:39 PST 2007


Vadim Zeitlin wrote:
> On Fri, 30 Nov 2007 21:05:12 -0500 Brian Vanderburg II <BrianVanderburg2 at aim.com> wrote:
>
> BVI> After doing some work on IPC and testing it in the current stable and 
> BVI> partial testing in the dev branch I came to the following conclusion.
>
>  Notice that wxIPC behaviour is quite different in 2.8 and trunk. All my
> remarks apply to the trunk only.
>
> BVI> So for the server to be most flexible it should do something like this?
>
>  In trunk it should just wxIPC_UTF8TEXT.
>
> BVI> But DDE on MSW seems to only 'best' support sending it in the format the 
> BVI> program is compiled in and receiving it likewise.
>
>  DDE is supposed to use Unicode in Unicode build (i.e. always now). I don't
> see where would the conversion to multibyte happen with it, do you?
>
> BVI> Also the above tests wouldn't work well with DDE so extra code would be 
> BVI> needed:
>  This is indeed a problem. We probably need a function in wxConnectionBase
> to convert (data, size) to wxString.
>   
It would be nice if any Execute(char*, wchar_*t*, wxSting*) would do 
right. For TCP server, it could remain as it (ansi for char*, unicode 
for wchar_t and utf8 for wxString), with a helper function like 
GetDataAsText().  Keeping it the same and not always converting it to 
utf8 may be more efficient.

wxString GetDataAsText(const void* data, size_t size, wxIPCFormat format)
{
    assert(format is valid)

    #if wxUSE_DDE_FOR_IPC
       // the received data in GetDdeData is always in the format the 
program is in
       wxUnusedVar(format)
       #if wxUSE_UNICODE
          return wxString((wchar_t*)data, size);
       #else
          return wxString((char*)data, size);
       #endif
    #else
       if(format == wxIPC_TEXT)
          return wxString((char*)data, wxConvLibc);
       else if(format == wxIPC_UTF8TEXT)
         return wxString((char*)data, wxConvUTF8);
      else
         return wxString((wchar_t*)data);
    #endif
}

There is a minor problem with this code.  If an empty string is sent 
then the return string IsEmpty should be true, but the size will include 
the null terminator and so
wxString(data, size) will have the extra null that it should not have.  
Perhaps this could be fixed by adjusting 'size' to exclude the NULL:

wxString GetDataAsText(const void* data, size_t size, wxIPCFormat format)
{
    assert(format is valid)

    if(size == 0)
       return wxEmptyString;

#define FixSize(type, str, len) while(len > 0 && *((type*)str + len / 
sizeof(type) - 1) == 0) { len--; }


    #if wxUSE_DDE_FOR_IPC
       // the received data in GetDdeData is always in the format the 
program is in
       wxUnusedVar(format)
       #if wxUSE_UNICODE
          FixSize(wchar_t, data, size)
          return wxString((wchar_t*)data, size);
       #else
          FixSize(char, data, size)
          return wxString((char*)data, size);
       #endif
    #else
       if(format == wxIPC_TEXT)
       {
          FixSize(char, data, size)  
          return wxString((char*)data, wxConvLibc);
       }
       else if(format == wxIPC_UTF8TEXT)
       {
          FixSize(char, data, size)
          return wxString((char*)data, wxConvUTF8);
       }
      else
       {
          FixSize(wchar_t, data, size)
          return wxString((wchar_t*)data);
        }
    #endif
}
> BVI> After doing testing the new code, it seems that MSW execute does not 
> BVI> even work at all when saying Execute(const char*).
>
>  Hmm, what happens? Can you reproduce this in the exec sample?
>   
It was an error in my code, saying OnExecute(... void* data) instead of 
OnExecute(... const void* data) so it wasn't an overload of the virtual 
function and the base function was called returning false.
>  Thanks,
> VZ
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: wx-dev-unsubscribe at lists.wxwidgets.org
> For additional commands, e-mail: wx-dev-help at lists.wxwidgets.org
>
>   
Brian Vanderburg II




More information about the wx-dev mailing list