interop

string.withCString and UnsafeMutablePointer(mutating: cstring) wrapped into a function

旧时模样 提交于 2019-12-11 05:56:15
问题 I have a problem with the String.withCString{} in combination with UnsafeMutablePointer(mutating: ...). Given: a C-Function like this randomSign(xml_string: UnsafeMutablePointer<Int8>!) -> Uint Also given: a String like str = "some xml_tag" My working code is like this (VERSION_1) func randomSignWrapper_1(xml_tag_str: String) -> Uint { let result = xml_str.withCString { s in return randomSign(UnsafeMutablePointer(mutating: s)) } return result } But I want the withCString to be put into a

Receiving Windows Message on C# from managed Dll using p/invoke

♀尐吖头ヾ 提交于 2019-12-11 05:49:03
问题 I have to call some native C functions from C# using p/invoke. So far, I had no problems marshaling the different methods and structures to C#. Where my problem resides is in the fact that many of the methods I have to call are asynchronous, and return their final results to my WinForms application through Windows Messages. For instance, I have a call to a method that has the following signature in C: HRESULT AsyncOpenSession( LPSTR lpszLogicalName, HANDLE hApp, LPSTR lpszAppID, DWORD

Calling a function from a Win32 .lib project with /clr from a project that is a pure Win32 project, no clr

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-11 05:24:45
问题 I want to know how do I exactly call a function from ProjectA::ClassA::FuncA() that is a Win32 .lib with /clr from a ProjectB::ClassB::FuncB() that does not have clr support and is a pure Win32 project. Both these projects are under same solution. First, this is what I have tried: 1. Created the ProjectA with the .lib 2. Added the .lib path to ProjectB properties (in Linker:Input:Add.Dependencies) 3. I added the .h for the .lib created by ProjectA in ProjectB 4. Created the object for

TYPE_E_CANTLOADLIBRARY when using a COM object on a separate thread on Windows 2003 x64 only

℡╲_俬逩灬. 提交于 2019-12-11 04:55:15
问题 I have a Windows Forms app (compiled as x86) accessing a COM object. It gives me the following error, only on Windows 2003 x64, when the code is run on a separate thread: Exception during creation of IDoc:Unable to cast COM object of type 'PTISG.COM.TeklogixQueue.QueueClass' to interface type 'PTISG.COM.TeklogixQueue._Queue'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{3CBD7297-27D8-11D6-B75D-00902761DFA4}' failed due to the

Allowing multiple versions of the same COM library

巧了我就是萌 提交于 2019-12-11 04:46:33
问题 I wrote a C# program and library that allow a user to more easily use a particular proprietary simulator's COM interface. Currently I have to build and distribute a different version of the C# library for each version of the simulator I wish to support. The company that develops the simulator regularly releases new versions, and each new version gets an incremented major version number. As far as I can tell, there is no change to the COM interface between versions (yet) so the calls and

How to read pages in a Word document (C#)

偶尔善良 提交于 2019-12-11 04:36:22
问题 We use PDF-Focus. And we want to export PDF-documents in landscape-format to a Word-document. We want to export this document to Word. We get the document in Word. And everything looks fine. If we want to print this new word-document the margins of this document are portrait-orientated. I tried to solve this by creating an empty Word document and then inserting a temporary exported Word-document. Then I changed the orientation to Landscape. I saw that this solution works. The document is now

Word Interop C#: Insert new page using existing page

假如想象 提交于 2019-12-11 04:13:00
问题 I have a word template file which contains a table and it has 11 rows and 3 columns. So there are 33 cells in table on first page. I fill these cell with some data, however if number of records are greater than 33 say 66, I am creating two files, each containing 33 records. I want to create single file which will contain all 66 records and there should be two pages in one file instead of two separate files. How should I do it? Following is the code I am using to create one doc file. private

I want to add only one sheet after creating an Excel workbook through C#

笑着哭i 提交于 2019-12-11 04:09:50
问题 The code is this Excel.Application appC = new Excel.Application(); appC.Visible = true; Excel.Workbook bookC = appC.Workbooks.Add(1); Excel.Worksheet sheetC = bookC.Worksheets.Add(); sheetC.Name = "something"; The command Workbook.Add() takes one parameter that is supposed to determine how many sheets will be created in the workbook... right? So why do I get 2 sheets... one named "something" and one named "sheet 2"? What am I doing wrong?? 回答1: This is the code to create an Excel application

Date conversion issue with Excel Interop and CSV file

不想你离开。 提交于 2019-12-11 03:43:48
问题 I have a CSV file which contains dates formatted as m/dd/yyyy as follows 1/06/2013,15,1,1/06/2013 0:15,1,6.44 When I open the file in Excel, the dates are correctly converted - 1/06/2013 has numeric value 41,426.00 and the MONTH() function returns 6. When I use Microsoft.Office.Interop.Excel to open the same file using either the Open() or OpenText() method the date gets converted to 41,280.00 (6/01/2013). Can you open a CSV file using Microsoft.Office.Interop.Excel so that it opens the same

CopyFileEx in windows 7

左心房为你撑大大i 提交于 2019-12-11 03:28:30
问题 I'm trying to use function CopyFileEx from kernel32.dll in Windows 7 using .NET interop. MSDN says: If lpProgressRoutine returns PROGRESS_STOP due to the user stopping the operation, CopyFileEx will return zero and GetLastError will return ERROR_REQUEST_ABORTED. In this case, the partially copied destination file is left intact. On windows XP code works OK, but on Windows 7 partial file is being deleted automatically. Have I missed something? using System; using System.Runtime.InteropServices