interop

UnmanagedFunctionPointer causes stackoverflow when using .NET 4.0, 3.5 works

家住魔仙堡 提交于 2019-12-11 03:26:06
问题 I have a simple function inside of a click handler that has a try catch block. If I throw an exception within this try catch block it catches the exception successfully. If I put a call to an unmanaged DLL before I throw the exception the exception is unhandled and not caught. What is the unamanged DLL call doing that could be breaking my programs exception handling? If I run the program in debug mode it catches the exception even with "break on exception" unticked for all exceptions. The

Convert LPWSTR * array of string pointers to C#

南笙酒味 提交于 2019-12-11 03:05:43
问题 I'm trying to convert the following method from C++ to C# HRESULT GetDevices( [in, out] LPWSTR *pPnPDeviceIDs, [in, out] DWORD *pcPnPDeviceIDs ); In the MSDN documents it says: pPnPDeviceIDs [in, out] A caller-allocated array of string pointers that holds the Plug and Play names of all of the connected devices. To learn the required size for this parameter, first call this method with this parameter set to NULL and pcPnPDeviceIDs set to zero, and then allocate a buffer according to the value

Why is TypedReference.MakeTypedReference so constrained?

情到浓时终转凉″ 提交于 2019-12-11 03:01:53
问题 I've finally understood the usage of the TypedReference.MakeTypedReference method, but why are the arguments so limited? The underlying private InternalMakeTypedReference(void* result, object target, IntPtr[] flds, RuntimeType lastFieldType) can do a lot more things than the MakeTypedReference that limits the field array to have elements and the field types to be non-primitive. I've made a sample usage code that shows the full possibility of it: private static readonly MethodInfo

Excel protect workbook with password but allow readonly

▼魔方 西西 提交于 2019-12-11 02:56:06
问题 Using the interop classes in C# I was able to protect a workbook for reading and writing with a password. But I want users to be able to open the sheet as read-only. Is this possible without using the Workbook.SaveAs method? Protecting a workbook with a password (picture 1) I'm using the Workbook.Password property. 回答1: According to MSDN, the only way to change the Workbook.ReadOnlyRecommended property is with the Workbook.SaveAs method. In needed precisely what you're looking for a while ago

Calling Mono Assemblies from Java

守給你的承諾、 提交于 2019-12-11 02:53:25
问题 I have a large text proofing framework written in C# and I want to write a OpenOffice extension that uses this set of libraries. My prefered language for doing so is Java. Hence, I need a method to access .NET assemblies from Java (both in Windows and Linux ). Is there a way to call Mono assemblies from Java? 回答1: IKVM should allow you to do what you want but I must admit that I haven't done this myslef. Here's a link to their project: http://www.ikvm.net/ And a simple java program that calls

C++/C# Float issues

夙愿已清 提交于 2019-12-11 02:51:58
问题 I have a problem when trying to read a struct from C++ in C#. I did this more times and it worked always, but i never used floating point numbers. These are the structs i use on the C# side: [StructLayout(LayoutKind.Sequential)] public struct ImageData { public UInt32 Width; public UInt32 Height; public UInt32 Length; public IntPtr PixelPointer; } [StructLayout(LayoutKind.Sequential)] public struct UserData { public UInt32 misc; public Boolean IsValid; public VirtualPosition RightHand; public

InvalidCOMObjectException: COM object that has been separated from its underlying RCW cannot be used?

纵然是瞬间 提交于 2019-12-11 02:45:57
问题 I'm getting this exception thrown when I run my tests: Test method OuvertureClasseur threw exception: System.Runtime.InteropServices.InvalidComObjectException: COM object that has been separated from its underlying RCW cannot be used... though each of my test passes when ran individually. Here's my tests code: <TestClass()> _ Public Class FabriqueExcelTests Private Shared _xl As ApplicationClass <ClassInitialize()> _ Public Shared Sub MyClassInitialize(ByVal testContext As TestContext) _xl =

Pass structure (or class) from C++ dll to C# (Unity 3D)

风格不统一 提交于 2019-12-11 02:45:00
问题 I am writing a wrapper to get some data from a sensor. While I have no problems with passing int, float and arrays of them, I have difficulties to grasp how to pass a structure. Code summary C++ side The structure is as follows: struct HandInfo { int id; float x, y, z; }; At some point one static, globally visible HandInfo leftHand is filled with values which are retrievable through the following wrapper function: extern EXPORT_API HandInfo MyWrapper_getLeftHand() { return handtracker

How to build a 64-bit .NET DLL, with 64-bit COM interop?

一笑奈何 提交于 2019-12-11 02:44:22
问题 I need to build a managed DLL, targeted for x64, and expose it via x64 COM. I need a walk through, good article, etc... Interop is fairly straightforward, but when you talk about x64 on both sides, I can't find anything. 回答1: Take a look at this discussion. And this. 来源: https://stackoverflow.com/questions/95628/how-to-build-a-64-bit-net-dll-with-64-bit-com-interop

does GetComInterfaceForObject pin the object?

本秂侑毒 提交于 2019-12-11 02:29:10
问题 Will using GetComInterfaceForObject and passing the returned IntPtr to unmanaged code keep the managed object from being moved in memory? Or does the clr somehow maintain that ptr? Note that the unmanaged code will use this for the lifetime of the program, and I need to make sure the managed object is not being moved by the GC.(At least I think that's right?) EDIT - Alright I found some info and I am thinking that this may be the answer. It deals with delegates, but I would have to believe