interop

How to insert a cover page in MS Word at the beginning of the document?

梦想的初衷 提交于 2019-12-11 15:57:52
问题 I need to insert a cover page into a Word 2016 document. The building block is a cover page and has InsertOptions = (int)WdDocPartInsertOptions.wdInsertPage; //= 2 So far so good. But VSTO can only insert so: buildingBlock.Insert(range); It does insert in place of range. The event Application.ActiveDocument.BuildingBlockInsert is not raised. Using native insert cover page (tab insert --> cover page) does insert properly (and creates only one undo entry insert building block). // -------------

Office Interop run via Task Scheduler

社会主义新天地 提交于 2019-12-11 15:13:50
问题 Trying to set up c# console program that converts pdf to html using Word as intermediary. Works from command line when logged in, but will not do when run from scheduler. Now I know MS do not officially support this- https://support.microsoft.com/en-us/help/257757/considerations-for-server-side-automation-of-office - but no the less I wish to pursue this avenue. I have seen various posts on workarounds, but have failed to get it to work. In short program stalls at the point of opening the

Memory leaks? in passing IEnumerable<byte[]> array to unmanaged function as byte** parameter

不打扰是莪最后的温柔 提交于 2019-12-11 15:08:51
问题 Is that the correct way to allocate and free handles to managed data passed to unmanaged dll? There is unmanaged dll with exported function void Function(byte** ppData, int N); I need to pass it IEnumerable<byte[]> afids var handles = afids.Select(afid => GCHandle.Alloc(afid, GCHandleType.Pinned)); var ptrs = handles.Select(h => h.AddrOfPinnedObject()); IntPtr[] afidPtrs = ptrs.ToArray(); uint N = (uint)afidPtrs.Length; Function(afidPtrs, N); handles.ToList().ForEach(h => h.Free()); I get

Problem at marshalling a standard C++ string to a C# string

假如想象 提交于 2019-12-11 13:25:32
问题 I'm writing a wrapper for a DLL that manages an OCR device. The DLL has a method whose signature resembles the following: unsigned long aMethod(char **firstParameter, char **secondParameter); aMethod returns string pointers to all parameters. I wrote this signature in C# ... it is almost functional: [DllImport(aDll.dll, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Auto)] static unsafe extern ulong aMethod(ref IntPtr firstParameter, ref IntPtr secondParameter); I do the

Multisampling and Direct3D10 / D3DImage interop

依然范特西╮ 提交于 2019-12-11 13:24:28
问题 I'm trying to implement a renderengine using Direct3D 10 (SlimDX) and WPF. I create my device and rendertargetview with the right MultiSample parameters ( 1,0 / 2,0 and 4,0 are working) this.multiSamplingDescription = new SampleDescription(sampleCount, qualityLevel - 1); // 4,1 Texture2DDescription colordesc = new Texture2DDescription(); colordesc.BindFlags = BindFlags.RenderTarget | BindFlags.ShaderResource; colordesc.Format = this.renderTargetViewFormat; // Format.B8G8R8A8_UNorm colordesc

Add as link to within a project folder to copy always to root of output

末鹿安然 提交于 2019-12-11 13:11:35
问题 I'm doing some interop with unmanaged .dll s in a standard c# project. I cannot add these .dll s as simple references and have to use P/Invoke to actually use them. They don't include manifests so doing any clever reflection stuff to load these dynamically (And thus solve the problem of including them as explicit, separate files) is simply out of the question. I am not concerned with installer releases, I can tell WiX(Or whatever installer platform I choose) what files to exactly put where on

Registering _set_purecall_handler function using P/Invoke in C#

家住魔仙堡 提交于 2019-12-11 13:09:48
问题 I'm having trouble using _set_purecall_handler with P/Invoke in C#. Basically, this works: (C++) _set_purecall_handler(MyPureCallHandler); void MyPureCallHandler(void) { // gets called } But this doesn’t: (C#) [UnmanagedFunctionPointer(CallingConvention.Cdecl)] private delegate void PureCallHandler(); [DllImport("msvcr100.dll", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr _set_purecall_handler([MarshalAs(UnmanagedType.FunctionPtr)] PureCallHandler handler); _set

How to edit cell value in VB.net - Using .Interop.Excel

有些话、适合烂在心里 提交于 2019-12-11 12:59:02
问题 This is a simple question. I have this code: CurrentRow = 3 MyColumn = 2 CurrentCell = (CurrentRow & "," & MyColumn) WorkingSheet.Cells(CurrentCell).value = (ClientName & " " & "(" & ClientLocation & ")" & " " & ExtraDefinition) I thought that this would place the data on the 'WorkingSheet' in the position "B3" but it places the data in the cell "AF1". Why is this? Thanks, Josh 回答1: Cell is not expected to be used as you are using it; you have to input the row and column indices (as integers)

Connect to COM events in C# - support both managed and unmanaged servers

无人久伴 提交于 2019-12-11 12:48:16
问题 I'm writing C# code that needs to connect to COM events. I implemented the use of IConnectionPointContainer and IConnectionPoint thus: IConnectionPointContainer connectionPointContainer = internalGenerator as IConnectionPointContainer; if (connectionPointContainer == null) { Debug.Fail("The script generator doesn't support the required interface - IConnectionPointContainer"); throw new InvalidCastException("The script generator doesn't support the required interface -

Unmanaged Exports / Robert Giesecke

旧街凉风 提交于 2019-12-11 12:36:41
问题 In the following answer Robert Giesecke describes a way to export managed code to native applications without the need of COM registration: Answer on stackoverflow from Robert Giesecke I downloaded the UnmanagedExportLibrary.zip from and built the samples using Visual C# 2008 Express Edition for the .net part and delphi 2010 for the win32 part as described on his page. When i start the delphi application which calls the dll, i get an exception "unable to start application...". Is someone able