interop

How to use .Net assembly from Win32 without registration?

烂漫一生 提交于 2019-11-29 01:38:46
问题 I'd like to dynamically load and use a .Net assembly created in C# from a Delphi Win32 application. My classes and interfaces are marked as ComVisible, but I would like to avoid registering the assembly. Is this possible? P.S. I found here link text another good discussion on the topic, but it is more around hosting the CLR. Which begs a question - why would you host CLR versus using ClrCreateManagedInstance? 回答1: Strangely enough, I couldn't find an answer on StackOverflow, and there is not

How to dispose of a NET COM interop object on Release()

别说谁变了你拦得住时间么 提交于 2019-11-29 01:37:20
问题 I have a COM object written in managed code (C++/CLI). I am using that object in standard C++. How do I force my COM object's destructor to be called immediately when the COM object is released? If that's not possible, call I have Release() call a MyDispose() method on my COM object? My code to declare the object (C++/CLI): [Guid("57ED5388-blahblah")] [InterfaceType(ComInterfaceType::InterfaceIsIDispatch)] [ComVisible(true)] public interface class IFoo { void Doit(); }; [Guid("417E5293

Call a Haskell function in .NET

有些话、适合烂在心里 提交于 2019-11-29 01:31:09
I want to use a Haskell function with the following type :: string -> string from a C# program. I want to use hs-dotnet to bridge both worlds. The author claim that it's possible, but provide no sample of this case. The only samples provided are the one to use .NET from Haskell. Is there a sample of this use, or how to use it? (I used .NET Reflector on the bridging assembly, but I didn't understand a thing.) While your way works, it's worth noting that the dificulties you encountered were of your own doing unfortunately (and not a bug in GHC ) :( (The following assumes you used the GHC

Is it absolutely safe to display a WPF window from a WinForms form?

耗尽温柔 提交于 2019-11-29 01:30:22
问题 I would like to display a WPF window from a windows forms application (.NET 3.5). This code seems to work without any problem in a sample project: public partial class WinFormsForm1 : Form { public WinFormsForm1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { WpfWindow1 w = new WpfWindow1(); w.Show(); } } The form is started from Main() as a normal Winforms form: Application.Run(new WinFormsForm1()); This seems to me too easy to be true. Are there any

Call function from DLL?

南楼画角 提交于 2019-11-29 01:04:58
I'm new to C# and I'm trying to learn to usage of DLLs. I'm trying to wrap my objects in a DLL, and then use it in my program. public class Foo // its in the DLL { public int ID; public void Bar() { SomeMethodInMyProgram(); } } So I try to pack this to a DLL but I can't, because compiler doesn't know what the SomeMethodInMyProgram() is. I would like to use it like: class Program // my program, using DLL { static void Main(string[] args) { Foo test = new Foo(); test.Bar(); } } Add the DLL via the solution explorer - right click on references --> add reference then "Browse" to your DLL - then it

Excel Interop - Add a new worksheet after all of the others

江枫思渺然 提交于 2019-11-29 01:04:22
I am trying to add a new worksheet to an Excel workbook and make this the last worksheet in the book in C# Excel Interop. It seems really simple, and I thought the below code would do it: using System.Runtime.InteropServices; using Excel = Microsoft.Office.Interop.Excel; namespace ConsoleApplication2 { class Program { static void Main(string[] args) { var excel = new Excel.Application(); var workbook = excel.Workbooks.Open(@"C:\test\Test.xlsx"); workbook.Sheets.Add(After: workbook.Sheets.Count); workbook.Save(); workbook.Close(); Marshal.ReleaseComObject(excel); } } } No such luck. I get this

Parsing a .NET DataSet returned from a .NET Web Service in Java

帅比萌擦擦* 提交于 2019-11-29 00:30:54
问题 I have to consume a .NET hosted web service from a Java application. Interoperability between the two is usually very good. The problem I'm running into is that the .NET application developer chose to expose data using the .NET DataSet object. There are lots of articles written as to why you should not do this and how it makes interoperability difficult: http://www.hanselman.com/blog/ReturningDataSetsFromWebServicesIsTheSpawnOfSatanAndRepresentsAllThatIsTrulyEvilInTheWorld.aspx http://www

Embed bash in python

…衆ロ難τιáo~ 提交于 2019-11-29 00:24:57
问题 I am writting a Python script and I am running out of time. I need to do some things that I know pretty well in bash, so I just wonder how can I embed some bash lines into a Python script. Thanks 回答1: If you want to call system commands, use the subprocess module. 回答2: The ideal way to do it: def run_script(script, stdin=None): """Returns (stdout, stderr), raises error on non-zero return code""" import subprocess # Note: by using a list here (['bash', ...]) you avoid quoting issues, as the #

What should I know when developing interoperable WCF web service?

*爱你&永不变心* 提交于 2019-11-29 00:15:09
I'm starting this Wiki to collect best practices about creating interoperable web services (not clients) in WCF. Please share your experience if you know any feature which is not generally interoperable or which is not interoperable with specific platform. Fairly simple: avoid any .NET specifics like Exceptions (turn them into SOAP faults) don't use any binding that start with net like netTcp, netNamedPipes, netMsmq and so forth - use wsHttpBinding for secure WS-* services, and basicHttpBinding for maximum reach / compatibility with even the weirdest client platforms don't use the

C# Marshalling double* from C++ DLL?

ⅰ亾dé卋堺 提交于 2019-11-28 23:36:58
I have a C++ DLL with an exported function: extern "C" __declspec(dllexport) double* fft(double* dataReal, double* dataImag) { [...] } The function calculates the FFT of the two double arrays (real and imaginary) an returns a single double array with the real an imaginary components interleaved: { Re, Im, Re, Im, ... } I'm not sure how to call this function in C#. What I'm doing is: [DllImport("fft.dll")] static extern double[] fft(double[] dataReal, double[] dataImag); and when I test it like this: double[] foo = fft(new double[] { 1, 2, 3, 4 }, new double[] { 0, 0, 0, 0 }); I get a