interop

Calling C++ function from C#

女生的网名这么多〃 提交于 2019-12-10 16:34:37
问题 I have a the following C++ function void FillAndReturnString(char ** someString) { char sourceString[] = "test"; *someString = new char[5]; memcpy(*someString, sourceString, 5); } It is declared as extern "C" { __declspec(dllexport) void __cdecl FillAndReturnString(char ** someString); } How do I call this function from C#? Thanks 回答1: With P/Invoke. 回答2: You need to know that you're allocating unmanaged memory block in your c++ function, so it will not be possible to pass a managed String or

calling .net 4 from .net 3.5 via self hosted wcf service

假装没事ソ 提交于 2019-12-10 16:33:57
问题 I have a .net 3.5 application. It cannot be migrated to 4. I need to call a .net 4 assembly from my application. I thought to create a new executable in .net 4 which has a self hosted wcf service that is an adapter over the 4 assembly. My 3.5 app can then execute the external process and call the assembly. This is a little ugly - any better idea? 回答1: Google says it is possible. It seems there is a new feature in .Net 4 called Inproc Sxs (In process side by side). Have a look here : http:/

C# Excel interop - how to test if interop object is still working and performing a task?

风流意气都作罢 提交于 2019-12-10 16:14:14
问题 I am looping through a directory of several hundered excel files and trying to refresh the excel files one at a time. I keep getting this error which indicates that the refresh operation is still running on File A, for example, and FileB is trying to start a refresh operation. The loop is to fast and somehow I have to wait for the prior refresh operation on File A to complete before starting to refresh File B. Unhandled Exception: System.Runtime.InteropServices.COMException: The message

Passing an object from C++ to C# though COM

末鹿安然 提交于 2019-12-10 16:04:22
问题 hi have a COM visible API in C# which looks like the following: public void DoSomething(string par1, string par2, object additionalParameter) The idea is that based on the value of the string parameters I expect a different class as the third parameter and cast it appropriately in the implementation (I know this design is not optimal but I don't have much flexibility here). Suppose that for some combination of the string parameters the type of the additional parameter is the following:

Creating a Mixed Mode C++ Bridge from C to C#?

℡╲_俬逩灬. 提交于 2019-12-10 15:56:56
问题 I hope someone can help me with this, I'm mostly a C# developer so my C and C++ skills are bad. I have a native C dll that is a plugin of a larger application. I cross compile this dll for windows on linux using gcc. In the native dll when I create a D3DSurface I want to call a function in a Mixed Mode C++ dll and pass in the pointer to the surface along with a Hwnd/handle. That Mixed Mode C++ should then call my C# managed code. As an example, in C I want to do the following; Hwnd handle;

Can't instantiate COM component in C# - error 80070002

自古美人都是妖i 提交于 2019-12-10 15:30:33
问题 I'm attempting to instantiate a Windows Media Player COM object on my machine: Guid mediaPlayerClassId = new Guid("47ac3c2f-7033-4d47-ae81-9c94e566c4cc"); Type mediaPlayerType = Type.GetTypeFromCLSID(mediaPlayerClassId); Activator.CreateInstance(mediaPlayerType); // <-- this line throws When executing that last line, I get the following error: System.IO.FileNotFoundException was caught Message="Retrieving the COM class factory for component with CLSID {47AC3C2F-7033-4D47-AE81-9C94E566C4CC}

Accessing a namespace containing .base in its name from F#

梦想的初衷 提交于 2019-12-10 15:29:28
问题 As the title says, I'm trying to use a class declared in a namespace which contains "base" in its name. Think of a situation like the following: open Foo.base.Bar In C# I'd just use @ before base but F# seems to ignore that and to think that @ is the infix operator used for list concatenation. Since the namespace belongs to a third-party library which I cannot modify, is there a way I can still access it from F#? 回答1: In F#, you can achieve similar thing by enclosing the special name between

How to find column id by cell value?

∥☆過路亽.° 提交于 2019-12-10 14:54:35
问题 I have a huge excel file and would like to find column "ID" for later use. Row 1 is empty, header rows is in the second. int ID_Number = ((Range)sheet.get_Range("A2", sheet.UsedRange.Columns.Count).Find("ID Number", Missing.Value, XlFindLookIn.xlValues, XlLookAt.xlPart, XlSearchOrder.xlByColumns, XlSearchDirection.xlNext, true, Missing.Value, Missing.Value) ).Column; int Size = ((Range)sheet.get_Range("A2", sheet.UsedRange.Columns.Count).Find("Size", Missing.Value, XlFindLookIn.xlValues,

A continued saga of C# interoprability with unmanaged C++

喜你入骨 提交于 2019-12-10 14:52:54
问题 After a day of banging my head against the wall both literally and metaphorically, I plead for help: I have an unmanaged C++ project, which is compiled as a DLL. Let's call it CPP Project . It currently works in an unmanaged environment. In addition, I have created a WPF project, that shall be called WPF Project . This project is a simple and currently almost empty project. It contains a single window and I want it to use code from Project 1. For that, I have created a CLR C++ project, which