BUG: RPC Encoding API MyType_Encode() Causes Access Violation

ID: Q181651

The information in this article applies to:

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          : kbnetwork kbAPI kbNTOS400bug kbRPC kbSDKPlatform kbGrpNet 
Hardware          : x86
Issue type        : kbbug
Solution Type     : kbpending

Last Reviewed: July 31, 1998