interop

how to call a C function from C# with a WCHAR* out parameter?

我的未来我决定 提交于 2020-01-13 02:23:08
问题 I'm having a bit of problem with marshaling and I just can't figure it out by myself. I've searched for this topic, but hadn't have any luck yet, so basically I'm trying to call an unmanaged C function from my managed C# application. The signature of the C function looks like this: long MyFunction(WCHAR* upn, long upnSize, WCHAR* guid, long* guidSize); I don't access to the .dll file, I just know that the function is being exposed for usage and I know what the function is supposed to do, but

How I can declare arrays in struct?

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-12 18:46:42
问题 How can I declare structure with a fixed size array in it? I found solution, but it only works for primitive data-types. I need my array to be of type MyStruct . So how can I declare a struct with an array of other structs in it? ex. unsafe struct Struct1{ fixed int arrayInt[100]; // works properly fixed Struct2 arrayStruct[100]; //not compile } 回答1: My colleague found the working way to do this. I think it`s right way. [StructLayout(LayoutKind.Sequential)] public struct Struct1 { [MarshalAs

Size of structures in .NET

谁说我不能喝 提交于 2020-01-12 07:16:28
问题 My problem is to send a structure between a program in C to a C# program. I made a structure in C#: public struct NetPoint { public float lat; // 4 bytes public float lon; // 4 bytes public int alt; // 4 bytes public long time; // 8 bytes } The total size of the structure must be 20 bytes. When I do a sizeof() in C++ of this structure, System.Diagnostics.Debug.WriteLine( "SizeOf(NetPoint) = " + System.Runtime.InteropServices.Marshal.SizeOf(new NetPoint())); the debug console shows: SizeOf

Passing Data from a Java program to a Python program and getting results back

左心房为你撑大大i 提交于 2020-01-12 05:29:36
问题 What is the preferred way of passing data (a list of string) from a Java program to a Python script. The python script performs some processing on the data and then I need to get the results back in my Java program. Is there is a framework that allows you to do this easily? EDIT: More specific requirements. My Java program is a scheduler (runs every X minutes and Y seconds ) that connects to an external service and gets the RAW data and send it to python. I can rewrite everything in Python

C# interop: excel process not exiting after adding new worksheet to existing file [duplicate]

江枫思渺然 提交于 2020-01-12 05:11:20
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: How to properly clean up Excel interop objects in C# I've read many of the other threads here about managing COM references while using the .Net-Excel interop to make sure the Excel process exits correctly upon exit, and so far the techniques have been working very well, but I recently came across a problem when adding new worksheets to an existing workbook file. The code below leaves a zombie Excel process. If

Using a .net compiled dll inside native c++

北战南征 提交于 2020-01-11 04:15:07
问题 as i understand that any .NET program gets compiled to MSIL which is fed to the CLR which compiles it to the assembly code and along with the help of JIT it executes it. I was wondering, as .NET is a wrapper around the win32 api and the CLR ultimately converts the MSIL to assembly program. Isn't it possible for me to write some functionality in C#, make to a dll and then i use a tool which makes it a complete .net independent file for me to use inside unmanaged code like in C or C++. Am i

How to use C# BackgroundWorker to report progress in native C++ code?

风流意气都作罢 提交于 2020-01-10 04:47:08
问题 In my Visual Studio solution I have UI implemented in C# and some code implemented in native C++. I use BackgroundWorker class to implemenent reporting progress of execution long operation. How can I use BackgroundWorker to report progress from my native C++ code? In other words, how can I rewrite the C# code below to native C++ and call obtained C++ code from C#? If it is not possible to rewrite the code below directly, it could be good to know about other equivalent solutions. Thanks. class

Why does this Using() give me an error?

与世无争的帅哥 提交于 2020-01-10 03:50:06
问题 I am trying to open an (hundreds actually) excel file(s). I open the application but want to use the Using() functionality around each of the workbooks I open. Why is this resulting in an error? using (Excel.Workbook wbXL = appXL.Workbooks.Open(_sourceFullPath, Type.Missing, Excel.XlFileAccess.xlReadOnly)) { //stuff with wbXL } using gets the red underline and says "'Microsoft.Office.Interop.excel.Workbook':Type used in a using statement must be implicitly convertible to 'System.IDisposable'.

Can not add reference a COM in COM client?

谁都会走 提交于 2020-01-10 02:34:30
问题 A COM server is create and I registerd that. When I am trying to add that COM server in a COM Client, I was not able to add, and following error is comming. " A reference to 'COMTest' could not be added The ActiveX type Library 'c\user\~\Debug\COMTest.tlb' was exported from a .NET assembly and can not added as a reference. Add a reference to .NET instead " can anybody tell me What is the mistake. I register the COM in both way, from VS also and also tried with command prompt. 回答1: This is a

How to speed up dumping a DataTable into an Excel worksheet?

孤者浪人 提交于 2020-01-09 19:23:26
问题 I have the following routine that dumps a DataTable into an Excel worksheet. private void RenderDataTableOnXlSheet(DataTable dt, Excel.Worksheet xlWk, string [] columnNames, string [] fieldNames) { // render the column names (e.g. headers) for (int i = 0; i < columnNames.Length; i++) xlWk.Cells[1, i + 1] = columnNames[i]; // render the data for (int i = 0; i < fieldNames.Length; i++) { for (int j = 0; j < dt.Rows.Count; j++) { xlWk.Cells[j + 2, i + 1] = dt.Rows[j][fieldNames[i]].ToString(); }