I have a c# class library that I call to centralize some code amongst projects. It returns an arraylist back to the calling function that contains class data. Anyway when I call it I can receive it as an object and the data looks fine. However when I do the type casting I get the above error. Any ideas. Below is the code. At the bottom you can see the comment on the cast that blows. I have even tried it without using the Object*. I just added that to make sure the get_item call was working properly.
Bob
C# side.
[ StructLayout(LayoutKind.Sequential, CharSet=CharSet.Auto) ]
public class LOGFONT
{
public int lfHeight = 0;
public int lfWidth = 0;
public int lfEscapement = 0;
public int lfOrientation = 0;
public int lfWeight = 0;
public byte lfItalic = 0;
public byte lfUnderline = 0;
public byte lfStrikeOut = 0;
public byte lfCharSet = 0;
public byte lfOutPrecision = 0;
public byte lfClipPrecision = 0;
public byte lfQuality = 0;
public byte lfPitchAndFamily = 0;
[ MarshalAs(UnmanagedType.ByValTStr, SizeConst=32) ] public string lfFaceName = null;
}
public class CStyleSheet
{
public string strTagname = "";
public string strTagContext = "";
public LOGFONT lfFont = new LOGFONT(); // Structure defining the font attributes for each tag us to be logical
public System.Drawing.Color FontColor, BackgroundColor, rgbAlternateColor;
public short LineSpace = 0;
public short SpaceAbove = 0;
public short SpaceBelow = 0;
public short IndentLeft = 0;
public short IndentRight = 0;
public short IndentFirst = 0;
public short[] tabsArray = new short[10];
public short justification = 0;
public ushort Flags = 0;
public ushort ActualFlags = 0;
public string strTextBefore = "";
public string strTextAfter = "";
public string Emph = "";
public ushort InheritanceFlags = 0; // Use to be WORD
public string LinkAttribute = "";
public byte BorderStyle = 0;
public byte SpecialEmph = 0;
public byte ChangeLevel = 0;
public ushort AutonumberStyle = 0;
public int iMatchWeight = 0;
public CStyleSheet()
{
}
}
Visual C++ side.
__gc class CStyleSheet
{
public:
System::String *strtagname;
System::String *strTagContext;
LOGFONT lfFont; // Structure defining the font attributes for each tag
System::Drawing::Color FontColor, BackgroundColor, rgbAlternateColor;
short LineSpace;
short SpaceAbove;
short SpaceBelow;
short IndentLeft;
short IndentRight;
short IndentFirst;
short tabsArray __nogc[MAXTABS];
short justification;
USHORT Flags;
USHORT ActualFlags;
System::String *strTextBefore;
System::String *strTextAfter;
System::String *Emph;
USHORT InheritanceFlags; // Use to be WORD
System::String *LinkAttribute;
byte BorderStyle;
byte SpecialEmph;
byte ChangeLevel;
USHORT AutonumberStyle;
int iMatchWeight;
};
Header defs:
gcroot<System::Collections::ArrayList*> StyleArray;
gcroot<CStyleSheet*> pGCStyleStruct;
Cpp calls
Load Works just fine.
StylesIO::CStylesIO *myStyles = new StylesIO::CStylesIO();
StyleArray = myStyles->LoadStyleSheet(strPath, theApp.m_pActiveWnd);
Type cast where it blows
Object* myObject;
myObject = pDoc->StyleArray->get_Item(1);
CStyleSheet *sty1 = new CStyleSheet ();
sty1 = (CStyleSheet *) myObject; ********* Blows here.