interop

What Should I MarshalAs for Character Type in Fortran?

风格不统一 提交于 2019-12-06 14:49:40
I am calling a fortran subroutine from C#. One of the parameter I have to pass in is character .i.e, in fortran that parameter is declared as character, intent(in) :: bmat*1 The issue now is, in C# code, what should I marshaled it as? I know that for integer , I should marshal it as [MarshalAs(UnmanagedType.I4)] , but what about character ? Edit: This is my fortran code: subroutine chartest(bmat) !DEC$ ATTRIBUTES DLLEXPORT::chartest !DEC$ ATTRIBUTES ALIAS:'chartest'::chartest !DEC$ ATTRIBUTES VALUE ::bmat character, intent(in) :: bmat*1 if(bmat .eq. 'G')then print *, bmat else print *, ' no

How to cast a control to IOleObject

被刻印的时光 ゝ 提交于 2019-12-06 14:15:51
I want to invoke GetClientSite on a .net control. For this purpose I am trying to cast a control (in example Windows.Forms.Form) to IOleObject which returns null. What should I do to get IOleObject? using System; using System.Runtime.InteropServices; using System.Security; using System.Windows.Forms; namespace Test001 { public class Form001 : Form { public Form001() { InitializeComponent(); } private void InitializeComponent() { this.SuspendLayout(); this.Name = "Form001"; this.Text = "Form001"; this.Load += new System.EventHandler(this.Form001_Load); this.ResumeLayout(false); } private void

Retrieving table data from a doc file using c#

末鹿安然 提交于 2019-12-06 14:06:00
I am working on a project which involves getting data from a .doc or a .docx file. The input requirements are in a tabular format. Is it possible to retrieve data from table in a row wise manner or as a dataset.I am using Microsoft.Office.Interop.Word to get the data from the doc file. You can use the property Tables of the Document interface to get a collection with all the tables in your document. For each Table in this collection you can get the rows and for each row the cells. I.e. if app is your Application object you can write something like this to get the text contained in each cell

How to Pass an Array from C# (VSTO) project to VBA Macro

亡梦爱人 提交于 2019-12-06 13:52:52
I'm having performance issues with my VSTO solution, I believe the reason is mainly the way the cellColor is set cell by cell. This depends on data from a recordSet and is thus different everytime. (I can't use a copyFormats from another row/column) it's similar to filling a Range of values, only for that one there are several methods. I thought about creating the whole thing in C# in Memory first (a XlColorIndex[,] array) which I pass through to a VBA method similar to the one below: Sub fillInterior(ByRef rg As Range, a As Variant) //a is a double array that represents the colors for the

Need to Find the COM DLL from an interop dll

南楼画角 提交于 2019-12-06 13:49:31
I have a Interop dll in a c# project, But I am not able to findout the corresponding COM dll associated with it. Please let me know, how to find out the actual COM dll from its interop dll. Got it. One way is to use any one of its class in the project. Then go to definition of it, which will take us to Metadata. we can note down the GUID and then search it in registry, if that is available, like this one. namespace NETWORKLIST { [ClassInterface(0)] [Guid("DCB00C01-570F-4A9B-8D69-199FDBA5723B")] [ComSourceInterfaces("NETWORKLIST.INetworkEvents")] 来源: https://stackoverflow.com/questions/20301820

Accessing .NET Collection in VB6

落爺英雄遲暮 提交于 2019-12-06 13:44:56
问题 I have a .NET assembly that has routines that need to be called from a VB6 dll. The .NET assembly's routines, for other .NET code will return Lists of objects. However that won't work for VB6. So I am using Interop to create a "vb6 class" that will return the data needed. I had read that the VB.NET Collection is compatible with the VB6 Collection, but I've found that to be untrue. My simple test consists of: .NET Code: <ClassInterface(ClassInterfaceType.AutoDual)> _ Public Class MyCOMClass

Why aren't my fortran functions exported when using the BIND(C, NAME=“name”) attribute

走远了吗. 提交于 2019-12-06 12:46:11
I am used to using the following syntax subroutine CalcA(A,N) !DEC$ ATTRIBUTES DLLEXPORT :: CALCA !DEC$ ATTRIBUTES ALIAS:'CalcA' :: CalcA IMPLICIT NONE ... end subroutine CalcA which produces an exported function in a .dll So now I am trying the new ISO_C_BINDING with the following code subroutine CalcA(A,N) BIND(C, NAME="CalcA") USE, INTRINSIC :: ISO_C_BINDING IMPLICIT NONE ... end subroutine CalcA But the export function is not created So what am I missing here? How is the new iso_c_binding going to replace the deprecated !DEC$ ATTRIBUTE DLLEXPORT declarations? PS. I am on Intel Fortran XE

Connecting c++ and c# code with a c++/cli bridge

北城以北 提交于 2019-12-06 12:31:15
问题 I have a client application in native c++ code which is using native c++ dlls. I am investigating the possibility of connecting this code with c# dlls as they would be much easier to write. I decided to write a c++/cli bridge dll which can be loaded with LoadLibrary and which would pass the calls to c# dll. The communication between the client and the dll is such that the client passes a pointer to an interface object through which the dll then communicates with the client. I wrapped this

Marshalling C# structure to C++ Using StructureToPtr

浪子不回头ぞ 提交于 2019-12-06 12:18:24
I have C# class: namespace Models { [StructLayout(LayoutKind.Explicit, Size = 120, CharSet = CharSet.Unicode)] public struct DynamicState { [FieldOffset(0)] public double[] Position; [FieldOffset(24)] public double[] Velocity; [FieldOffset(48)] public double[] Acceleration; [FieldOffset(72)] public double[] Attitude; [FieldOffset(96)] public double[] AngularVelocity; } } and C++/CLI method: Models::DynamicState SomeClassClr::DoSomething(Models::DynamicState ds) { int struct_size = Marshal::SizeOf(ds); System::IntPtr ptr = Marshal::AllocHGlobal(struct_size); DynamicStateStruct ds_struct; struct

Workaround to see if Excel is in cell-edit mode in .NET

邮差的信 提交于 2019-12-06 11:56:35
I have an application written in VB.NET that interacts with Excel via interop. I eventually ran into the known issue of Cell-edit mode (see MSDN and stackoverflow for some background). I have been trying to convert the suggested code to VB.NET but keep getting the following error: Reference required to assembly 'office, Version=11.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c' containing the type 'Microsoft.Office.Core.CommandBars'. Add one to your project. (BC30652) - E:\ ... .vb:3471 The original C# code (from previosuly mentioned articles) is as follows private bool IsEditMode() {