Pages: 1
Print
Author Topic: Unable to call Range method GreaterThan from C#/COM-Interop  (Read 1196 times)
freyp576
Member

Posts: 7


« on: February 24, 2011, 07:15:15 AM »

Hi Derek

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?
Logged
Derek Read
Program Manager (XMetaL)
Administrator
Member

Posts: 1546



WWW
« Reply #1 on: February 24, 2011, 11:45:01 AM »

Microsoft has some tutorials on COM interop for C# here that might help:
http://msdn.microsoft.com/en-us/library/aa645712%28v=VS.71%29.aspx

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.
Logged
freyp576
Member

Posts: 7


« Reply #2 on: February 25, 2011, 03:10:06 AM »

Hi Derek,

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.

best regards,
Peter Frey

Logged
Derek Read
Program Manager (XMetaL)
Administrator
Member

Posts: 1546



WWW
« Reply #3 on: February 25, 2011, 03:44:36 PM »

There's another good article here specifically on this subject and how different versions of C# handle parameters:
http://msdn.microsoft.com/en-us/library/dd264739.aspx

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.
« Last Edit: February 25, 2011, 03:47:13 PM by Derek Read » Logged
Pages: 1
Print
Jump to:  

email us