interop

how to solve Exception:Call was rejected by callee. (Exception from HRESULT: 0x80010001 (RPC_E_CALL_REJECTED)) in C#?

ぐ巨炮叔叔 提交于 2019-11-28 13:20:02
I have written a C# code in console application to open two excels and copy and paste data from one excel to another excel. It was working fine until the destination excel's visibility was true. But I need to hide the excel at the time of execution. So I changed the visibility to false. Like, _destExcelApp = new Excel.ApplicationClass(); _destExcelApp.Visible = false; Now its showing an exception like Call was rejected by callee. (Exception from HRESULT: 0x80010001 (RPC_E_CALL_REJECTED)) How to solve this one? I ran into this same error being thrown when I deployed my application onto a

Using D programming language in a .NET context

我的未来我决定 提交于 2019-11-28 13:19:48
I'm curious: has anyone used D together with .NET languages? Is that even possible? What kind of stuff is easier/makes sense to do in D that's hard to do in, say, C++/CLI? Using D together with .NET is very possible. The reason: .NET is able to import unmanaged C libraries (.dll's which export C functions) using the dllImport attribute. D is able to export C functions. using the export and extern (C) attributes So the considering the technicalities, it's completely possible. With regards to what D makes easier than C++, the answer is fairly easy: "Everything". In a sense, D is really just a

How can I invoke a static method on a .NET object over COM interop?

自作多情 提交于 2019-11-28 13:16:55
Is it possible to invoke a static method on a .NET Object, via COM interop? I know I could write a wrapper class. What if I don't wanna do that? No you cannot do this. COM interop communicates via objects, not types. Work arounds I know of ... The best work around is to create a wrapper method on an instance to do the call on the type. Yes this still requires an instance so it defeats the purpose but it's you're best option. Reverse PInvoke: Still requires you to pass a function pointer down to the C++ layer 来源: https://stackoverflow.com/questions/1395897/how-can-i-invoke-a-static-method-on-a

Best Way to Release Excel Interop com Object

这一生的挚爱 提交于 2019-11-28 13:02:43
Experts, Please let me know the best way I can do this... I am working on a VB.Net application that uses the Microsoft.Office.Interop.Excel Object Library to create worksheets within a workbook and Pivot Tables within those worksheets. My code looks something like this: Dim ExcelApp As New Microsoft.Office.Interop.Excel.Application Dim wbk As Microsoft.Office.Interop.Excel.Workbook = Nothing Dim wksRawData As Microsoft.Office.Interop.Excel.Worksheet = Nothing Dim wksPvtTbl As Microsoft.Office.Interop.Excel.Worksheet = Nothing Dim pvtCache As Microsoft.Office.Interop.Excel.PivotCache = Nothing

How to use MS UI Automation in Delphi 2009

感情迁移 提交于 2019-11-28 13:01:49
I have a C# application, which uses Microsoft UI Automation functionality, e. g. a call like AutomationElement.RootElement.FindFirst(...) . Now I need to do the same thing (use MS UI Automation) in Delphi 2009. How can I a) declare that my Delphi code uses MS UI Automation library and b) make calls like AutomationElement.RootElement.FindFirst(...) ? There are several tutorials ( tutorial 1 , tutorial 2 ) explaining how to package one's own .NET code so that it can be used with Delphi, but in my case I need to use "pre-packaged" (already installed) assembly in Delphi. Update 1 Now I can get

Marshal an array of strings from C# to C code using p/invoke

£可爱£侵袭症+ 提交于 2019-11-28 13:00:18
I need to pass an array of C# strings into C code Example C code void print_string_array(const char** str_array, int length){ for (int i = 0; i < length; ++i) { printf("Sting[%l] = %s\n", i, str_array[i]); } } C# that I have tried (This did not work) string foo[] = {"testing", "one", "two", "three"}; print_string_array(foo, foo.Length); [DllImport(my_C_dll, CharSet = CharSet.Ansi)] private static extern void print_string_array([In][MarshalAs(UnmanagedType.LPArray, ArraySubType=UnmanagedType.LPStr)] string[] sa, int length); Fails with a System.AccessViolationException System

Calling C++ function from C#, with lots of complicated input and output parameters

淺唱寂寞╮ 提交于 2019-11-28 12:43:37
I am new to C# but have worked extensively with C++. I have a C++ function that needs to be called from C#. After reading some answers from SO and some googling, I conclude that I need to make a pure C interface to the function. I have done this, but am still confused about how to call it from C#. The function in C++ looks like this: int processImages( std::string& inputFilePath, // An input file const std::vector<std::string>& inputListOfDirs, // Input list of dirs std::vector<InternalStruct>& vecInternalStruct, // Input/Output struct std::vector<std::vector< int > >& OutputIntsForEachFile,

COM object that has been separated from its underlying RCW can not be used - why does it happen?

我的梦境 提交于 2019-11-28 12:29:28
I sometimes get the following exception: COM object that has been separated from its underlying RCW can not be used Sample code: using (AdOrganizationalUnit organizationalUnit = new AdOrganizationalUnit(ADHelper.GetDirectoryEntry(ouAdDn))) { using (AdUser user = organizationalUnit.AddUser(commonName)) { //set some properties user.Properties[key].Add(value); user.CommitChanges(); user.SetPassword(password); //it is set using Invoke //must be set after creating user user.Properties["UserAccountControl"].Value = 512; user.CommitChanges(); } } AdUser looks like this: public class AdUser :

Can I call a static method of a C# class from VBA via COM?

早过忘川 提交于 2019-11-28 12:20:40
If I define a class in a C#/.NET class library, then by making it COM visible I can instantiate the class and call its methods from VBA using COM. Is there any way to call the static methods of such a class from VBA? COM does not support static methods, and instances of COM objects do not invoke static methods. Instead, set ComVisible(false) on your static method, then make an instance method to wrap it: [ComVisible(true)] public class Foo { [ComVisible(false)] public static void Bar() {} public void BarInst() { Bar(); } } Or just make the method instance instead of static and forget static

How do I marshall a pointer to a pointer of an array of structures?

流过昼夜 提交于 2019-11-28 12:11:55
My C declarations are as follows: int myData(uint myHandle, tchar *dataName, long *Time, uint *maxData, DATASTRUCT **data); typedef struct { byte Rel; __int64 Time; char Validated; unsigned char Data[1]; } DATASTRUCT ; My C# declarations are as follows: [DllImport("myData.dll", EntryPoint = "myData")] public static extern int myData(uint myHandle, [MarshalAs(UnmanagedType.LPTStr)] string dataName, out long Time, out uint maxData, ref DATASTRUCT[] data); [StructLayout(LayoutKind.Sequential, Pack = 1)] public struct DATASTRUCT { public sbyte Rel; public long Time; public byte Validated; public