interop

Calling FORTRAN dll from C# and assigning values to array of structures

眉间皱痕 提交于 2019-11-28 10:28:25
I can pass a C# struct into FORTRAN just fine. I can even pass an array of a C# struct as an array of TYPE() in FORTRAN . Where I run into trouble is when I tried to return values back into C# . Here is an example: The fortran dll is: MODULE TESTING TYPE VALUEREF INTEGER*4 :: A ENDTYPE VALUEREF CONTAINS SUBROUTINE TEST_REF(T,N) !DEC$ ATTRIBUTES DLLEXPORT :: TEST_REF !DEC$ ATTRIBUTES ALIAS:'TEST_REF' :: TEST_REF !DEC$ ATTRIBUTES VALUE :: N IMPLICIT NONE INTEGER*4 :: A,I,N TYPE(VALUEREF) :: T(N) A = 100 DO I=1,N T(I)%A = A + I END DO END SUBROUTINE END MODULE and the C# calling function that

Get pages of word document

孤者浪人 提交于 2019-11-28 10:26:37
I'm trying to get all pages of MSWord document via Microsoft.Office.Interop.Word (I'm using C# in VS2012). What I would like to get is List< String > Pages, where index is the number of page. I understand (at least I think so) that there is no direct way to do that. So I came up with something like that: List<String> Pages = new List<String>(); int NumberOfPreviousPage = -1; int NumberOfPage = -1; string InnerText = ""; for (int i = 0; i < Doc.Paragraphs.Count; i++) { Paragraph CurrentParagraph = Doc.Paragraphs[i + 1]; InnerText = CurrentParagraph.Range.Text; NumberOfPage = CurrentParagraph

IntPtr to Byte Array and Back

偶尔善良 提交于 2019-11-28 10:22:17
Referencing How to get IntPtr from byte[] in C# I am attempting to read the data that an IntPtr is referencing into a byte [] and then back into another IntPtr. The pointer is referencing an image captured from a scanner device so I have also made the assumption that capturing this information should be placed into a byte array. I am also not sure if the Marshal.SizeOf() method will return the size of the data the IntPtr is referencing or the size of the pointer itself. My issue is I am receiving the error "Type 'System.Byte[]' cannot be marshaled as an unmanaged structure; no meaningful size

How do I marshal wchar_t* from C++ to C# as an out parameter or return value?

一笑奈何 提交于 2019-11-28 10:14:00
I have tried to do this in many ways, but none is working. Does anyone have a correct example for this? I just want to move the wchar_t* value from a function to the C# level. This isn't as difficult as you think it is... What is wchar_t* ? What value does that type typically represent? A string. It's the equivalent to the LPWSTR type defined in windows.h . So, you marshal it as a string type. However, since it's an out parameter (or a return value), you'll need to use the StringBuilder class on the C# end, rather than the string type. The P/Invoke syntax would look something like this:

Setting up a DLL for registration-free COM Interop with C# / Managed code

落花浮王杯 提交于 2019-11-28 10:04:02
问题 I am new to COM and have to create a COM wrapper for a C++ dll, to make some functionality in it accessible for managed code. I mainly followed this tutorial on code project to create a COM ATL dll. I created a post-build-step that calls tlbimp.exe on the COM dll to create the wrapping. Adding a reference to the dll that tlbimp.exe creates works, and I get code completion for methods on my COM dll, and can compile managed code that uses that dll. However, running that code leads to the

C# Excel automation causes Excel memory leak

喜欢而已 提交于 2019-11-28 09:57:52
I'm trying to use C# with the COM Interop library to open a set of very heavy excel workbooks. I have to use C#, because I also need to start macros, move some cells around, and start a custom excel-add-in my company uses. My program then exits, leaving the workbooks open, each in a separate excel instance. I DO NOT want the workbooks to be closed when the program exits. The problem is that when my C# program exits, over time, the excel workbooks gradually consume more memory, until they're consuming 3.5 gigs of memory from an original 500 mb. I used to open the workbooks by hand, and the

Interop between F# and C# lambdas

梦想与她 提交于 2019-11-28 09:40:23
F# powerpack comes with a set of conversion methods to translate from Func<...> to F# functions, either standard or tupled ones. But is it possible to achieve the opposite: in case you want to call from F# code a C# method that takes Func<...> and want to use native F# lambda expression (e.g. fun x -> some_function_of(x))? If I send a F# function with a signature 'a -> 'b to a C# method that expects Func then F# compiler generates the following error: This expression was expected to have type Function<'T,'R> but here has type 'T -> 'R I want to stay with F# lambda expressions but to use a

Access C variable in swift

时间秒杀一切 提交于 2019-11-28 09:37:10
问题 I'm trying to access a state variable declare in .h file but the compiler said the variable doesn't exist. Do I need to add anything in my bridging header file ? In my swift file I can't access dstate or cstate The compiler says "Use of unresolved identifier 'dstate'" on the line g722_coder_init(&dstate) . Header file #ifdef __cplusplus extern "C" { #endif extern struct g722_dstate dstate; extern struct g722_cstate cstate; int g722_coder_init ( struct g722_cstate *s ); int g722_encode(short

How do I read the values of Excel dropdowns or checkboxes from c# or vb.net?

会有一股神秘感。 提交于 2019-11-28 08:51:29
问题 I'm using Microsoft.Office.Interop.Excel to read the values of cells of a worksheet, but I'm unable to find information that shows how to read dropdowns, checkboxes and option buttons. Thanks! 回答1: Apparently accessing the DropDowns collection directly is verboten. A workaround is to access the Validation property of the cell containing the dropdown, get it's formula and then parse out the location of the list. Excel.Range dropDownCell = (Excel.Range)ws.get_Range("A1", "A1"); //cell

Could not load type Microsoft.Office.Interop.Excel._Application

删除回忆录丶 提交于 2019-11-28 08:48:53
问题 I'm getting a error when I try to debug a code that reads Excel files. I'm wondering if the reference to 'Microsoft.Office.Interop.Excel._Application' is wrong, I get the following error. isn't the Microsoft.Office.Interop.Excel version suppose to be 12? and not loaded from my project assembly? Could not load type 'Microsoft.Office.Interop.Excel._Application' from assembly 'Dialog, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. The type is marked as eligible for type equivalence, but