LighthouseMike
Member
- Joined
- Jul 20, 2020
- Messages
- 11
- Programming Experience
- 5-10
Hey guys, happy Friday!
As usual, Microsoft's propensity to create ultra-complex hierarchies of objects upon objects upon objects has me completely baffled. So in Word, there are 2 "shape" (picture) object types that I know of: Shapes and InlineShapes. Shapes have a "Name" property that corresponds with what users have called them, or default placeholders like "Picture 1". InlineShapes are significantly more mysterious, much better obfuscated from the view of most developers. I've tried things like InlineShapes[1].Range.ShapeRange[with or without numeric index].Name, InlineShapes[1].Title, I've tried casting from an InlineShape to a Shape, and all through this hair-jerker of a bug battle it's been error after error after error, an infinite loop of trial / error / DuckDuckGo. I've been all over MSDN, Stack Overflow, and other usual places like this. Anyone know where in the name of William Q. Gates they hid that darn name/title/label/McWhatsits?
EDIT: I get normally you'd want to see some code (apart from the examples above) but the only code I have is the code that gets the reference to the object (and I know I have a valid object). Sorry in my complete frustration I forgot that (didn't think it was relevant, but of course it is since I didn't tell u what the errors were lol). Here's that, in case you want it:
As usual, Microsoft's propensity to create ultra-complex hierarchies of objects upon objects upon objects has me completely baffled. So in Word, there are 2 "shape" (picture) object types that I know of: Shapes and InlineShapes. Shapes have a "Name" property that corresponds with what users have called them, or default placeholders like "Picture 1". InlineShapes are significantly more mysterious, much better obfuscated from the view of most developers. I've tried things like InlineShapes[1].Range.ShapeRange[with or without numeric index].Name, InlineShapes[1].Title, I've tried casting from an InlineShape to a Shape, and all through this hair-jerker of a bug battle it's been error after error after error, an infinite loop of trial / error / DuckDuckGo. I've been all over MSDN, Stack Overflow, and other usual places like this. Anyone know where in the name of William Q. Gates they hid that darn name/title/label/McWhatsits?
EDIT: I get normally you'd want to see some code (apart from the examples above) but the only code I have is the code that gets the reference to the object (and I know I have a valid object). Sorry in my complete frustration I forgot that (didn't think it was relevant, but of course it is since I didn't tell u what the errors were lol). Here's that, in case you want it:
C#:
// Create a new Word window
var word = new Application();
counter.Add(word); // Counter is a bugfix - they forgot to automatically free the unmanaged COM pointers in the interop API, so if you don't do C++-style manual memory management you get a Word/Excel process hanging in limbo until you reboot or discover it. So retro problems call for retro solutions - this is a reference-counter. :D
word.Visible = true;
// Open the doc I'm using for testing
var documents = word.Documents;
counter.Add(documents);
var doc = documents.Open(@"C:\whatever.docx");
counter.Add(doc);
var shapes2 = doc.InlineShapes; // "shapes2" because I did something similar with regular "shapes"
counter.Add(shapes2);
for (var i = 1; i <= shapes2.Count; i++)
{
var shape = shapes2[i];
counter.Add(shape);
Console.WriteLine(shape.This.That.Object.Interface.Property.Method.Collection.Blah.Blah.Blah.Blablabloogendah.ObviouslyThisIsTheProblemLOL);
}
// EDIT 2: Forgot a line :D
while(true) {
hair--;
sanity = 7 * "cheese" / (0x0C0005 | "pepperoni"); // hmmm, must be lunchtime. :D
}
Last edited: