interop

Calling C++ dll from .Net Code is Excruciatingly Slow when a Debugger is Attached

时光毁灭记忆、已成空白 提交于 2019-12-10 22:58:02
问题 I am using VS 2008 to compile and debug my code. In my application, the front end is C#, the backend is C++. I access the C++ code via interop. One thing I notice is that if I press F5, and I link in the debug version of the native code, it would take more than 20 seconds to run the native code. If I link in the release version of the native code, the time needed to run it is cut down to 7-8 seconds. And if I don't have the VS 2008 debugger attached ( i.e., I click on the exe outside of the

When is the Window.SourceInitialized event raised

ぃ、小莉子 提交于 2019-12-10 22:54:40
问题 Can I guarantee the Window.SourceInitialized event will always be raised before the Window.Loaded event? I need the HwndSource object for further processing in my Window.Loaded event handler and I'm not sure if this will always be available by then 回答1: Here's the sequence of events you can expect (it should occur before Loaded): http://wpf.2000things.com/2012/07/30/613-window-event-sequence/ If you want to double-check, or don't trust getting the SourceInitialized event...then you can try

Does GCHandle.Alloc do anything beyond keeping a reference to an object?

混江龙づ霸主 提交于 2019-12-10 22:48:29
问题 GCHandle.Alloc "protects the object from garbage collection," but merely holding a reference to that object in a static variable will also prevent it from being collected. What benefit does GCHandle.Alloc provide (assuming GCHandleType.Normal )? This article says that delegates "need not be fixed at any specific memory location" but I can't find any documentation on MSDN to back that statement up. If the delegate is moved by the CLR garbage collector, how can the umanaged library find it so

Convert Microsoft.Office.Interop.Excel.Application to byte[]

一世执手 提交于 2019-12-10 22:03:59
问题 I am creating a excel file in the code as Shown Below Microsoft.Office.Interop.Excel.Application excelFile = CreateExcelFile(); now I want to convert this excelFile to byte[] without saving to hard drive. How is it possible? 回答1: had the same problem some time ago. You have to create a temporary file, and then read it to a byte array. Example code: string tempPath = AppDomain.CurrentDomain.BaseDirectory + DateTime.Now.Hour + DateTime.Now.Minute + DateTime.Now.Second + DateTime.Now.Millisecond

C array memory deallocation from swift

白昼怎懂夜的黑 提交于 2019-12-10 21:49:45
问题 var cpuInfo: processor_info_array_t = nil var numCpuInfo: mach_msg_type_number_t = 0 var coresTotalUsage: Float = 0.0 var numCPUsU: natural_t = 0 let err = host_processor_info(mach_host_self(), PROCESSOR_CPU_LOAD_INFO, &numCPUsU, &cpuInfo, &numCpuInfo); assert(err == KERN_SUCCESS, "Failed call to host_processor_info") Hi, I am calling the above C API host_processor_info to get process load informations from swift, no problem there. cpuInfo is a inout parameter (pointer) that, on return, will

.Net usercontrol in MS Access

核能气质少年 提交于 2019-12-10 21:22:57
问题 It is possible to create .Net UserControls that can be consumed on a VB6/MS Access form through COM, with the help of the Interrop toolkit, or as a simple ActiveX. This works pretty well except for one major pain: resizing . You cannot resize the control on the form during runtime. Anchoring the control to opposite sides of the form makes it grow every time you resize the form, even if you reduce the form... There doesn't seem to be any way to tame this behaviour: From .Net, any attempt at

Passing DataTable over COM into R

懵懂的女人 提交于 2019-12-10 20:47:20
问题 I am trying to pass data from SQL, to C#, then to an R server for data analysis then back to my web application; however, the COM interface that I am using does not allow complex data types to be passed between C# and R (no data tables). I have gotten it to work in the past by using the following code: int count = dataTable.Rows.Count; object[] y = new object[count]; object[] x = new object[count]; //R does not accept DataTables, so here we extract the data from //the table and pass it into 2

How to create an interface using .NET for C++ application?

我只是一个虾纸丫 提交于 2019-12-10 20:36:19
问题 I have written all the code for an application in C++. It is standard C++ written using Visual Studio 2010. I want to create a GUI using .NET. Is it possible? Thank you! 回答1: There a plenty of options, here's a few off the top of my head: Wrap the c++ code in a Windows DLL, call the c++ code from .NET using p/invoke. Wrap the c++ code in a com object, .NET can directly use com objects. Wrap the c++ code inside some type of managed c++ wrapper (c++/CLI), load and use that new assembly in the

UsedRange in excel column

情到浓时终转凉″ 提交于 2019-12-10 19:35:52
问题 How do you get a column from the UsedRange; for example column A? xlApp = new Excel.Application(); xlWorkBook = xlApp.Workbooks.Open("C:\\base.xls", 0, true, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0); xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1); //range = xlWorkSheet.UsedRange; range = xlWorkSheet.get_Range("A") // reading from A1 to max of excel 65536? 回答1: @Lance's answer: range = xlWorkSheet.UsedRange

Where does IDispatchEx exists?

≯℡__Kan透↙ 提交于 2019-12-10 19:21:33
问题 Can't find the library which contains IDispatchEx interface. I want to implement this interface, but can't find it. Does anyone knows where it is? Thanks, Paul. 回答1: If you want to write a managed class that implements the IDispatchEx interface you will first need to define this interface because it does not exist in .NET. Here's a link to its definition. IMHO implementing this interface won't be a trivial task. 回答2: What exactly do you want to do? Is this for use inside C#? Or from outside