interop

Calling a VB6 method from a .NET DLL

混江龙づ霸主 提交于 2020-01-09 08:08:19
问题 I have a DLL written in VB 6 and another DLL written in Visual Studio 2005 (VB.NET). Now I want to invoke the method of the VB DLL from my .NET DLL. What should I do for this? Any thoughts? 回答1: As VB6 creates COM DLLs, Visual Studio should have no problems generating an interop stub for you. Simply add a reference to the VB6 DLL from your .NET project by selecting Add Reference in Visual Studio and finding your DLL under the COM tab. Make sure the VB6 DLL is registered on your machine before

Exporting a native C function from a .net DLL? [duplicate]

久未见 提交于 2020-01-09 07:52:08
问题 This question already has answers here : Is is possible to export functions from a C# DLL like in VS C++? (4 answers) Closed 3 years ago . I have a .net assembly written in C#, and I'm looking to export a native C function from the assembly. I have an application which will perform a 'LoadLibrary()' on any DLL's found in a 'plugin' folder. After loading the DLL, the application performs a 'GetProcAddress' looking for a function named 'Register'. The application expects this function to follow

.Net Excel Interop Deleting a worksheet

↘锁芯ラ 提交于 2020-01-09 03:43:46
问题 I'm trying to delete a worksheet from a excel document from a .Net c# 3.5 application with the interop Excel class (for excel 2003). I try many things like : Worksheet worksheet = (Worksheet)workbook.Worksheets[1]; worksheet.Delete(); It's doesn't work and doesn't throw any error ... 回答1: After more than one hour looking I found the answer: xlApp.DisplayAlerts = false; worksheet.Delete(); xlApp.DisplayAlerts = true; 回答2: When dealing with deleting Excel Worksheets , there are two important

How do I handle null or optional dll struct parameters in C#

南楼画角 提交于 2020-01-08 14:36:15
问题 How do I deal with optional struct arguments in dll methods called from C# using pinvoke? For example, the lpSecurityAttributes parameter here should be passed null when absent. The correct way of passing struct 's seems to be using ref , but it cannot have optional parameters, or take null in general. What ways are there to achieve this? 回答1: You have a few options 1) Use a class instead of a struct I think this method is the easiest. Simply declare the struct as a class : [StructLayout

Cannot get interface from different process via ROT

旧时模样 提交于 2020-01-07 07:01:18
问题 my app is an .exe, it registers itself to ROT. [ComVisible(true)] [ProgId("My.App")] public class MyApp { public Interop_MyApp.IXXX XXX { get { return XXXImpl.Instance; } // -> Instance is derived from Interop_MyApp.IXXX, and static } public MyApp() { } }; I start the .exe above, it's running. Then I start an other .exe, which tries to get the XXX. object o = Marshal.GetActiveObject("My.App"); // -> returns a __ComObject, fine if (o == null) throw new InvalidOperationException("Could not

Using assemblyresolve to handle missing assemblies in C#

二次信任 提交于 2020-01-07 04:32:40
问题 I am following Method 3 in http://support.microsoft.com/kb/837908 to load assemblies dynamically in C#. However, the code is not working for me. In the following section of the code, the author loads the missing assembly only if the name of missing assembly is one of the assemblies referenced by the application. When I run this under debug, the function is getting called, but the missing assembly is not in any of those referenced assemblies, and so it is not set in my case. Any ideas why is

How can I write a signature on C# for a wrapped C++ method having double indirection on its arguments?

自古美人都是妖i 提交于 2020-01-07 02:48:07
问题 I'm writing a wrapper for a dll. The dll has a method whose signature resembles the following: unsigned long aMethod(char **firstParameter, char **secondParameter)) aMethod returns string pointers to all parameters. I've searching at google for a tutorial to give me insight on how to write the signature on C# so the framework can do the marshalling process. How can it be written? Do you know about any tutorial, book or documentation on this subject? 回答1: Not really answering you question but

Synchronizing a WPF ScrollViewer with a WinForms ScrollBar

你说的曾经没有我的故事 提交于 2020-01-06 14:39:08
问题 Due to an unsolved issue in my current project [ Weird scrollbar UI in hosted WPF composite control ], I've had to defer to workarounds. One such idea I came up with was to keep the ScrollViewer in question in sync with a Windows Forms ScrollBar (horizontal and vertical). How would I go about doing that? In essence, I want the WinForms scrollbar(s) to work like the ScrollViewers (in terms of dragging and events suchlike). 回答1: I think there's no any other way than send/listen to the lo-level

C# Microsoft.Office.Interop.Word

ぐ巨炮叔叔 提交于 2020-01-06 05:45:08
问题 I'm using Microsoft.Office.Interop.Word with C#. I know that you can set the text to be bold by using Range.Font.Bold=1. My problem is that I have a long sentence and I have to make some words bold in it, not the whole sentence. If my sentence is "Would you like to have responses to your questions sent to you via email?", I would like "have responses" to be bold. With this example I can bold only one word (by looping through the whole word document): foreach(Microsoft.Office.Interop.Word

How to copy excel columns from one file to another?

泄露秘密 提交于 2020-01-05 17:09:24
问题 I using excel addin application, to create function which can copy columns from one excel file to another. Here is the code so far but when I render the application, however the program outputs a blank book.xls file. private void button1_Click(object sender, EventArgs e) { Excel.Application xlApp = new Microsoft.Office.Interop.Excel.Application(); Excel.Workbook xlWorkBook; Excel.Workbook xlWorkBook2; Excel.Worksheet xlWorkSheet; Excel.Worksheet xlWsheet2; Excel.Range xlSourceRange; Excel