interop

Using F1 Help (CHM format) With WPF

一笑奈何 提交于 2019-11-28 08:19:42
I've been working on a WPF application for a while, and the time has come to attach the CHM format help document to it. But alas! HelpProvider, the standard way to show CHM files in Winforms, has magically vanished and has no counterpart in WPF. I've been trying to use WindowsFormsHost to spawn a new control so I can actually display the help, but essentially it just grabs control of the entire UI. A little more detail: I've got a menu item that I want to, when clicked, open up the CHM file. First I set up the WindowsFormsHost... host = new System.Windows.Forms.Integration.WindowsFormsHost();

Accessing static inner class defined in Java, through derived class

≯℡__Kan透↙ 提交于 2019-11-28 08:03:20
问题 I've got some classes defined in java, similar to the code below. I'm trying to access SomeValue through a derived java class, which is allowed in java, but not in kotlin. Is there a way to access the field through the derived class? // java file // ------------------------------------------------- class MyBaseClass { public static final class MyInnerClass { public static int SomeValue = 42; } } final class MyDerivedClass extends MyBaseClass { } // kotlin file // -----------------------------

How to check, programmatically, if MS Excel exists on a pc?

耗尽温柔 提交于 2019-11-28 07:31:48
I have an application that needs MS Excel to run, otherwise it crashes. So I want to check and warn the user in case Excel is not installed on user's machine. How do I do this? Type officeType = Type.GetTypeFromProgID("Excel.Application"); if (officeType == null) { //no Excel installed } else { //Excel installed } As a quick fix you could just catch the exception and implement proper error handling. Then you can inform the user there. const string ASSEMBLY2003 = "Microsoft.Office.Interop.Excel, Version=11.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"; static bool IsAssemblyInstalled

How to free IntPtr in C#?

左心房为你撑大大i 提交于 2019-11-28 07:24:11
问题 How to free ptrSentFromPinvokedDLL? IntPtr ptrSentFromPinvokedDLL= IntPtr.Zero; int resultFromVendor = CallVendorDll(ref ptrSentFromPinvokedDLL); resultFromVendor = DoMoreWorkFromVendorDLL( ptrSentFromPinvokedDLL, "workonthis"); // Free ptrSentFromPinvokedDLLhere 回答1: Ideally either the vendor worries about this or there would be a vendor function for deallocating the memory. If not, you need to know how the vendor allocated the memory. For example, if the vendor allocated the memory using

Convert Interface IDL file to C#

给你一囗甜甜゛ 提交于 2019-11-28 06:52:32
I have an interface defined in an IDL file that I would like to use in C#. Is there a way to convert the IDL to something usable in C#? One way is to run MIDL on the IDL to create a type library (.tlb). This requires a library block in the IDL. Once you have the .tlb, you can run tlbimp.exe on it to get a C# definition/Interop DLL. DevByDefault What datatypes/structures are used in the IDL? You should first define the datatypes in C# first if there is no inbuild type already. You can use the following tool to convert the structures, but you need to verify the ouput manually. Download: http:/

How to call win32 CreateMutex from .Net

谁都会走 提交于 2019-11-28 06:42:35
问题 I've been successfully creating a .net mutex like this: SingleIns = new Mutex(true, AppName); for a while. It works in XP, Vista, but apparently not in Windows7. So I need to make an interop call to a Win32 library so other Com components can identify the mutex. I found the following code, but the Win32Calls. is not found... is there an assembly or reference I need? Thanks in advance, Found code from: http://www.pinvoke.net/default.aspx/kernel32/CreateMutex.html using System.Runtime

Read data from Excel files

烈酒焚心 提交于 2019-11-28 06:18:28
问题 I'm having some trouble reading from an Excel spreadsheet in C#. I have this code which I read every cell from A to X. System.Array myvalues; string[] strArray; Microsoft.Office.Interop.Excel.Range range = worksheet.get_Range("A" + i.ToString(), "W" + i.ToString()); while(range.Count!=0) { i++; //Console.WriteLine(i); range = worksheet.get_Range("A" + i.ToString(), "W" + i.ToString()); myvalues = (System.Array)range.Cells.Value; strArray = ConvertToStringArray(myvalues); name = clearstr

Can C++/CLI be used to call .NET code from native C++ applications? [closed]

折月煮酒 提交于 2019-11-28 05:34:01
I've done the other way around (calling pure C++ code from .NET) with C++/CLI, and it worked (for the most part). How is the native-to-C++/CLI direction done? I really don't want to use COM interop... You can always host the CLR in your native app. Daniel Earwicker If you have an existing native C++ app and want to avoid "polluting" it with too much CLR stuff, you can switch on the /clr flag for just one specific file and use a standard C++ header to provide an interface to it. I've done this in an old bit of code. In the header I have: void SaveIconAsPng(void *hIcon, const wchar_t

find the process tree in .NET

假装没事ソ 提交于 2019-11-28 05:24:02
问题 I'm looking for an easy way to find the process tree (as shown by tools like Process Explorer), in C# or other .NET language. It would also be useful to find the command-line arguments of another process (the StartInfo on System.Diagnostics.Process seems invalid for process other than the current process). I think these things can only be done by invoking the win32 api, but I'd be happy to be proved wrong. 回答1: If you don't want to P/Invoke, you can grab the parent Id's with a performance

Bullet points in Word with c# Interop

丶灬走出姿态 提交于 2019-11-28 05:21:57
问题 I have the following code which is supposed to add a bulleted list to a word document that I'm generating automatically. From other answers I believe the code is correct, but the result doesn't produce any bullet points at all, it doesn't seem to apply the indent either. Any Ideas? Microsoft.Office.Interop.Word.Paragraph assets; assets = doc.Content.Paragraphs.Add(Type.Missing); // Some code to generate the text foreach (String asset in assetsList) { assetText = assetText + asset + "\n"; }