Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Mobile Development
  3. Mobile
  4. structure mapping for wm_copy_data

structure mapping for wm_copy_data

Scheduled Pinned Locked Moved Mobile
csharpc++helpquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sliver80
    wrote on last edited by
    #1

    Hi, i've two mobile application, one in c++ and the other in c# that exchange a structure with wm_copy_data. If i have a simple int inside the struct, everything work fine, but i have problem with the correct struct definition in c# code. Here is the c++ app code:

    typedef struct tagMYRECASR
    {
    char roName[100];
    char roRole[100];
    char rpName[100];

    } MYASR;

    COPYDATASTRUCT MyCDS;
    MYASR MyRec;

    char *roName;
    char *roRole;
    char *rpName;

    CString rp = _T("rp_it-it");
    CString vbRoName = rp;
    vbRoName += "/";
    vbRoName += grmName;

    CString vbRoRole = _T("");
    CString vbRpName = _T("");

    ConvertToMultibyte(&roName,vbRoName);
    ConvertToMultibyte(&roRole,vbRoRole);
    ConvertToMultibyte(&rpName,vbRpName);

    strcpy(MyRec.roName,(const char*)roName);
    strcpy(MyRec.roRole,(const char*)roRole);
    strcpy(MyRec.rpName,(const char*)rpName);

    MyCDS.dwData = 1; // function identifier
    MyCDS.cbData = sizeof( MyRec ); // size of data
    MyCDS.lpData = &MyRec;
    HWND window = ::FindWindow(NULL, _T("ManageWindow"));

    if(window!=NULL) {
    ::SendMessage(window, WM_COPYDATA, (WPARAM)(HWND) window, (LPARAM) (LPVOID) &MyCDS );

    In c# i tried to define the structure in this way:

    [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
    struct UserData
    {
    [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 100)]
    public string roName;
    [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 100)]
    public string roRole;
    [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 100)]
    public string rpName;
    }

    and in many other way, but it doesn't work any idea? consider me a newbye. thanks in advance

    S 1 Reply Last reply
    0
    • S sliver80

      Hi, i've two mobile application, one in c++ and the other in c# that exchange a structure with wm_copy_data. If i have a simple int inside the struct, everything work fine, but i have problem with the correct struct definition in c# code. Here is the c++ app code:

      typedef struct tagMYRECASR
      {
      char roName[100];
      char roRole[100];
      char rpName[100];

      } MYASR;

      COPYDATASTRUCT MyCDS;
      MYASR MyRec;

      char *roName;
      char *roRole;
      char *rpName;

      CString rp = _T("rp_it-it");
      CString vbRoName = rp;
      vbRoName += "/";
      vbRoName += grmName;

      CString vbRoRole = _T("");
      CString vbRpName = _T("");

      ConvertToMultibyte(&roName,vbRoName);
      ConvertToMultibyte(&roRole,vbRoRole);
      ConvertToMultibyte(&rpName,vbRpName);

      strcpy(MyRec.roName,(const char*)roName);
      strcpy(MyRec.roRole,(const char*)roRole);
      strcpy(MyRec.rpName,(const char*)rpName);

      MyCDS.dwData = 1; // function identifier
      MyCDS.cbData = sizeof( MyRec ); // size of data
      MyCDS.lpData = &MyRec;
      HWND window = ::FindWindow(NULL, _T("ManageWindow"));

      if(window!=NULL) {
      ::SendMessage(window, WM_COPYDATA, (WPARAM)(HWND) window, (LPARAM) (LPVOID) &MyCDS );

      In c# i tried to define the structure in this way:

      [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
      struct UserData
      {
      [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 100)]
      public string roName;
      [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 100)]
      public string roRole;
      [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 100)]
      public string rpName;
      }

      and in many other way, but it doesn't work any idea? consider me a newbye. thanks in advance

      S Offline
      S Offline
      slumberparty
      wrote on last edited by
      #2

      Try to use StringBuilder to convert from character arrays.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups