interop

Java <-> Scala interop: transparent List and Map conversion

孤街浪徒 提交于 2019-11-27 09:35:08
问题 I am learning Scala and I have a Java project to migrate to Scala. I want to migrate it by rewriting classes one-by-one and checking that new class didn't break the project. This Java project uses lots of java.util.List and java.util.Map . In new Scala classes I would like to use Scala’s List and Map to have good-looking Scala code. The problem is that new classes (those are wtitten in Scala) do not integrate seamelessly with existing Java code: Java needs java.util.List , Scala needs its own

.Net Excel Interop Deleting a worksheet

寵の児 提交于 2019-11-27 09:24:30
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 ... Melursus After more than one hour looking I found the answer: xlApp.DisplayAlerts = false; worksheet.Delete(); xlApp.DisplayAlerts = true; itsho When dealing with deleting Excel Worksheets , there are two important things to know: Excel interop counts from 1 (and not from zero), therefore, removing the second item

How to pass a nullable type to a P/invoked function [duplicate]

懵懂的女人 提交于 2019-11-27 09:05:20
This question already has an answer here: How do I handle null or optional dll struct parameters in C# 1 answer I have a few p/invoked functions (but I'm rewriting my code at the moment so I'm tidying up) and I want to know how to use/pass a nullable type as one of the parameters. working with int types isn't a problem but given the following: [DllImport("setupapi.dll", CharSet = CharSet.Auto, SetLastError = true)] static extern IntPtr SetupDiGetClassDevs(ref Guid ClassGuid, int? enumerator, IntPtr hwndParent, uint Flags); I'd like to be able to pass the Guid parameter as a nullable type. As

how to access PHP variables from within JavaScript?

浪尽此生 提交于 2019-11-27 08:53:25
问题 This question was migrated from Software Engineering Stack Exchange because it can be answered on Stack Overflow. Migrated 8 years ago . I want to access PHP(server side file variables) with JavaScript(Client side script) without using MySQL. e.g. i have $name=Tom; How do i access this $name variable in JavaScript? Please show code example as i am new to programming. Thank you. 回答1: You could do something like <script> php_variable = <?= json_encode($php_variable) ?>; </script> which should

Changing a C# delegate's calling convention to CDECL

て烟熏妆下的殇ゞ 提交于 2019-11-27 08:37:47
I have had this problem with C# when I was using DotNet1.1 The problem is this. I have an unmanaged dll, which has a function which takes a function pointer (among other arguments). When I declare the DLLImport in C# code, I pass a delegate. But the delegates in C# have stdcall calling convention whereas the unmanaged function expects a cdecl function pointer. Thus my naive approach resulted in crashes. Then I found the following: http://www.codeproject.com/KB/cs/cdeclcallback.aspx Some guy wrote an excellent library that enables changing calling convention of the delegate by, as I understood,

Add offset to IntPtr

冷暖自知 提交于 2019-11-27 08:34:04
I'm looking for a way to perform pointer operations in C# or .NET in particular. I want to do something very simple Having a pointer IntPtr I want to get IntPtr object which points to 2 bytes ahead. I read some post that the foolowing snippet will work... IntPtr ptr = new IntPtr(oldptr.ToInt32() + 2); But I have doubts whether this statement is also valid for 64-bit machine (since addressing is in 64-bits there).. I found this elegant method to add offset, but unfortunately is in .NET 4.0 only http://msdn.microsoft.com/en-us/library/system.intptr.add%28VS.100%29.aspx Laurent Etiemble I suggest

Releasing temporary COM objects

谁都会走 提交于 2019-11-27 08:25:29
Consider the following C# code using a COM object. MyComObject o = new MyComObject; try { var baz = o.Foo.Bar.Baz; try { // do something with baz } finally { Marshal.ReleaseComObject(baz); } } finally { Marshal.ReleaseComObject(o); } This will release the COM objects o and baz , but not the temporary objects returnd by o.Foo and o.Foo.Bar . This can cause problems, when those objects hold a large amount of unmanaged memory or other resources. An obvious but ugly solution would be, to clutter the code even more with try-finally and Marshal.ReleaseComObject . See C# + COM Interop, deterministic

Passing a C# callback function through Interop/pinvoke

早过忘川 提交于 2019-11-27 07:50:51
I am writing a C# application which uses Interop services to access functions in a native C++ DLL. I am already using about 10 different functions which are working. Now I am not sure how to handle passing a callback as a parameter so that the DLL can call my code. Here is the function prototype of the DLL: typedef void (WINAPI * lpfnFunc)(const char *arg1, const char *arg2) And the function that allows me to pass the above type: int WINAPI SetFunc(lpfnFunc f) Here is my C# code for the delegate and function definitions: public delegate void Func(string arg1, string arg2); public static void

Using D programming language in a .NET context

独自空忆成欢 提交于 2019-11-27 07:44:59
问题 I'm curious: has anyone used D together with .NET languages? Is that even possible? What kind of stuff is easier/makes sense to do in D that's hard to do in, say, C++/CLI? 回答1: Using D together with .NET is very possible. The reason: .NET is able to import unmanaged C libraries (.dll's which export C functions) using the dllImport attribute. D is able to export C functions. using the export and extern (C) attributes So the considering the technicalities, it's completely possible. With regards

How can I pass a Scala object reference around in Java?

泄露秘密 提交于 2019-11-27 07:40:14
问题 I want to return from a Java method a reference to a Scala object. How can I do that? My Scala objects are like this: trait Environment object LocalEnvironment extends Environment {...} object ServerEnvironment extends Environment {...} ... and I want my Java method to be like this: Environment getEnvironment() { return LocalEnvironment; } // DOES NOT COMPILE Is there a way to do this? 回答1: { return LocalEnvironment$.MODULE$; } should work. Edit: the reason why this works is that this is how