天道酬勤,学无止境

interop

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

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 invocation in this way: aMethod(ref firstParameter, ref secondParameter); Marshalling and unmarshalling

2021-09-25 06:09:46    分类:问答    c#   .net   c++   interop   dllimport

C++ calling C# COM interop error: HRESULT 0x80131509

I create a C# COM interop for c++ to invoke. I have registered the dll and tlb file by regasm. everything goes well till one day i changed code of C# part (i didn't change the definition of interface, just implementation changed). one interface in COM returns an error 0x80131509. the strange thing is, it is only happened in some computers (my develop PC is works well so i can't debug this problem). I'm not really clear on how the C# COM worked with C++, after i registered them, i just know they create key value in window registry.(like what regasm /regfile generated). how c++ knows where the

2021-09-25 03:31:18    分类:问答    c#   com   interop

如何在 VB.net 中编辑单元格值 - 使用 .Interop.Excel(How to edit cell value in VB.net - Using .Interop.Excel)

问题 这是一个简单的问题。 我有这个代码: CurrentRow = 3 MyColumn = 2 CurrentCell = (CurrentRow & "," & MyColumn) WorkingSheet.Cells(CurrentCell).value = (ClientName & " " & "(" & ClientLocation & ")" & " " & ExtraDefinition) 我认为这会将数据放在“WorkingSheet”的位置“B3”中,但它会将数据放在单元格“AF1”中。 为什么是这样? 谢谢, 乔希 回答1 Cell不会像您使用的那样使用; 您必须输入以逗号分隔的行和列索引(作为整数)。 因此正确的代码是: WorkingSheet.Cells(CurrentRow, MyColumn).Value = (ClientName & " " & "(" & ClientLocation & ")" & " " & ExtraDefinition) 您拥有的另一种选择是使用Range 。 例子: WorkingSheet.Range("B3").Value = (ClientName & " " & "(" & ClientLocation & ")" & " " & ExtraDefinition)

2021-09-25 02:43:32    分类:技术分享    vb.net   excel   com   interop   cell

How to run MATLAB in background

I have 2 programs: A Fortran program that does a lot of calculations using intel compiler and Visual studio 2013, Windows 10. It generates a dataintomatlab.dat file as an input for the MATLAB program and receives a dataoutmatlab.dat file from MATLAB. A MATLAB m.file which loads dataintomatlab.dat and save data as dataoutmatlab.dat as an input for the Fortran program. The following code is used to link the Fortran program with MATLAB: result_matlab = SYSTEMQQ("C:\PROGRA~1\MATLAB\R2019a\bin\matlab.exe" -wait -nodesktop -nosplash -r "my_mfile") However, this is not efficient for large

2021-09-24 14:36:09    分类:问答    visual-studio   matlab   fortran   interop

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

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

2021-09-24 04:57:39    分类:问答    vb.net   excel   com   interop   cell

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

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??

2021-09-23 23:13:45    分类:问答    c#   excel   interop   export-to-excel

tlbexp.exe 更改方法名称的大小写(tlbexp.exe changes method names' case)

问题 我有一个比较奇怪的问题。 我正在将接口从 C# 库导出到 COM。 我已启用“向 COM 注册”项目设置,因此它调用 tlbexp.exe 来生成类型库。 我们在方法名称上使用驼峰式大小写,我注意到导出的类型库将这些恰好与类名重合的任何方法更改为 Pascal 大小写... 例如 interface IFoo { void randomClass() } class RandomClass { } 类型库中导出的 IFoo 定义了 IFoo->RandomClass() 而不是 IFoo->randomClass() 关于是什么原因以及如何阻止它的任何想法? 回答1 由于 COM 不区分大小写,因此“RandomClass”和“randomClass”在输出库的表中是相同的符号。 (这是 .NET 指南推荐类名和方法使用 PascalCasing 的部分原因。) 被选中的将是编译器发出的第一个,从程序员的角度来看,这是相当不确定的! 您可以使用 tlbexp 的/names参数选择其中之一,但两种大小写不能在库中共存。 要使用 tlbexp 的名称文件,您只需创建一个带有标识符列表的文件,每行一个: RandomClass SomeOtherIdentifier 然后你这样称呼它: tlbexp MyAssembly.dll /names=MyNames.txt 然后

2021-09-22 03:47:15    分类:技术分享    c#   com   interop   typelib   tlbexp

通过 COM 包装器从托管代码调用 COM 可见的托管组件(Calling COM visible managed component from managed code through COM wrapper)

问题 我有一个 3rd 方组件,可以说 FIPreviewHandler 来处理预览,它实现了 IPreviewHandler。 FIPreviewHandler 实现为托管组件,并通过互操作的方式使用 IPreviewHandler 接口和相关接口。 FIPreviewHandler 使用 regasm.exe 注册为 COM。 我有一个也是托管的客户端应用程序。 我想在我的应用程序中创建一个 FIPreviewHandler 实例作为 COM 组件。 我有一个定义 IPreviewHandler 和相关接口的互操作程序集。 当我使用 Activator.CreateInstance() 在 GetTypeByCLSID() 返回的类型上创建 FIPreviewHandler 的实例时,它使用 FIPreviewHandler 的正确 CLSID,它返回一个托管实例,因为它具有可用的实际程序集,并跳过 COM . 当我尝试将此实例 QI/cast 作为任何接口时,例如 IPreviewHandler,它返回 null,因为它作为托管对象加载,尽管 FIPreviewHandler 实现的 IPreviewHandler 接口与我在互操作中的接口相同,但它在不同的命名空间/程序集中,因此为空。 如果它返回给我一个 COM 实例/RCW (System.__ComObject)

2021-09-21 23:06:47    分类:技术分享    c#   com   interop   proxy   marshalling

无法转换类型为“Microsoft.Office.Interop.PowerPoint.ApplicationClass”的 COM 对象(Unable to cast COM object of type 'Microsoft.Office.Interop.PowerPoint.ApplicationClass')

问题 无法将“Microsoft.Office.Interop.PowerPoint.ApplicationClass”类型的 COM 对象转换为接口类型“Microsoft.Office.Interop.PowerPoint._Application” 。 此操作失败,因为 IID 为“{91493442-5A91-11CF-8700-00AA0060263B}”的接口的 COM 组件上的 QueryInterface 调用因以下错误而失败:库未注册。 (来自 HRESULT 的异常:0x8002801D (TYPE_E_LIBNOTREGISTERED))。 我无法找到解决方案,请有人帮忙吗?

2021-09-21 11:00:24    分类:技术分享    c#   interop

找出excel中是否有隐藏列(find out if there are hidden columns in excel)

问题 我需要知道excel表中是否有隐藏的列。 我使用了以下工作正常,然后突然停止工作。现在它总是返回false。 bool.Parse(worksheet.PageSetup.Application.Columns.Hidden.ToString()) TIA excel 2007 .net 3.5 回答1 根据需要重构以下代码片段。 Option Strict Off Imports System Imports System.Console Imports Microsoft.Office.Interop Public Class AreThereHiddenColumnsInExcelWorkSheet Public Shared Sub Execute() Dim excel = New Excel.Application excel.Visible = True excel.Workbooks.Add() excel.Columns("C:C").Select() excel.Selection.EntireColumn.Hidden = True Dim columns = excel.Columns Dim hasHiddenColumns As Boolean For Each column In columns If column.Hidden Then

2021-09-21 09:23:54    分类:技术分享    c#   excel   interop