com-interop

How can I speed-up creating excel Excel spreadsheets from C#?

五迷三道 提交于 2019-12-06 05:55:57
问题 I am currently writing around 200 Excel spreadsheets using Excel 2007 with C# COM Interop. Unfortunately I need about 4 minutes to write these 200 sheets - each sheet has around 1000 rows with 8- 10 columns. How can I speed up things? My code looks like this basically: var xlApp = new Excel.Application(); xlApp.DisplayAlerts=false; foreach (x in z) { var wb = xlApp.Workbooks.add(XLWBATemplae.xlWBATWorksheet); var ws = (Worksheet)wb.Worksheets[1]; //fill data into sheet wb.SaveAs(fileName);

Dynamically load and use COM object in C#

只谈情不闲聊 提交于 2019-12-06 05:27:35
问题 I have a C# project, where I would like to access MS outlook, if it is installed on a client´s machine. The "access outlook" part has been done by referencing the outlook COM object, and going from there. My problem is now the "if it is installed" part. At the moment, my project doesn´t compile on machines without outlook installed, so I assume that I will have to not reference the outlook component, and instead load and use it dynamically, after detecting that outlook is present, but I haven

Difference between Dual interface and Dispatch only interface for C# COM automation

本小妞迷上赌 提交于 2019-12-06 05:26:06
问题 I am implementing a c# COM client against a C++ COM server. The COM client functions correctly when I mark the COM interface as "Dual" but it throws an InvalidCastException when I remove the "Dual" attribute. Therefore the easy fix for me is to mark it as Dual. But from reading online, it looks like it is not the recommended approach to use for COM servers. Can anyone explain to me the significance (in layman terms) to marking an interface as dual and why it would not be recommended? I only

Embed a Registration-Free COM manifest into a C# dll with native/managed environment

冷暖自知 提交于 2019-12-06 04:59:20
问题 I'm currently working on a mixed native / managed application chain, which employs registration-free COM. The following image illustrates this: The C# wrapper DLL has been created using the tlbimp.exe utility. This allows each of the C# executables to access the native types and methods in the COM DLL. The COM DLL itself employs a server based RegFree COM manifest. Everything works fine, when the client based RegFree COM manifests are embedded in the C# executables. However, I would like to

Pass string from unmanaged code to managed

北战南征 提交于 2019-12-06 04:32:30
问题 I have a problems with passing string from unmanaged code to managed. In my unmanaged class ( unmanagedClass.cpp ) I have a pointer to function from managed code: TESTCALLBACK_FUNCTION testCbFunc; TESTCALLBACK_FUNCTION takes one string and returns nothing: typedef void (*TESTCALLBACK_FUNCTION )(char* msg); Unmanaged class inherites from ITest interface which has only one method: STDMETHOD(put_TestCallBack) (THIS_ LPVOID FnAddress ) PURE; In managedClass.cs I write this code: public class

Load a COM dll at runtime?

微笑、不失礼 提交于 2019-12-06 03:57:39
问题 I'm writing an application for the Peachtree API and it needs to work with any version of the API. Unfortunately the dll from Peachtree 2011 can't interact with Peachtree 2010, and vice versa, even though the two dlls are stored in the same location and run with exactly the same code. I thought I should be able to refer to the dll by it's file path, leave specific version at false, embed interop types at false, and copy local at false and it would just use whatever version the machine had,

Custom COM class factory for managed in-proc server

馋奶兔 提交于 2019-12-06 03:01:15
I'm looking at implementing custom COM activation logic for a managed class library, in MkParseDisplayName/BindToObject manner . This way, creating an object from VB might look like this: obj = GetObject("clsid:12341234-1234-1234-1234-123412341234:!UniqueObjectId") That would not be a problem for an out-of-proc server (using CoRegisterClassObject ). However, for an in-proc server, I'd need to alter the implementation of DllGetClassObject , which is normally provided by mscoree.dll . Is this possible at all? The only other option I see is to create a C# singleton object to serve as class

Raise positive VB style error codes via COM interop from C#

隐身守侯 提交于 2019-12-06 02:25:27
I have a base library created in VB6 that exposes a standard COM interface that is used in a number of applications. This also exposed a number of error code constants, used with Err.Raise to indicate certain conditions. Public Enum IOErrors IOErrorBase = 45000 IOErrorConnectionFailed IOErrorAuthFailed IOErrorNotConnected IOErrorInvalidPortDirection IOErrorGettingValue IOErrorNoValueYet End Enum Come on 10 years and we're creating C# objects implementing the same set of interfaces and want to throw exceptions in a way that the calling application will recognise them. I can only find two

COMException (0x800401E3): Operation unavailable (Exception from HRESULT: 0x800401E3 (MK_E_UNAVAILABLE)) with scheduled task

馋奶兔 提交于 2019-12-06 02:06:21
After searching on the web without success, here's my question. I've a task that i want to schedule to retrieve the attachment of an email from outlook and extract the data. It works fine when I launch the task manually but whenever I try to launch it through a scheduled task it fails with the error : COMException (0x800401E3): Operation unavailable (Exception from HRESULT: 0x800401E3 (MK_E_UNAVAILABLE)) It occurs when the program tries to retrieve or create an instance of Outlook as follow: private Application GetApplicationObject() { Application application = null; if (Process

How to debug a managed BHO from Visual Studio 2010

青春壹個敷衍的年華 提交于 2019-12-06 01:59:51
问题 I've a managed Explorer Bar (working in Internet Explorer) that is working reasonably well. Currently, the only way to debug it: Start IE outside VS From VS (Debug => Attach) Attach to the process "iexplore.exe" Trying to do the following: Go to Project Properties => Debug tab Start External Program: c:\program files (x86)\internet explorer\iexplore.exe Command line argument: about:blank Hit F5 The first method is very cumbersome. With the second method, iexplore starts, but the debugger