BUG: RPC Encoding API MyType_Encode() Causes Access Violation

Last reviewed: February 25, 1998
Article ID: Q181651
The information in this article applies to:
  • Microsoft Windows NT, version 4.0 on the following platform:

        - x86
    

SYMPTOMS

If you define MyType as a structure with a union that has structures as union_arms in your IDL file, the Midl generated type encoding function, MyType_Encode(), may fail with the following error code:

   0xC0000005 Access Violation

CAUSE

In some specific cases, a union that contains structures may cause Midl to produce incorrect offset for the description of the structure. As a result, the Midl generated stub routine crashes in the marshaling engine.

RESOLUTION

Change your union member inside MyType from a flat member to a pointer type.

Sample Code

For example, given the following type definitions:

   typedef enum _MyStructEnum {
      MyStructEnum1, MyStructEnum2
   } MyStructEnum;

   typedef struct _MyStruct1 {
      char   foo;
   } MyStruct1;

   typedef struct _MyStruct2 {
      long   length;
      [size_is(length)] char* bytes;
   } MyStruct2;

   // A union with structs as arms.
   typedef [switch_type(MyStructEnum)] union {
      [case(MyStructEnum1)]     MyStruct1 myStruct1;
      [case(MyStructEnum2)]     MyStruct2 myStruct2;
   } MyUnion;


Change the myUnion field of MyType listed below:

   typedef struct _MyType {
      long                        someData;
      MyStructEnum                whichStruct;
      [switch_is(whichStruct)]    MyUnion myUnion;
   } MyType;


to a pointer to MyUnion as follows:

   typedef struct _MyType {
      long                        someData;
      MyStructEnum                whichStruct;
      [switch_is(whichStruct)]    MyUnion *myUnion;
   } MyType;

STATUS

Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. We are researching this bug and will post new information here in the Microsoft Knowledge Base as it becomes available.

REFERENCES

X/Open DCE: Remote Procedure Call


Additional query words: Type, Encoding, Midl, union_arms
Keywords : NtwkRpc
Version : WINNT:4.0
Platform : winnt
Hardware : x86
Issue type : kbbug
Solution Type : kbpending


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: February 25, 1998
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.