com

Can I call a static method of a C# class from VBA via COM?

爱⌒轻易说出口 提交于 2019-12-17 20:35:59
问题 If I define a class in a C#/.NET class library, then by making it COM visible I can instantiate the class and call its methods from VBA using COM. Is there any way to call the static methods of such a class from VBA? 回答1: COM does not support static methods, and instances of COM objects do not invoke static methods. Instead, set ComVisible(false) on your static method, then make an instance method to wrap it: [ComVisible(true)] public class Foo { [ComVisible(false)] public static void Bar() {

C# wrapper interface error: E_NOINTERFACE

主宰稳场 提交于 2019-12-17 19:25:21
问题 I am trying to produce a C# wrapper for a COM object that I have (named SC_COM.dll), but am having some issues linking it with Visual Studio 2008 (running Vista). I need to do this registration-free with the COM DLL--I'm using a manifest file to let Visual Studio know about SC_COM.dll, and that appears to be working. I used TblImp.exe to generate a type library (SC_COMtlb.dll) that I'm referencing in Visual Studio 2008 so I can do early binding with the DLL that I need. The DLLs are both in

Utilizing a 32-bit DLL in a 64-bit process via COM

血红的双手。 提交于 2019-12-17 19:24:03
问题 So some time ago I was investigating an issue that I knew would be coming up soon. We have a DLL that links to 32-bit versions of a certain library. There is no x64 version of this library available to us and we have no practical options in regards to replacing it. When I performed this initial investigation I found an article or two describing a method by which a 64-bit process can utilize a 32-bit DLL (Windows) via a COM "server". Unfortunately I lost the links I had saved and I have now

Why is GUID attribute needed in the first place?

久未见 提交于 2019-12-17 18:43:07
问题 What is the necessity for the GUID attribute? why don't just let the compiler handle this automatically?! 回答1: If the compiler handled this automatically, you'd end up with one of two situations. A new GUID every time you compiled - since GUIDs are supposed to be published, this would fail. Collisions - if the GUID was the same every time, based on (say) a Hash of the name, multiple projects would end up using the same GUID for different purposes. The existing approach - an explicit GUID

Unable to cast COM object of type exception

蹲街弑〆低调 提交于 2019-12-17 18:36:37
问题 I have the following code: public void Test(IMyInterface iInterface) { iInterface.CallMethod ( ); } Which works fine. However, if I change the code to be threaded: private IMyInterface myInterface; public void Test(IMyInterface iInterface) { myInterface = iInterface; new Thread ( new ThreadStart ( CallInterfaceMethod) ).Start ( ); } public void CallInterfaceMethod ( ) { myInterface.CallMethod ( ) } When i use the thread I receive the exception: Unable to cast COM object of type 'System._

Get property names via reflection of a COM object

主宰稳场 提交于 2019-12-17 18:26:59
问题 How can I read out all property names via reflection of an COM Object in C#? I know how to get the property if I know the name. comObject.GetType().InvokeMember("PropertyName", System.Reflection.BindingFlags.GetProperty, null, comObject, null); but what is when I want to dump all properties? PropertyInfo[] properties = t.GetProperties(); This way didn't work with Com-Objects. If I do a GetMembers() I get these Members: Name: GetLifetimeService Name: InitializeLifetimeService Name:

Calling C# BHO methods from Javascript

♀尐吖头ヾ 提交于 2019-12-17 18:10:12
问题 I'm trying to figure out how to call C# methods in my BHO object from Javascript within the page. I found numerous pages on how to do it in C++/ATL/Com such as: Browser Helper Objects and Scripts Options Calling BHO method from Javascript? I have tried to follow along and implement it correctly in C#, but I can't get it to work probably due to some obvious COM problems that I have which I don't fully understand. I am using C# 4.0. Here are the relevant parts of the code: using SHDocVw; using

Calling C++ function from JavaScript script running in a web browser control

*爱你&永不变心* 提交于 2019-12-17 17:48:12
问题 I have embedded a web browser control in my c++ application. I want javascript running in the web browser control to be able to call a c++ function/method. I have found mentions of three ways to do this: Implement an ActiveX component that acts as a middle man. (Implementation details here: http://blogs.msdn.com/b/nicd/archive/2007/04/18/calling-into-your-bho-from-a-client-script.aspx) Use window.external. (Also discussed in the link above, but no implementation provided) Add a custom object

Tool for creating .NET wrappers for a COM DLL?

孤街醉人 提交于 2019-12-17 16:44:26
问题 Is there any open source tool for automatically generating .NET wrappers for a COM DLL library? 回答1: You can try to use SWIG which is able to generate wrapper code for 18 languages. Also this MSDN article might be useful. 回答2: There is no wrapper necessary to use a COM object in .NET. In Visual Studio, right-click your project name in the Solution Explorer, and select "Add Reference." Any registered COM objects will be listed in the COM tab. Interop wrappers are only necessary when using .NET

How to properly close Internet Explorer when launched from PowerShell?

孤街醉人 提交于 2019-12-17 16:35:55
问题 There was a set of recently asked questions about doing something with Internet Explorer via PowerShell. All of them contain codes to launch IE from PowerShell as an object, via $ie=new-object -comobject InternetExplorer.Application . The problem is, the proper way of closing IE that consists of calling $ie.quit() does not work - first, if that IE would have happened to have more than a single open tab, IE doesn't quit as a whole and only the tab that corresponds to the COM object is closed,