com-interop

Register a C#/VB.NET COM dll programmatically

爱⌒轻易说出口 提交于 2019-11-27 20:10:55
Question: I have a .NET dll which I use from a C++ program. Now I have to register the dll programmatically on a deployment computer. How do I do that (programmatically! not using regasm)? I remember, when I once called a VB6 dll from a C++ dll, I had to use DllRegisterServer and DllUnregisterServer. Is that still so with a .NET dll? It seems I have to somehow add the dllregisterserver function to the .NET dll. YUK, .NET dlls don't have DllRegisterServer, so you have to write a .NET installer, executing this somewhere: Assembly asm = Assembly.LoadFile (@"c:\temp\ImageConverter.dll");

Is it possible to intercept (or be aware of) COM Reference counting on CLR objects exposed to COM

空扰寡人 提交于 2019-11-27 19:17:53
问题 I have rephrased this question. When .net objects are exposed to COM Clients through COM iterop, a CCW (COM Callable Wrapper) is created, this sits between the COM Client and the Managed .net object. In the COM world, objects keep a count of the number of references that other objects have to it. Objects are deleted/freed/collected when that reference count goes to Zero. This means that COM Object termination is deterministic (we use Using/IDispose in .net for deterministic termination,

SetWindowsHookEx returns 0 when compiling for the .NET 4.0 framework in 32bit machines

那年仲夏 提交于 2019-11-27 18:31:08
问题 I'm trying to set a low level windows keyboard hook to grab three keys pressed even if the application is not in focus. To do this I'm calling SetWindowsHookEx as // Create an instance of HookProc. KeyboardHookProcedure = new HookProc(KeyboardHookProc); //install hook hKeyboardHook = SetWindowsHookEx( WH_KEYBOARD_LL, KeyboardHookProcedure, Marshal.GetHINSTANCE( Assembly.GetExecutingAssembly().GetModules()[0]), 0); //If SetWindowsHookEx fails. if (hKeyboardHook == 0) { //Returns the error code

“Register for COM Interop” vs “Make assembly COM visible”

泪湿孤枕 提交于 2019-11-27 17:09:38
What is the real difference between these two options? What I know is: Register for COM Interop This options executes regasm on the assembly and registers the assembly as an COM component(or maybe not) in the registry with all COM like registry entries. Does this step generates a TLB file? What else is done? Sometimes I see a tlb is generated when I compile the project but sometimes not, why is this? Make assembly COM visible What effect does this one has on an assembly? If I have the following type inside this assembly, do I still need to specify the "Make assembly COM Visible" even though my

Registering COM referenced DLLs on a build server

与世无争的帅哥 提交于 2019-11-27 14:08:43
问题 We're developing a C# application that references a few COM libraries (AutoIT for example). I am including all referenced components under source control, in a 3rd party "Libs" folder. The problem is that COM dll's don't have a HintPath property in the .csproj file, and i assume these must be manually registered using regsvr32 (or using a script of some sort). I am currently looking into creating an MSBuild script that will run before every build, however i couldn't figure out if i should be

Calling regasm without administrative rights for COM interop in Excel VBA

喜你入骨 提交于 2019-11-27 13:19:28
A workaround for calling regasm without the admin rights was described here already: COM Interop without regasm I'm trying to create a COM library that my users can deploy and use from Excel VBA without the admin privileges. I liked the regasm workaround, since it seems that people don't have much success with using registration-free COM objects from Excel VBA. I also want early binding so my users can benefit from syntax completion. The accepted answer in the question mentioned above, however, doesn't describe where to put the assembly dll on the user's computer. Admin rights are required to

How to correctly marshal VB-Script arrays to and from a COM component written in C#

你说的曾经没有我的故事 提交于 2019-11-27 13:17:54
I'm building a COM object in C# (.Net 4.0) to be used in an classic asp site. Now I'd like to know what's the proper way to marshal VB-Script arrays (single and multidimensional) back and forth between the component and the asp site? A code sample would be highly appreciated. VBScript only likes to handle SAFEARRAY's that contain VARIANTS. And it likes to have these passed arround in VARIANTS on the COM methods or properties. So you need to construct a VARIANT property that contains a SAFEARRAY of VARIANT type. The following C# code does this. First using just a plain array of objects and then

An MTA Console application calling an STA COM object from multiple threads

纵饮孤独 提交于 2019-11-27 13:11:46
问题 Although there are many questions about COM and STA/MTA (e.g. here), most of them talk about applications which have a UI. I, however, have the following setup: A console application, which is by default Multi-Threaded Apartment (Main() explicitly has the [MTAThread] attribute). The main thread spawns some worker threads. The main thread instantiates a single-threaded COM object. The main thread calls Console.ReadLine() until the user hits 'q', after which the application terminates. A few

Building a COM interop library for ASP Classic using 4.0 framework and Visual Studio 2010

社会主义新天地 提交于 2019-11-27 12:15:21
After going through a number of different articles and not finding anything especially conclusive that takes me step-by-step through the process, I've come seeking help. The Scenario A client of mine is only proficient in development for ASP Classic . They have recently acquired an account for a site originally written in ASP.NET. They are rolling the site into something they can actively maintain, but the site originally included an image handler that took dynamically changing data regarding water levels and outputs an image containing a graphical representation of that data. The requirement

Type exists in 2 assemblies

ε祈祈猫儿з 提交于 2019-11-27 11:52:48
I have created two .NET Interop assemblies from two different third-party COM DLLs. Both of the COM DLLs contained a type named COMMONTYPE . Therefore, COMMONTYPE is now exposed through the two Interop assemblies as well. I have a third project that needs to use these two Interop assemblies, and I get the infamous compile time error: The type <ABC> exists in both <ASSEMBLY1.dll> and <ASSEMBLY2.dll> Since the COM DLLs are provided by a third-party vendor, I have no access to the source code, and I'm writing a C# Console application, which means I have no web.config file where I could add the