title: Boost IPC Message_Queue try_receive throws interprocess_exception::library_error
body: <p>I am making interprocess communication between two of my processes with boost::interprocess::message_queue.</p>
  
  <p>This is the first time I'm using it so this exception isn't clear to me because I cannot find any documentation on it.</p>
  
  <p>I have my classes setup as following:</p>
  
  <pre><code>struct Pos{float X,Y,Z;};
  struct Quat{float W,X,Y,Z;};
  typedef unsigned char Byte;
  struct NPCDataFoot
  {
      //some Pos and Quat variables here too
      unsigned short AnimationIndex;
      void Apply(NPCDataFoot &amp;data){AnimationIndex=data.AnimationIndex;}
      NPCDataFoot(){AnimationIndex=0;}
  };
  struct NPCDataVehicle
  {
      //many many more
      unsigned short lrAnalog;
      void Apply(NPCDataVehicle &amp;data){lrAnalog=data.lrAnalog;}
      NPCDataVehicle(){lrAnalog = 0;}
  };
  enum TransmissionDataType{
      TDT_NewNPC,//many more...
  };
  const unsigned short QueueMaxSize = 256;
  struct ExchangeData
  {
      unsigned short  CommandType;
      unsigned short  NPCPlayerID;
      Byte            State;
      NPCDataFoot     OnFootData;
      NPCDataVehicle  InCarData;
      float MoveSpeed;
      Pos MoveToPos;
      //206
      ExchangeData(unsigned short CommandType = 0, unsigned short NPCPlayerid = 0xFFFF)
          : CommandType(CommandType), NPCPlayerID(NPCPlayerid)
      {}
      ExchangeData(unsigned short CommandType, unsigned short NPCPlayerid, NPCDataFoot&amp; foot_data, NPCDataVehicle&amp; car_data)
          : CommandType(CommandType), NPCPlayerID(NPCPlayerid), OnFootData(foot_data), InCarData(car_data)
      {}
  };
  </code></pre>
  
  <p>both my programs are set to compile with the /zp1 flag (Align structures/classes to 1-byte alignment).</p>
  
  <p>now whenever I reach this code:</p>
  
  <pre><code>ServerMsgQueue * message_queue = NULL;
  PLUGIN_EXPORT void PLUGIN_CALL
      ProcessTick()
  {
      static bool init = false;
      static ExchangeData DataTransmision;
      if(!init)
      {
          try
          {
              ServerMsgQueue = new message_queue(open_or_create              
                      ,string_format("REMOTESHAREDMEMORYBTWNPRCS%04x",GetServerVarAsInt("port")).c_str()
                      ,1024 * QueueMaxSize,sizeof(ExchangeData)); 
          }
          catch(interprocess_exception &amp;ex)
          {
              std::cout &lt;&lt; ex.what() &lt;&lt; ":" &lt;&lt; __FILE__ &lt;&lt; ":" &lt;&lt; __FUNCTION__ &lt;&lt; ":" &lt;&lt; __LINE__ &lt;&lt; std::endl;
          }
          init = true;
      }
      static unsigned int unused;
      if(ServerMsgQueue)
      {
          try
          {
              if(ServerMsgQueue-&gt;try_receive(&amp;DataTransmision,sizeof(ExchangeData),unused,unused))
              {
                  switch(DataTransmision.CommandType)
                  {//some cases
                  default:{std::cout &lt;&lt; "UNKNOWN RECEIVED DATA!!!" &lt;&lt; std::endl;break;}
                  }
              }
          }
          catch(interprocess_exception &amp;ex)
          {
              //this happens always
              std::cout &lt;&lt; ex.what() &lt;&lt; ":" &lt;&lt; __FILE__ &lt;&lt; ":" &lt;&lt; __FUNCTION__ &lt;&lt; ":" &lt;&lt; __LINE__ &lt;&lt; std::endl;
          }
      }
  }
  </code></pre>
  
  <p>The application keeps issuing "boost::interprocess_exception::library_error" in the block where <code>try_receive</code> is being used.</p>
  
  <p>What am I doing wrong in this case? I'm sure the data send is the same size because 1) i use the same header and 2) I compile with the same options.</p>
  
  <p>I have confirmed that the variable sizes are the same with the following code in both programs:</p>
  
  <pre><code>MessageBox(NULL,string_format(
  "Pos(%d):Quat(%d):NPCDataFoot(%d):NPCDataVehicle(‌​%d):ExchangeData(%d)",
  sizeof(Pos),sizeof(Quat),sizeof(NPCDataFoot),sizeof(NPCData‌Vehicle),sizeof(ExchangeData)).c_str()
  ,"Reported sizes Client",0);
  </code></pre>
  
  <hr>
  
  <p>Edit: I seem have "solved" it.. magicly;</p>
  
  <p>It seems that this code was the error:</p>
  
  <pre><code>static unsigned int unused;
  if(ServerMsgQueue-&gt;try_receive(&amp;DataTransmision,sizeof(ExchangeData),unused,unused))
  </code></pre>
  
  <p>changed it to</p>
  
  <pre><code>unsigned int Priority;
  size_t sizexxx;
  if(ServerMsgQueue-&gt;try_receive(&amp;DataTransmision,sizeof(ExchangeData),sizexxx,Priority))
  </code></pre>
  
  <p>Can someone explain why this works and the other code not?</p>