interop

How can I write a generic C function for calling a Win32 function?

旧时模样 提交于 2019-12-06 00:52:49
问题 To allow access to the Win32 API from a scripting language (written in C), I would like to write a function such as the following: void Call(LPCSTR DllName, LPCSTR FunctionName, LPSTR ReturnValue, USHORT ArgumentCount, LPSTR Arguments[]) which will call, generically, any Win32 API function. (the LPSTR parameters are essentially being used as byte arrays - assume that they have been correctly sized to take the correct data type external to the function. Also I believe that some additional

COMException (0x80010108 - RPC_E_DISCONNECTED) When Closing Excel.Workbook

霸气de小男生 提交于 2019-12-06 00:25:45
When I run the following code, I get the exception below: ''# NOTE: ExcelApp is a Private main form variable Dim ReportBooks As Excel.Workbooks = ExcelApp.Workbooks Dim ReportBook As Excel.Workbook = ReportBooks.Open(localFilename) Dim ReportSheet As Excel.Worksheet = ReportBook.Sheets("Report") ''# Retreive data from sheet ReleaseCOM(ReportSheet) ReportBook.Close(True) ''# Error raised here ReleaseCOM(ReportBook) ReleaseCOM(ReportBooks) ERROR: COMException was unhandled The object invoked has disconnected from its clients. (Exception from HRESULT: 0x80010108 (RPC_E_DISCONNECTED)) Note: All

CoCreateInstance exact match in .NET?

巧了我就是萌 提交于 2019-12-05 22:35:31
I have in-proc (DLL) COM Server, but I settled in to run as DllSurrogate, for this reason from unmanaged code (Delphi) i have: function TComWrapper.GetServer: IUnknown; begin OleCheck(CoCreateInstance(ServerData^.ClassId, nil, CLSCTX_LOCAL_SERVER, IUnknown, Result)); end; from C# am using now: [DllImport("ole32.dll", EntryPoint = "CoCreateInstance", CallingConvention = CallingConvention.StdCall)] static extern UInt32 CoCreateInstance([In, MarshalAs(UnmanagedType.LPStruct)] Guid rclsid, IntPtr pUnkOuter, UInt32 dwClsContext, [In, MarshalAs(UnmanagedType.LPStruct)] Guid riid, [MarshalAs

Marshalling of C Struct as return value of C# delegate

走远了吗. 提交于 2019-12-05 22:34:20
I'm attempting to return a small (8 byte) struct by value from a delegate bound to a native function, but am running into the following error when targeting the .NET Framework 2.0 (the code seems to work correctly when targeting 4.0+): An unhandled exception of type 'System.AccessViolationException' occurred in testclient.exe Additional information: Attempted to read or write protected memory. This is often an indication that other memory is corrupt. I suspect I've messed up the managed type annotations such that the return value isn't being marshalled correctly, but I can't see what I'm doing

Using .NET class from native C++ using C++/CLI as a 'middleware'

亡梦爱人 提交于 2019-12-05 22:29:14
I have to use a class/assembly made in C# .NET from native C++ application. I suppose I need to make a wrapper class in C++/CLI, that would expose native methods in header files, but use .NET class as needed. Thing that's unclear to me is how to convert data types from .NET to standard C++ types. Does anybody have some sample code to learn from? Only text I have found on this is: http://msdn.microsoft.com/en-us/magazine/cc300632.aspx But text is very old (using Managed C++, not C++/CLI), and lot of things remains unclear Yes you need to build a wrapper with C++/CLI around your managed assembly

C# Excel Interop : Excel process remains in memory until parent form closed

落花浮王杯 提交于 2019-12-05 22:24:14
问题 In my form I am doing something as simple as private void btnPrintPickList_Click(object sender, EventArgs e) { using (var salesRpt = new SalesOrder(CurrentItem())) { salesRpt.CreateSpreadSheet(); salesRpt.Dispose(); } } I have followed the "no 2 dots rule for excel interop". protected ExcelSheet(bool documentVisible, XlPageOrientation orientation) { ExcelApplication = new Application {Visible = documentVisible}; WorkBooks = ExcelApplication.Workbooks; WorkBook = WorkBooks.Add(XlSheetType

java mixed with clojure in maven and eclipse

给你一囗甜甜゛ 提交于 2019-12-05 22:06:06
i created a sample polyglot program. i have a sensor and a robot implemented in java and AI implemented in clojure. and i can't connect maven properly --src/main/java/clojuretest | DistanceSensor.java AI.clj (uses DistanceSensor) Robot.java (uses AI) DistanceSensor.java: package clojuretest; public class DistanceSensor { public int getValue() {return 5;} } AI.clj: (ns clojuretest.AI (:gen-class :methods [[isObstacleAhead [] boolean]])) (defn -isObstacleAhead [this] (< (.getValue (clojuretest.DistanceSensor.)) 10)) Robot.java: package clojuretest; public class Robot { public boolean shouldStop(

Interop'ing between C# and an unmanaged C library

怎甘沉沦 提交于 2019-12-05 21:51:35
I have a small C library in a DLL and I need to call a handful of its methods. It uses pointers and a few structs but is otherwise quite simple. Problem is I'm not terribly knowledgable on .NET's interop with the unmanaged world and my attempts so far keep hitting memory access violation exceptions (presumably due to me not getting the pointers quite right). Could anyone give me some pointers (ooh a pun!) on the best way to approach this? Thank you extern vconfig_t *Pobsopen(Ppoly_t ** obstacles, int n_obstacles); extern int Pobspath(vconfig_t * config, Ppoint_t p0, int poly0, Ppoint_t p1, int

JavaFX Script and Java

强颜欢笑 提交于 2019-12-05 21:42:21
Simple question: Can I mix in my desktop application Java and JavaFX Script code? If it is possible could you provide me with some link with examples? Or could I pack my custom made javafx CustomNode-s in a jar and use them in my project side by side with standard SWING components? This article gives an example of calling JavaFX from Java, using the Scripting API . Yes, you can mix Java and JavaFX. According to one of the FAQ entries : In addition, developers can use any Java library in their JavaFX applications. This allows JavaFX applications to take advantage of the rich JavaFX UI libraries

Problem creating COM-library only containing enum's

人盡茶涼 提交于 2019-12-05 20:33:19
I'm am doing a COM-interop project. Substituting some VB and C++ ATL COM projects with C# and .NET Interop. When i define enumerations in .NET and they are made ComVisible, they get exposed as Typelib.EnumType_EnumValue enstead of just Typelib.EnumValue. The typelib exporter does this to ensure that the value names are unique. But i know that all my enum's are unique, so i don't want the underscores. Also there is a lot of client code that needs alteration if i don't get rid of the underscores. To find a solution to this problem, i have defined the enum's in an IDL-file and creating a typelib