interop

How to speed up dumping a DataTable into an Excel worksheet?

亡梦爱人 提交于 2019-11-28 23:27:53
I have the following routine that dumps a DataTable into an Excel worksheet. private void RenderDataTableOnXlSheet(DataTable dt, Excel.Worksheet xlWk, string [] columnNames, string [] fieldNames) { // render the column names (e.g. headers) for (int i = 0; i < columnNames.Length; i++) xlWk.Cells[1, i + 1] = columnNames[i]; // render the data for (int i = 0; i < fieldNames.Length; i++) { for (int j = 0; j < dt.Rows.Count; j++) { xlWk.Cells[j + 2, i + 1] = dt.Rows[j][fieldNames[i]].ToString(); } } } For whatever reason, dumping DataTable of 25 columns and 400 rows takes about 10-15 seconds on my

Call C++ native/unmanaged member functions from C# when member functions were not exported

本秂侑毒 提交于 2019-11-28 22:11:18
I have an unmanaged DLL that exports only a C style factory method that returns a new instance of a class (simplified here to look simple). hello.h #if defined(HWLIBRARY_EXPORT) // inside DLL # define HWAPI __declspec(dllexport) #else // outside DLL # define HWAPI __declspec(dllimport) #endif struct HelloWorld{ public: virtual void sayHello() = 0; virtual void release() = 0; }; extern "C" HWAPI HelloWorld* GetHW(); hello.cpp #include "hello.h" struct HelloWorldImpl : HelloWorld { void sayHello(){ int triv; std::cout<<"Hello World!"; std::cin>>triv; }; void release(){ this->HelloWorldImpl::

Writing to an existing Excel File using c#

て烟熏妆下的殇ゞ 提交于 2019-11-28 22:07:33
I am trying to open (or create a new xls) Excel file and write some values to it. Although, the program below works just fine if I simply create a new xls file, I encounter the some problem in line **mWorkBook = oXL.Workbooks.Open (path, 0, false, 5, "", "", false, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "", true, false, 0, true, false, false);** Here's the error: 'LOG.xls' cannot be accessed. The file may be corrupted, located on a server that is not responding, or read-only. It's not read-only, it's not corrupted(because sometime the file is created on Run Time). What is the

How to inject VBA code into Excel .xlsm without using Interop?

人走茶凉 提交于 2019-11-28 22:03:59
My goal is to add macros to an excel workbook without having to enable "Trust Access to the VBA Project Object Module" in the Excel Trust Center. (Enabling access seems a security risk). Found random pieces of puzzle on my initial fact finding search: -I see that VBA script is stored in the zipped .xlsm file as vbaProject.bin. -There are several free/commercial resources that can work with excel files: Create excel without interop and template with or without row and columnspan It would be nice to simply have a file of VBA script in the C# project that the C# code pulls from and injects into

How to create a COM object in a UWP application? (C#)

删除回忆录丶 提交于 2019-11-28 21:36:36
问题 Question: How to create COM object in a Universal Windows Platform (UWP) application? Motivation: I want to switch from WPF to UWP. Since my workload requires making calls to third-party libraries accessible only through COM (so far as I know), I need to make COM calls from UWP. Context: C# .NET Visual Studio 2015 Windows 10 Ideally targeting all UWP devices, but okay if restricted to desktops/laptops. Background In Visual Studio 2013 ("Classic Desktop" project in Visual Studio 2015), I used

Using a COM dll from C# without a type library

▼魔方 西西 提交于 2019-11-28 21:36:11
I need to use a COM component (a dll) developed in Delphi ages ago. The problem is: the dll does not contain a type library... and every interop feature (eg. TlbImp) in .NET seem to rely on TLBs. The component has been used in Delphi programs here for many years without problems because "It's not much of a problem using COM objects from Delphi, because we know the interfaces" (quote Delphi developer). Is there any way I can use this DLL from c# without a TLB? I've tried using the DLL as unmanaged, but the only method it exports are DllUnregisterServer , DllRegisterServer , DllCanUnloadNow and

Registering COM referenced DLLs on a build server

拟墨画扇 提交于 2019-11-28 21:31:45
We're developing a C# application that references a few COM libraries (AutoIT for example). I am including all referenced components under source control, in a 3rd party "Libs" folder. The problem is that COM dll's don't have a HintPath property in the .csproj file, and i assume these must be manually registered using regsvr32 (or using a script of some sort). I am currently looking into creating an MSBuild script that will run before every build, however i couldn't figure out if i should be manually calling regsvr32.exe or use some predefined MSBuild task? Currently, this is what i've

Entry Point Not Found Exception

限于喜欢 提交于 2019-11-28 21:27:42
I'm trying to use a C++ unmanaged dll in a C# project and I'm getting an error when trying to call a function that says that entry point cannot be found. public class Program { static void Main(string[] args) { IntPtr testIntPtr = aaeonAPIOpen(0); Console.WriteLine(testIntPtr.ToString()); } [DllImport("aonAPI.dll")] public static extern unsafe IntPtr aaeonAPIOpen(uint reserved); } Here is the dumpbin for the function: 5 4 00001020 ?aaeonAPIOpen@@YAPAXK@Z I changed the dll import to [DllImport("aonAPI.dll", EntryPoint="?aaeonAPIOpen")] and [DllImport("aonAPI.dll", EntryPoint="_aaeonAPIOpen")]

Could not load file or assembly 'Microsoft.mshtml … Strong name validation failed

走远了吗. 提交于 2019-11-28 21:22:07
I made a WPF/C# program and I am using the internet control for WYSIWYG HTML editing. it is a regular Executable program. it works on most computers however some computers are giving me the following error. Could not load file or assembly 'Microsoft.mshtml, Version=7.0.3300.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. Strong name validation failed. The 'Microsoft.mshtml.dll' file is distributed with the program. It is with all of the other required dlls in the same folder as the exe file. Here is the output from Fuslogvw *** Assembly Binder Log Entry (1/14

Java and C# interoperability

萝らか妹 提交于 2019-11-28 21:08:55
I have two programs. One is in C# and another one in Java. Those programs will, most probably, always run on the same machine. What would be the best way to let them talk to each other? So, to clarify the problem: This is a personal project (so professional/costly libraries are a no go). The message volume is low, there will be about 1 to 2 messages per second. The messages are small, a few primitive types should do the trick. I would like to keep the complexity low. The java application is deployed as a single jar as a plugin for another application. So the less external libraries I have to