interop

Arrays of strings in Fortran-C bridges using iso_c_binding

只谈情不闲聊 提交于 2019-11-29 13:33:39
I'm writing code that will call a C function from Fortran using Fortran's C interoperability mechanism (introduced in Fortran 2003 and implemented in newer versions of gfortran and ifort). This answer is almost what I need, but I can't quite get my head around what interface declaration I should use in Fortran for a C function that looks like this: int use_array(int n, char * array[]){ int i; for(i=0; i<n; i++){ printf("Item %d = %s\n",i,array[i]); } return n; } I'm not clear what the declaration should be for the interface on the Fortran end: interface function use_array(n, x) bind(C) use iso

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

倖福魔咒の 提交于 2019-11-29 13:05:59
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 MyClass { public void Calculate(object sender, DoWorkEventArgs e) { BackgroundWorker worker = sender

How to call win32 CreateMutex from .Net

久未见 提交于 2019-11-29 12:57:36
I've been successfully creating a .net mutex like this: SingleIns = new Mutex(true, AppName); for a while. It works in XP, Vista, but apparently not in Windows7. So I need to make an interop call to a Win32 library so other Com components can identify the mutex. I found the following code, but the Win32Calls. is not found... is there an assembly or reference I need? Thanks in advance, Found code from: http://www.pinvoke.net/default.aspx/kernel32/CreateMutex.html using System.Runtime.InteropServices; [DllImport("kernel32.dll")] public static extern IntPtr CreateMutex(IntPtr lpMutexAttributes,

C++ and C# interoperability : P/Invoke vs C++/CLI

◇◆丶佛笑我妖孽 提交于 2019-11-29 12:19:38
问题 In the course of finding a way to interoperate between C# and C++ I found this article that explains about P/Invoke. And I read a lot of articles claiming that C++/CLI is not exact C++ and requires some effort to modify from original C++ code. I want to ask what would be the optimal way when I have some C++ objects (code/data) that I want to use from C# objects. It looks like that in order to use P/Invoke, I should provide C style API. Is it true? I mean, is there a way to export C++ object

How to know if native method is safe / unsafe?

岁酱吖の 提交于 2019-11-29 12:19:12
问题 I implement this function : GetSystemPowerStatusEx & GetSystemPowerStatusEx2 according to this article on MSDN, I should create a class named according to the functions I will use, but my question is : How can I know in which class I should put GetSystemPowerStatusEx & GetSystemPowerStatusEx2 ? I'm lost... Thanks for help. [EDIT] My question is : which of these three class names are the good one for me (NativeMethods / SafeNativeMethods / UnsafeNativeMethods) ? These methods should be in one

File not found when loading dll from vb6

老子叫甜甜 提交于 2019-11-29 11:15:50
I am declaring and calling a dll function using the following syntax in VB6: 'Declare the function Private Declare Sub MYFUNC Lib "mylib.dll" () 'Call the function MYFUNC Calling the function results in the error File not found: mylib.dll . This happens when the application is run from the vb6 IDE or from a compiled executable. The dll is in the working directory, and I have checked that it is found using ProcMon.exe from sysinternals. There are no failed loads, but the Intel Fortran dlls are not loaded (the ProcMon trace seems to stop before then). I have also tried running the application in

Install MathLink program with arbitrary PATH environment

时间秒杀一切 提交于 2019-11-29 10:56:09
Is it possible to use Install[] to start a MathLink program with a custom PATH environment variable? I am trying to use mEngine to connect Mathematica to MATLAB on Windows. It only works if mEngine.exe is launched when the PATH environment variable includes the path to the MATLAB libraries. Is it possible to modify the PATH for launching this program only , without needing to modify the system path? Or is there another way to launch mEngine.exe ? @acl's solution to wrap mEngine.exe in a batch file, and temporarily modify the PATH from there, works correctly: I used this as the contents of

Understanding the Running Object Table

丶灬走出姿态 提交于 2019-11-29 10:45:27
I'm attempting to use the running object table to get a DTE a specific instance of Visual Studio. I was intending to use the technique described on MSDN . I've managed to get one of the instances to list, but not the others. public static void PrintRot() { IRunningObjectTable rot; IEnumMoniker enumMoniker; int retVal = GetRunningObjectTable(0, out rot); if (retVal == 0) { rot.EnumRunning(out enumMoniker); IntPtr fetched = IntPtr.Zero; IMoniker[] moniker = new IMoniker[1]; while (enumMoniker.Next(1, moniker, fetched) == 0) { IBindCtx bindCtx; CreateBindCtx(0, out bindCtx); string displayName;

Activator.CreateInstance(<guid>) works inside VSIDE but not externally

…衆ロ難τιáo~ 提交于 2019-11-29 10:38:23
I have a bunch of COM objects which all implement the same interface, and need to create one of them as chosen at runtime from a list of options. Since I know the CLSID for each of the implementing COM servers, this should be easy. However, for a certain subset of COM libraries, I can only make this work if I'm running inside of the VS2010 IDE. Here is the entire program I'm using to test with: using System; namespace ComTest { class Program { static void Main(string[] args) { var clsid = "{E8978DA6-047F-4E3D-9C78-CDBE46041603}"; var type = Type.GetTypeFromCLSID(new Guid(clsid)); var obj =

Why does this Using() give me an error?

China☆狼群 提交于 2019-11-29 10:16:56
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'. How to make this work? Pretty much what it says - you can only use using with classes that implement