interop

Getting UI text from external app in C#

梦想的初衷 提交于 2019-12-05 01:38:29
问题 Is it possible to get UI text from an external application in C#. In particular, is there a way to read Unicode text from a label (I assume it's a normal Windows label control) from an external Win32 app that was written by a 3rd party? The text is visible, but not selectable by mouse in the UI. I assume there is some accessibility API (e.g. meant for screen readers) that allows this. Edit: Currently looking into using something like the Managed Spy App but would still appreciate any other

How to add multiple recipients to mailitem.cc field c#

十年热恋 提交于 2019-12-05 01:27:55
Oki, so im working on outlook .msg templates. Opening them programmatically, inserting values base on what's in my db. ex. when i want to add multiple reciepients at "To" field, instead of doing as following, mailitem.To = a + ";" + b + ";" + c; i do whats below, which is simpler, especially when i'm doing it in a loop. mailitem.Recipients.add("a"); mailitem.Recipients.add("b"); mailitem.Recipients.add("c"); My problem is, i also want to add multiple recipients at "CC" field and the function above only works for "To" field. How can i add multiple recipients to "CC" field without having to do

Is it possible to expose a C# Enum to COM Interop callers, and if so, how?

拥有回忆 提交于 2019-12-05 01:21:12
I have a managed assembly that gets called via COM Interop. Like a VBScript client, a Perl client, and so on. The classes are decorated with [ClassInterface(ClassInterfaceType.AutoDual)] [GuidAttribute("ebc25cf6-9120-4283-b972-0e5520d0000E")] [ComVisible(true)] Then of course I do the regasm thing, and all the methods work just fine. But there are also enum types in the assembly. I'd like to use symbolic names COM applications, for the enum values. How do I expose the enums via COM interop? Do I just need to add these attributes? [GuidAttribute("ebc25cf6-9120-4283-b972-0e5520d0000E")]

Wrapping up a C++ API in Java or .NET

南楼画角 提交于 2019-12-05 01:19:55
问题 Has anyone successfully "wrapped up" a C++ API in Java or .NET? I have an application that provides a C++ API for writing plug-ins. What I'd like to do is access that API from .NET or Java. Would I need to use COM, or are there simpler/better alternatives? 回答1: If you have a very straight forward method signatures (i.e. methods that takes and returns primitive types such as int, char[], void* ... etc), it is reasonably easy to do so in .NET and still possible but a bit harder in Java with JNI

Is there a way to release unmanaged resources when a Go struct is collected?

邮差的信 提交于 2019-12-05 00:34:35
I have a pointer to a C type wrapped by a Go struct, like so: type Wrapper struct { unmanaged *C.my_c_type } The C type, in turn, has the following functions: my_c_type* make_c_type(); void free_c_type(my_c_type *ct); Is there a way that I can ensure that free_c_type is called whenever a Wrapper instance is finalized? You can use runtime.SetFinalizer . This allows you to run a cleanup function when the object falls out of scope. It is not guaranteed to run. However, when freeing memory, that does not really matter. What does matter is that for a long running process, it is likely to keep the

How can I get C# to interop with Javascript?

北城余情 提交于 2019-12-04 22:16:56
问题 I'd like to host Javascript in my C# program. I would like to allow users to write custom Javascript code, and have my C# program run their functions, as well as allow the users to use my framework code. Is it possible to do this? If so, how? Edit: To be clear, I am not using ASP.NET for this project. 回答1: you can also use a webbrowser control to host the javascript in a html document, to interact between the two you would make a COM visible class and set an instance of it to the

Connecting c++ and c# code with a c++/cli bridge

半腔热情 提交于 2019-12-04 21:59:44
I have a client application in native c++ code which is using native c++ dlls. I am investigating the possibility of connecting this code with c# dlls as they would be much easier to write. I decided to write a c++/cli bridge dll which can be loaded with LoadLibrary and which would pass the calls to c# dll. The communication between the client and the dll is such that the client passes a pointer to an interface object through which the dll then communicates with the client. I wrapped this object in the c++/cli bridge code for the c# code to use it. The bridge should also expose several

Passing pointers from unmanaged code

此生再无相见时 提交于 2019-12-04 21:54:58
问题 I have a C# project that imports a C dll, the dll has this function: int primary_read_serial(int handle, int *return_code, int *serial, int length); I want to get access to the serial parameter. I've actually got it to return one character of the serial parameter, but I'm not really sure what I'm doing and would like to understand what is going, and of course get it working. So, I'm very sure that the dll is being accessed, other functions without pointers work fine. How do I handle pointers?

Cannot call COM object created from STAThread from oher STA threads

倾然丶 夕夏残阳落幕 提交于 2019-12-04 21:26:07
问题 I am new to COM and trying to understand the difference between STA and MTA. I tried to create an example that would show that COM can manage calls to object created in STA that is not thread-safe. MyCalcServer class here is created using ATL Simple Object. The settings used are the same as in this article: Threading Model: Apartment Aggregation: No Interface: Custom MyCalcServer COM object is used in another C# project which is: class Program { [STAThread] static void Main(string[] args) {

Exposing events from .NET to COM

霸气de小男生 提交于 2019-12-04 19:47:07
recently I have been encountering problems with exposing events from .NET to COM. I have been successful with this example (conceptually taken from http://blogs.msdn.com/andreww/archive/2008/10/13/exposing-events-from-managed-add-in-objects.aspx ): // The delegate type for our custom event. [ComVisible(false)] public delegate void SomeEventHandler(object sender, EventArgs e); // Outgoing (source/event) interface. [ComVisible(true)] [InterfaceType(ComInterfaceType.InterfaceIsIDispatch)] public interface IAddInEvents { [DispId(1)] void SomeEvent(object sender, EventArgs e); } [ComVisible(true)]