com-interop

Passing strongly typed arguments in .NET COM interop

烂漫一生 提交于 2019-11-30 21:08:04
I have two .NET classes exposed via COM interop - let's say Foo and Bar, and I need to pass an argument of type Foo to a method defined in Bar. Something like this: [ComVisible(true)] public class Foo { // whatever } [ComVisible(true)] public class Bar { public void Method(Foo fff) { // do something with fff } } When I run the following VBS (using cscript.exe): set foo = CreateObject("TestCSProject.Foo") set bar = CreateObject("TestCSProject.Bar") call bar.Method(foo) I get an error: D:\test.vbs(3, 1) Microsoft VBScript runtime error: Invalid procedure call or argument: 'bar.Method' However,

COMException (0x800A13E9) - Word interop services

元气小坏坏 提交于 2019-11-30 19:22:44
I am getting this stacktrace: System.Runtime.InteropServices.COMException (0x800A13E9): Word ðú÷ì ááòéä. at Microsoft.Office.Interop.Word.Documents.Add(Object& Template, Object& NewTemplate, Object& DocumentType, Object& Visible) at Crm.DocumentGeneration.Printing.DocumentsPrinter.MergeDocuments(ApplicationClass& wordApp, IEnumerable`1 printDataItems, String tempDirectory, String template) in C:\Work\Danel.Nursing\Crm.DocumentGeneration.Printing\DocumentsPrinter.cs:line 249 After googling a bit it seems that COMException (0x800A13E9) is out of memory exception but there is enough memory on the

what is the advantage of .net4's new no pia feature [deploying PIA's]

混江龙づ霸主 提交于 2019-11-30 17:50:01
问题 Its possibly im just missing something here but, when I write some code for Excel interop, here is how it goes. I add a reference to the Excel Com libraries. VS creates a PIA - Microsoft.Office.Interop.Excel....(via tlbimp right?). I copy the exe and the interop(PIA) dll to any machine (with .net) and it works? Is there a scenario where I would have to deploy/register the PIA? Or have I got something wrong here, because it seems to me embedding the PIA into the main assembly doesn't seem like

How Add a COM-Exposed .NET Project to the VB6 (or VBA) References Dialog?

一笑奈何 提交于 2019-11-30 15:02:15
问题 I have created a .NET assembly that is exposed to COM according to the exceptional article Build and Deploy a .NET COM Assembly by Phil Wilson. And everything works fine in the sense that the .NET assembly is properly registered for COM, and compiled COM code can call it without any trouble. The only odd thing is that developing against the COM-exposed .NET assembly when using VB 6.0 or VBA requires that the programmer 'browse' to the exact file location of the associated .tlb file, after

Pass an array from vba to c# using com-interop

丶灬走出姿态 提交于 2019-11-30 14:24:38
What is the proper way to pass an array of user defined classes from vba to .net (specifically c#) using com-interop? Here's my c# code. If I call Method1 from vba it's failing with "Array or userdefined type expected" or "Function uses an automation type not supported in visual basic". public class MyClass { public Method1(UserDefinedClass[] Parameters) { ... } public Method2(Object Parameters) { ... } } I've read a bit about the MarshallAsAttribute class. Could this be the missing piece in the c# code? Here's the vba code I'm using: Dim udt As New UserDefinedClass Dim myArray() myArray(1) =

Why is the indexer on my .NET component not always accessible from VBScript?

岁酱吖の 提交于 2019-11-30 14:11:27
I have a .NET assembly which I am accessing from VBScript (classic ASP) via COM interop. One class has an indexer (a.k.a. default property) which I got working from VBScript by adding the following attribute to the indexer: [DispId(0)] . It works in most cases, but not when accessing the class as a member of another object. How can I get it to work with the following syntax: Parent.Member("key") where Member has the indexer (similar to accessing the default property of the built-in Request.QueryString : Request.QueryString("key") )? In my case, there is a parent class TestRequest with a

How Add a COM-Exposed .NET Project to the VB6 (or VBA) References Dialog?

旧街凉风 提交于 2019-11-30 13:45:48
I have created a .NET assembly that is exposed to COM according to the exceptional article Build and Deploy a .NET COM Assembly by Phil Wilson. And everything works fine in the sense that the .NET assembly is properly registered for COM, and compiled COM code can call it without any trouble. The only odd thing is that developing against the COM-exposed .NET assembly when using VB 6.0 or VBA requires that the programmer 'browse' to the exact file location of the associated .tlb file, after which everything works just fine. That is, the class library is not showing up directly within the

Lots of build warnings when COM objects ActiveDs or MSXML2 are referenced

元气小坏坏 提交于 2019-11-30 11:59:58
After moving a project from .NET 1.1 to .NET 2.0, MsBuild emits lots of warnings for some COM objects. Sample code for test (actual code doesn't matter, just used to create the warnings): using System; using System.DirectoryServices; using ActiveDs; namespace Test { public class Class1 { public static void Main(string[] args) { string adsPath = String.Format("WinNT://{0}/{1}", args[0], args[1]); DirectoryEntry localuser = new DirectoryEntry(adsPath); IADsUser pUser = (IADsUser) localuser.NativeObject; Console.WriteLine("User = {0}", pUser.ADsPath); } } } Warning messages look like C:\WINDOWS

Do I need to release the COM object on every 'foreach' iteration?

不打扰是莪最后的温柔 提交于 2019-11-30 11:48:41
Here's the (potential) problem: I create a COM object, and then use a 'foreach' to iterate through each element in a collection it returns. Do I need to release each individual element I iterate through in the collection? (See code below.) If so, I can't think of a way to effectively to release it from within a 'finally' statement, just in case there is an error as the item is being operated upon. Any suggestions? private static void doStuff() { ComObjectClass manager = null; try { manager = new ComObjectClass(); foreach (ComObject item in manager.GetCollectionOfItems()) { Log.Debug(item.Name)

How to get specific Range in Excel through COM Interop?

依然范特西╮ 提交于 2019-11-30 09:52:20
i have the following problem. I have to read an excel file through COM interop. I am new to programming with COM interop. I search for a specific string using this: this.sheet = (Excel.Worksheet)this.excelApp.Workbook.Sheets.Item[this.sheetname]; this.sheet.Activate(); Excel.Range firstRow = this.sheet.Range["A1", "XFD1"]; Excel.Range foundRange = firstRow.Find( this.StringISearch, Type.Missing, Type.Missing, Excel.XlLookAt.xlWhole, Excel.XlSearchOrder.xlByColumns, Excel.XlSearchDirection.xlNext, false, false, Type.Missing); No i want to use the foundRange as a starting point to get another