Wikipedia:Reference desk/Archives/Computing/2016 June 24
Computing desk | ||
---|---|---|
< June 23 | << May | June | Jul >> | June 25 > |
Welcome to the Wikipedia Computing Reference Desk Archives |
---|
The page you are currently viewing is an archive page. While you can leave answers for any questions shown below, please ask new questions on one of the current reference desk pages. |
June 24
editCOM objects in C#
edit(To forestall the obvious comments - can we assume it's the year 2005 for the purposes of this question? Using more up-to-date tools is not an option. Thanks.)
In VB6, to instantiate a COM object and use one of its interfaces, we can do:
Dim oTemp As Object
Dim oRealObject As MyTypeLib.IMyInterface
Set oTemp = CreateObject("MyDll.CMyClass")
If TypeOf oTemp Is MyTypeLib.IMyInterface Then
Set oRealObject = oTemp
oRealObject.DoThings
Else
MsgBox "MyDll.CMyClass does not support the IMyInterface interface!"
End If
In C#, we can do something similar:
Type comType = Type.GetTypeFromProgID("MyDll.CMyClass");
var instance = Activator.CreateInstance(comType);
if (somethingOrOther) // This is my question
{
IMyInterface realObject = (IMyInterface)instance;
realObject.DoThings();
}
else
{
MessageBox.Show("MyDll.CMyClass does not support the IMyInterface interface!");
}
What should "somethingOrOther" be? comType.Equals(typeof(IMyInterface))
returns false, even though
instance
does in fact implement the IMyInterface
interface (and the DoThings
function works properly). Thanks in advance. Tevildo (talk) 14:41, 24 June 2016 (UTC)
- You should use
typeof(IMyInterface).IsAssignableFrom(typeof(comType))
. (From here.) The reason thatcomType.Equals(typeof(IMyInterface))
returns false is because for simple equality comparison,comType
does not equalIMyInterface
.Type.IsAssignableFrom()
uses more complex comparison. Fr∧m∈Dr∧gtalk 14:56, 24 June 2016 (UTC)- Thanks for the link! It turns out that it's a lot simpler:
if (instance is IMyInterface)
. But I didn't manage to get there on my own, so the reply was still very useful. Tevildo (talk) 15:18, 24 June 2016 (UTC)
- Thanks for the link! It turns out that it's a lot simpler:
Word and Excel file size limitation
editWhy is the file size limited to 32 MB (for the total document text, not counting images and such)? Why did they limit the file size to 512 MB? Images can simply be linked and loaded when viewed, can't they? (according to MS). Most computers nowadays have much more memory than this. And why the discrepancy between text/image file size? Excel has also analogous file size limitations. 1,048,576 rows by 16,384 columns. I wonder whether it loads the whole file in memory. But even then, a file with 1,000,000+ lines could well be in the single-digit MB range. --Llaanngg (talk) 18:51, 24 June 2016 (UTC)
- Sometimes it is a performance issue -- if certain data structures get too large it takes a long time to search, sort, and index them, so the developers limit the size to avoid customer complaints. :( In other words, "that's why we can't have nice things"... --Guy Macon (talk) 20:08, 24 June 2016 (UTC)
- Although this makes sense in general, searching/sorting/indexing through 32 MB of text is not that difficult/slow. I was thinking that it might be that Word performs other operations, whose running time grows exponentially. Maybe their layout? Llaanngg (talk) 23:56, 24 June 2016 (UTC)
Pretty sure you're right. Word isn't a simple text editor, it aims to be a WYSIWYG word processor. Changing some simple things can easily require reformatting of the whole document. There are ways to handle such things, e.g. desktop publishing utilities like Adobe InDesign obviously do. (You could abandon WYSIWYG and instead embrace separation of presentation and content ala LaTeX etc but while it's popular in some areas like HTML to some extent, and circles, it's IMO not nearly as widespread as often seems to be suggested on the RD. Without commenting whether that's good or bad.)
Even for a WYSIWYG word processor, Microsoft's designs are unlikely to be the most effective but they presumably consider them sufficient for the program they're designing. (Consider also they may have needed fundamental changes to improve things, which even under their best estimation would probably break something and take quite a lot of time for possibly minimal benefit. There's a good chance that sort of core stuff may not have changed that much since the controversial Office Open XML.)
I guess you've never tried opening and editing a file with something close to 32 MB of text in any WYSIWYG word processor? (Which for 8 bit text is 33554432 characters or probably at least 4793490 words if English. Evidentally more than the entire Wheel of Time series [1].) When I've tried it's not a pleasant experience I can tell you. Admitedly I think I've only tried 2 or maybe 3 (but pretty sure more than Word). Once you add other things like complicated formating well....
IIRC Word doesn't actually have to have finished formatting the whole document before you can see the beginning but this still means you can't see the end for quite a while. (If the document was formatted before, nominally it could show the old formatting. I can't remember if it does though.)