interop

What Should I MarshalAs for Character Type in Fortran?

蹲街弑〆低调 提交于 2019-12-23 02:36:12
问题 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

How do I define the TBBUTTON struct in C#?

会有一股神秘感。 提交于 2019-12-23 01:44:16
问题 Greetings all, The TBBUTTON struct is defined on MSDN as follows: typedef struct { int iBitmap; int idCommand; BYTE fsState; BYTE fsStyle; #ifdef _WIN64 BYTE bReserved[6]; #else #if defined(_WIN32) BYTE bReserved[2]; #endif #endif DWORD_PTR dwData; INT_PTR iString; } TBBUTTON, *PTBBUTTON, *LPTBBUTTON; I need to do some interop in C# using this struct. How do I replicate this monster so that it's defined correctly when compiled for AnyCPU? Google is apparently full of dangerous misinformation!

Problem in calling a C++ dll function from C#

只愿长相守 提交于 2019-12-23 01:40:43
问题 This is my 3rd thread concerning a blowfish problem in C#.Despite the fact I cannot have blowfish implemented in my application, I decided to use it as an external C++ dll. Please note I've tried Blowfish.NET and any other, the problem is that I'm translating code from C++ to C# and the C# code must do exactly the same as the C++ code does. So far: --->C++ DLL source<--- Note the exported functions are in the end of the code C# code(definition) [DllImport("TestDLL.dll", EntryPoint = "Initkey"

Returning strings from Windows C functions

好久不见. 提交于 2019-12-23 01:36:08
问题 I am a complete novice at pure Windows API-level functions in C and C++ and have been experimenting recently with .NET interoperability. I have built a simple library which has successfully returned numeric values (int/float, etc.) to a .NET caller, but I am not having as much luck with strings. I have tried a variety of different data types, but none appear to work: LPSTR, LPCSTR, LPCTSTR, and LPCWSTR. Admittedly, I haven't tried char*. Also, once a method is set up to return a string, does

Mail Merge (Excel to Word) using C#

无人久伴 提交于 2019-12-23 01:18:06
问题 I was wondering if anybody knew how to do a mail merge using an Excel file as a datasource, to fill in fields on a Word template? I wish to use the interop for Word if i could...but am having a few difficulties finding code for this. Does anybody have any syntax for this? Thank you in advance. 回答1: A very useful method for learning how to automate specific actions in MS Word is to actually perform the action manually with 'Record Macro' enabled. Once you have the VBA macro its easy enough to

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

泪湿孤枕 提交于 2019-12-22 22:52:31
问题 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

Weird scrollbar UI in hosted WPF composite control

坚强是说给别人听的谎言 提交于 2019-12-22 20:33:12
问题 My windows forms application hosts AvalonEdit (the composite WPF control in question) in one of its forms to cater to its text editing requirements. Here's the code I use: WPFHost = gcnew ElementHost(); TextField = gcnew AvalonEdit::TextEditor(); WPFHost->Dock = DockStyle::Fill; WPFHost->Child = TextField; TextField->Options->AllowScrollBelowDocument = false; TextField->Options->EnableEmailHyperlinks = false; TextField->Options->EnableHyperlinks = true; TextField->Options-

How to cast a control to IOleObject

一个人想着一个人 提交于 2019-12-22 17:36:14
问题 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 =

Reentrancy was detected

左心房为你撑大大i 提交于 2019-12-22 14:41:03
问题 I'm getting "Reentrancy was detected" MDA error while setting a webbrowser control's properties. This only happens if I call "SetWindowsHookEx" to hook some dials within the same thread. Normally this hooking code works fine but it doesn't play nice with Webbrowser Control. When I ignore the exception code works fine, at least look like fine but obviously I'm a bit worried. Is there any idea why exactly this error is happening and how to resolve the problem. I've seen this article in MSDN -

EnumResourceNames issue - unknown error

喜夏-厌秋 提交于 2019-12-22 13:57:35
问题 I was recently working with resources from secondary libraries/binary modules and encountered a strange error. I have two native WinAPI references: [DllImport("kernel32.dll", SetLastError = true)] public extern static bool EnumResourceNames(IntPtr hModule, int lpszType, EnumResNameProc lpEnumFunc, IntPtr lParam); [DllImport("kernel32.dll", SetLastError=true)] public extern static IntPtr LoadLibraryEx(string lpFileName, IntPtr hFile, int dwFlags); When I call LoadLibraryEx, I am getting the