Tag: interop

是否可以从.NET测试COM暴露的程序集?

我有一个.NET程序集,我通过tlb文件向COM公开,以及一个注册tlb的安装程序。 我已手动检查安装程序是否正常工作,并且COM客户端可以访问该库。 到现在为止还挺好… 但是,我正在尝试组合一些自动化系统测试,以检查安装程序是否正常工作。 作为其中的一部分,我已经在VM上自动安装,我现在想要对已安装的COM库进行一些调用以validation它是否正常工作。 我最初想过在VB6中编写一些测试,但我已经有了一大堆用C#编写的测试,它引用了.NET程序集。 我希望我可以更改这些以引用.tlb,但是当我在VS2008中尝试这个时出现错误: ActiveX类型库’blah.tlb’是从.NET程序集导出的,无法添加为引用。 有什么方法可以欺骗VS2008允许我添加这个引用,也许是通过编辑tlb文件? 谷歌搜索没有提出任何解决方案。 我发现的只是一篇Microsoft Connect文章,声明这是“按设计”: http : //connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx ?FeedbackID = 120882

没有找到入口点的例外

我正在尝试在C#项目中使用C ++非托管dll,并且在尝试调用一个无法找到入口点的函数时遇到错误。 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); } 这是函数的dumpbin: 5 4 00001020 ?aaeonAPIOpen@@YAPAXK@Z 我将dll导入更改为[DllImport(“aonAPI.dll”, EntryPoint=”?aaeonAPIOpen”)]和[DllImport(“aonAPI.dll”, EntryPoint=”_aaeonAPIOpen”)]并且没有运气。

无法加载文件或程序集’Microsoft.mshtml …强名称validation失败

我制作了一个WPF / C#程序,我使用互联网控件进行所见即所得的HTML编辑。 它是一个常规的可执行程序。 它适用于大多数计算机,但有些计算机给我以下错误。 无法加载文件或程序集’Microsoft.mshtml,Version = 7.0.3300.0,Culture = neutral,PublicKeyToken = b03f5f7f11d50a3a’或其依赖项之一。 强名称validation失败。 “Microsoft.mshtml.dll”文件随程序一起分发。 它与exe文件在同一文件夹中的所有其他必需的dll。 这是Fuslogvw的输出 *** Assembly Binder Log Entry (1/14/2010 @ 6:36:51 PM) *** The operation failed. Bind result: hr = 0x80070002. The system cannot find the file specified. Assembly manager loaded from: c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\mscorwks.dll Running under executable C:\Documents and Settings\office\Desktop\Database\DATABASE.exe — A detailed […]

我们如何在c sharp中打开具有特定页码的word文件?

我们如何打开具有特定页码的word文件? 这是我用来打开文件的代码: public static Application Open(string fileName) { object fileNameAsObject = (object)fileName; Application wordApplication; try { wordApplication = new Application(); object readnly = false; object missing = System.Reflection.Missing.Value; wordApplication.Documents.Open(ref fileNameAsObject, ref missing, ref readnly); return wordApplication; } catch (Exception ex) { LogEntry log = new LogEntry(); log.Categories.Add(“Trace”); log.Message = ex.ToString(); Logger.Write(log, “Trace”); throw new System.IO.FileLoadException(“File […]

Interop从C#发送字符串到C ++

我想从C#发送一个字符串到本机C ++ DLL中的函数。 这是我的代码:C#方: [DllImport(@”Native3DHandler.dll”, EntryPoint = “#22”, CharSet = CharSet.Unicode)] private static extern void func1(byte[] path); public void func2(string path) { ASCIIEncoding encoding = new ASCIIEncoding(); byte[] arr = encoding.GetBytes(path); func1(this.something, arr); } C ++方面: void func1(char *path) { //… } 无论我发送什么,每次在C ++方面得到的都是一个空字符串。 救命? 谢谢。

获取word文档的页面

我试图通过Microsoft.Office.Interop.Word获取MSWord文档的所有页面(我在VS2012中使用C#)。 我想得到的是List Pages,其中index是页面数。 我理解(至少我认为是这样),没有直接的方法可以做到这一点。 所以我想出了类似的东西: List Pages = new List(); int NumberOfPreviousPage = -1; int NumberOfPage = -1; string InnerText = “”; for (int i = 0; i < Doc.Paragraphs.Count; i++) { Paragraph CurrentParagraph = Doc.Paragraphs[i + 1]; InnerText = CurrentParagraph.Range.Text; NumberOfPage = CurrentParagraph.Range.get_Information(WdInformation.wdActiveEndPageNumber); if (NumberOfPage == NumberOfPreviousPage) Pages[Pages.Count – 1] += String.Format("\r\n{0}", InnerText); else […]

从C ++ / CLI调用C#dll函数

我有一个C# dll。 代码如下: public class Calculate { public static int GetResult(int arg1, int arg2) { return arg1 + arg2; } public static string GetResult(string arg1, string arg2) { return arg1 + ” ” + arg2; } public static float GetResult(float arg1, float arg2) { return arg1 + arg2; } public Calculate() { } } 现在,我打算用这种方式从C++调用这个dll。 […]

如何编组指向结构数组指针的指针?

我的C声明如下: int myData(uint myHandle, tchar *dataName, long *Time, uint *maxData, DATASTRUCT **data); typedef struct { byte Rel; __int64 Time; char Validated; unsigned char Data[1]; } DATASTRUCT ; 我的C#声明如下: [DllImport(“myData.dll”, EntryPoint = “myData”)] public static extern int myData(uint myHandle, [MarshalAs(UnmanagedType.LPTStr)] string dataName, out long Time, out uint maxData, ref DATASTRUCT[] data); [StructLayout(LayoutKind.Sequential, Pack = 1)] public […]

将std :: wstring的内容从C ++返回到C#

我有一个非托管的C ++ DLL,我用一个简单的C接口包装,所以我可以从C#上调用PInvoke。 这是C包装器中的示例方法: const wchar_t* getMyString() { // Assume that someWideString is a std::wstring that will remain // in memory for the life of the incoming calls. return someWideString.c_str(); } 这是我的C#DLLImport设置。 [DllImport( “my.dll”, CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl )] private static extern string GetMyString(); 但是,字符串没有正确编组,通常会搞砸第一个字符,或者有时会显示一堆中文字符。 我已经记录了C端实现的输出,以确认std :: wstring是否正确形成。 我还尝试更改DLLImport以返回IntPtr并使用Marshal.PtrToStringUni使用包装方法进行转换,它具有相同的结果。 [DllImport( “my.dll”, CallingConvention = […]

如何将wchar_t *从C ++编组为C#作为out参数或返回值?

我试图在很多方面做到这一点,但没有一个是有效的。 有人有一个正确的例子吗? 我只想将wchar_t*值从函数移动到C#级别。