General XMetaL Discussion
freyp576 February 24, 2011 at 1:15 pm
Unable to call Range method GreaterThan from C#/COM-InteropFebruary 24, 2011 at 1:15 pmParticipants 2Replies 3Last Activity 11 years, 9 months ago
we are rewriting (part of) our old VB6 code using C# and accessing the XMetaL API through COM Interop. We are using Visual Studio 2008 and XMetaL 6.0
how can we call the IsGreaterThan/IsLessThan/IsEqual methods on a Range object
to compare it with an other range? COM Interop seems to provide IsGreaterThan as get_IsGreaterThan, strange.
Trying to do the following:
done = !(oRange.get_IsGreaterThan(oRangeLeft) && oRange.get_IsLessThan(oRangeRight)) || oRange.get_IsEqual(oRangeOld);
causing an error, “Keine Überladung für die get_IsGreaterThan-Methode nimmt 1 Argumente an.”
or in english, no overload for the get_IsGreaterThan method takes 1 arguments
also, it would be nice to do something like that:
done = !((oRange > oRangeLeft) && (oRange < oRangeRight)) || oRange.get_IsEqual(oRangeOld); but this results in: Fehler Der Operator “>” kann nicht auf Operanden vom Typ “XMetaL.Range” und “XMetaL.Range” angewendet werden.
(the operator … cannot be applied to operands of type …)
Is there a way to use XMetaL API/Range objects through COM Interop from C# code?
Are there samples how to do that?Derek Read February 24, 2011 at 5:45 pm
Reply to: Unable to call Range method GreaterThan from C#/COM-InteropFebruary 24, 2011 at 5:45 pm
Microsoft has some tutorials on COM interop for C# here that might help:
Note that some of this help is written specifically for VS 2003, 2005 or 2008. I'm not sure how much it varies, but they do have different pages for some versions.freyp576 February 25, 2011 at 9:10 am
Reply to: Unable to call Range method GreaterThan from C#/COM-InteropFebruary 25, 2011 at 9:10 am
thanks for the link. I will check that.
Also, I found the cause of my problem in the meantime. IsGreaterThan has an additional argument – and no default value when called from C#:
bool get_IsGreaterThan(XMetaL.Range Selection, bool OrEqual)
Member von XMetaL.Selection
so after passing false as value for the second argument, I was able to solve my problem.
Peter FreyDerek Read February 25, 2011 at 9:44 pm
Reply to: Unable to call Range method GreaterThan from C#/COM-InteropFebruary 25, 2011 at 9:44 pm
There's another good article here specifically on this subject and how different versions of C# handle parameters:
Scroll down to the section labelled “COM Interfaces” for information that will relate directly to how you write your code to interact with XMetaL (or anything else via COM). I have not tested the C# 4.0 feature they discuss here called “named and optional arguments”, but if it works for MS Office applications using COM then in theory it should work for anything.
- You must be logged in to reply to this topic.