interop

C++ Interop: How do I call a C# class from native C++, with the twist the class is non-static?

久未见 提交于 2019-11-30 04:03:58
I have a large application written in native C++. I also have a class in C# that I need to call. If the C# class was static, then it would be trivial (there's lots of examples on the web) - just write the mixed C++/CLI wrapper, export the interfaces, and you're done. However, the C# class is non-static, and can't be changed to static as it has an interface (the compiler will generate an error if you attempt to make the C# class static). Has anyone run into this problem before - how do I export a non-static C# class to native C++? Update 2010-11-09 Final solution: tried COM, this worked nicely

Communicating between C# and VBA

我是研究僧i 提交于 2019-11-30 04:03:42
问题 At the request of my boss I created a small set of scripts that are used to periodically monitor the status of certain devices and processes. This info is subsequently processed using a relatively elaborate VBA module that gathers all info, applies formulas, sets up ranges and generates graphs, etc. There are two problems however: I'm an amateur programmer, so my VBA routine is quite inefficient. That's not a huge problem for me (I just get up and get a coffee while it's running), but for

Tips for using a C library from C#

本秂侑毒 提交于 2019-11-30 03:59:21
I've got a library in C which I'd like to use from C#. From what I've gleaned off the internet, one idea is to wrap it in a C++ dll, and DllImport that. The problem is that the function I want to call has a fairly nasty parameter set: including a reference to a function (which will be a .NET function), and a couple of arrays (some write, some read). int lmdif(int (*fcn)(int, int, double*, double*, int*), int m, int n, double* x, double ftol, double xtol, double gtol, int maxfev, double epsfcn, double factor) Given an interface like this, what are the nasties I should be looking out for? (And

How to use .Net assembly from Win32 without registration?

a 夏天 提交于 2019-11-30 03:58:58
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? Sergey Aldoukhov Strangely enough, I couldn't find an answer on StackOverflow, and there is not much on the Net, especially for Delphi. I found the solution from examples posted here .

How to pass a typed collection from clojure to java?

狂风中的少年 提交于 2019-11-30 03:28:35
I know the basics of clojure/java interop: calling java from clojure and vice versa. However, I was not able to return a typed collection from clojure to java. I am trying to see something of that nature List<TypedObject> from the java code which is calling into clojure. Java Object: public class TypedObject { private OtherType1 _prop1; public OtherType1 getProp1() { return _prop1; } public void setProp1(OtherType1 prop1) { _prop1 = prop1; } } CLojure method: (defn -createListOfTypedObjects "Creates and returns a list of TypedObjects" [input] ;Do work here to create and return list of

Embed bash in python

最后都变了- 提交于 2019-11-30 03:19:50
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 ghostdog74 If you want to call system commands, use the subprocess module. 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 # arguments are passed in exactly this order (spaces, quotes, and newlines won't # cause problems): proc

C# and Excel Interop issue, Saving the excel file not smooth

ⅰ亾dé卋堺 提交于 2019-11-30 02:47:15
问题 I could Open and Write to the excel file, but when I try to save the file by passing a path to it, the save operation prompts with the Save dialog. I was expecting it to quitely Save the file at the specified path The code is as below: excelApp.Save(exportToDirectory); excelApp.Quit(); where, exportToDirectory is: "C:\files\strings.xlsx". PS: I have already checked with the excel version and similar issue. Thanks 回答1: You need to use Workbook.SaveAs instead of Application.Save : Excel

.NET Interop IntPtr vs. ref

浪尽此生 提交于 2019-11-30 02:25:08
Probably a noob question but interop isn't one of my strong points yet. Aside from limiting the number of overloads is there any reason I should declare my DllImports like: [DllImport("user32.dll")] public static extern int SendMessage(IntPtr hWnd, int msg, int wParam, IntPtr lParam); And use them like this: IntPtr lParam = Marshal.AllocCoTaskMem(Marshal.SizeOf(formatrange)); Marshal.StructureToPtr(formatrange, lParam, false); int returnValue = User32.SendMessage(_RichTextBox.Handle, ApiConstants.EM_FORMATRANGE, wParam, lParam); Marshal.FreeCoTaskMem(lParam); Rather than creating a targeted

How can I write to an Excel spreadsheet using Linq?

淺唱寂寞╮ 提交于 2019-11-30 02:22:23
I'm writing an app where I need to retrieve some rows from a DB and dump them into an Excel spreadsheet. I'm using Linq to retrieve these rows. Is it possible to dump these rows directly into their counterparts in the Excel sheet (where one cell in Excel corresponds to one cell from the DB)? There's no direct way to connect these two. It sounds like you want LINQ to SQL to handle the query generation, but not the O/R mapping (because Excel wouldn't know what to do with the objects that come out of LINQ- they don't look like data rows any more). You can do that first part by calling

Using C/inline assembly in C#

狂风中的少年 提交于 2019-11-30 02:08:32
Is there some method of using C source mixed with inline asm (this is not C++ code) in a C# app? I'm not picky about how it gets done, if it requires compiling the C/asm into a DLL alongside the C# app, so be it. I'm aware there's no provision for using assembly inside C#, hence this question. Sample code of what I'm trying to incorporate: SomeFunc(unsigned char *outputData, unsigned char *inputData, unsigned long inputDataLength) { _asm { //Assembly code that processes inputData and stores result in outputData } } There are some pointer/variable declarations in the C code before that function