Tag: com interop

如何将数组(通过引用,在VB6中)传递给C \ C ++ * .dll子例程?

我需要将一个空的变量数组传递给用C编写的DLL(并且在所有Windows版本上都可用),并且C代码(我无法控制并且无法编辑)将填充变量空数组及其一些返回值值。 基本上,当我尝试这个时 – 当它应该包含函数/子调用的结果时,ByRef数组总是空的(如果我在.NET中执行完全相同的操作,它可以工作)。 我想我需要做一个自定义声明,所以VB知道如何调用C函数,或者? 以下是C子/函数的声明方式。 鉴于此,我需要做些什么才能确保C能够正确使用我的空数组并且我可以获得我的结果? HRESULT InvokeAction( [in] BSTR bstrActionName, [in] VARIANT varInActionArgs, [in, out] VARIANT *pvarOutActionArgs, [in, out] VARIANT *pvarRetVal ); 有关此function的更多信息: http : //msdn.microsoft.com/en-us/library/aa382237(VS.85).aspx 谢谢

从C#COM dll返回S_FALSE

我在IDL中定义了一个方法,如下所示: interface IMyFunc : IDispatch { [id(1), helpstring(“method GetNextFunction”)] HRESULT GetNextFunction( [in,out] long* lPos, [out, retval] BSTR* bstrName); } 使用C ++我总是按如下方式实现: STDMETHODIMP CMyFunc::GetNextFunction(long *nID, long *lPos, BSTR *bstrName) { if ( function to return ) { // setup return values; return S_OK; } else { // just exit return S_FALSE; } } 现在我在C#中实现它并且在类型库上使用了tlbimp并最终得到: public string […]

在对C#.NET 3.5服务器进行DCOM调用时,如何可靠地检查客户端身份?

我有一个旧的Win32 C ++ DCOM服务器,我正在重写使用C#.NET 3.5。 客户端应用程序位于远程Windows XP计算机上,也是用C ++编写的。 这些客户端必须保持不变,因此我必须在新的.NET对象上实现接口。 这已经完成,并且正在成功地实现接口,并且正确地从旧客户端到新.NET对象进行所有调用。 但是,我在从DCOM客户端获取调用用户的身份时遇到问题。 为了尝试识别发起DCOM呼叫的用户,我在服务器上有以下代码…… [DllImport(“ole32.dll”)] static extern int CoImpersonateClient(); [DllImport(“ole32.dll”)] static extern int CoRevertToSelf(); private string CallingUser { get { string sCallingUser = null; if (CoImpersonateClient() == 0) { WindowsPrincipal wp = System.Threading.Thread.CurrentPrincipal as WindowsPrincipal; if (wp != null) { WindowsIdentity wi = wp.Identity as WindowsIdentity; if […]

无法在C#中实例化COM组件 – 错误80070002

我正在尝试在我的机器上实例化Windows Media Player COM对象: Guid mediaPlayerClassId = new Guid(“47ac3c2f-7033-4d47-ae81-9c94e566c4cc”); Type mediaPlayerType = Type.GetTypeFromCLSID(mediaPlayerClassId); Activator.CreateInstance(mediaPlayerType); // <– this line throws 执行最后一行时,我收到以下错误: System.IO.FileNotFoundException was caught Message=”Retrieving the COM class factory for component with CLSID {47AC3C2F-7033-4D47-AE81-9C94E566C4CC} failed due to the following error: 80070002.” Source=”mscorlib” StackTrace: at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandle& ctor, Boolean& bNeedSecurityCheck) […]

COMexception80040154创建Excel应用程序时

我正在尝试在没有安装Office的服务器上运行我的应用程序。 using EXCEL = Microsoft.Office.Interop.Excel; … EXCEL.Application app = new EXCEL.Application();//Exception thrown here 代码在我自己的系统上工作正常,但在服务器上它提供以下exception: Unhandled Exception: System.Runtime.InteropServices.COMException: Retrieving the COM class factory for component with CLSID {…} failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)). 两个系统都是32位,我在应用程序的exe旁边复制了excel Interop dll。 我还安装了O2010PIA 。 任何铅?

尝试使用C#中的新IFileDialog和IFileOpenDialog接口打开文件对话框,使用最少的代码

我正在尝试使用C#,Visual Studio 2010中的IFileOpenDialog接口显示可以选择文件夹的标准打开文件对话框。 我正在尝试使用最小的代码,所以我只在接口中定义了我需要的方法: using System; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; // Disable warning CS0108: ‘x’ hides inherited member ‘y’. Use the new keyword if hiding was intended. \#pragma warning disable 0108 namespace FolderDialog { internal static class IIDGuid { internal const string IModalWindow = “b4db1657-70d7-485e-8e3e-6fcb5a5c1802”; internal const string IFileDialog = “42f85136-db7e-439c-85f1-e4075d135fc8”; internal const string IFileOpenDialog […]

C#COMponent引发的exception消息是否通过interop传递给C ++?

如果我在C#类中实现一个COM接口,它将从C ++模块调用,那么在发生故障的情况下,C#代码应抛出exception; 这将由interop层编组为HRESULT故障代码。 但是,传递给Exception构造函数的任何消息文本(或其他信息)是否也可用于调用C ++代码? 如果是这样,怎样才能获得哪种API方法? 例如,如果在我的C#代码中我throw new ArgumentException(“The email address is invalid”)我将除了我的COM HRESULT为E_INVALIDARG但是我的自定义文本将被编组或者我是否只能查找E_INVALIDARG的文本描述?

“以管理员身份运行”时,实例化COM组件失败并显示“未注册类”

实例化COM Interop对象时: var comObj = new ComComponentClass(); 我得到了COMException : Retrieving the COM class factory for component with CLSID {C343ED84-A129-11D3-B799-0060B0F159EF} failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)). 我以“以管理员身份运行”启动应用程序时出现此错误。 当我正常运行时,不会发生错误。 笔记: 该应用程序是64位应用程序。 COM组件是64位dll中的inproc服务器。 关于我应该从哪里开始调查为什么会出现这种差异的任何想法? 我尝试过的: 我使用Procmon来查看它检查的注册表项。 在这两种情况下,通过检查键HKCU\Software\Classes\CLSID\{C343ED84-A129-11d3-B799-0060B0F159EF}\InprocServer32适当的dll HKCU\Software\Classes\CLSID\{C343ED84-A129-11d3-B799-0060B0F159EF}\InprocServer32 在这两种情况下,它都会查询密钥HKCR\CLSID\{C343ED84-A129-11D3-B799-0060B0F159EF}并返回NAME NOT FOUND 。 我发现这很奇怪(因为我可以使用regedit.exe找到该密钥。但由于这两种方案之间没有区别,所以它似乎并不重要。

当没有MBN设备时,来自IMbnInterfaceManager :: GetInterfaces的hresult

我在Windows 7中使用以下代码: MbnInterfaceManager mbnInfMgr = new MbnInterfaceManager(); IMbnInterfaceManager mbnInfMgrInterface = mbnInfMgr as IMbnInterfaceManager; if (mbnInfMgrInterface != null) { IMbnInterface[] mobileInterfaces = mbnInfMgrInterface.GetInterfaces() as IMbnInterface[]; } MBN设备存在但MBN设备不存在时没有问题我在调用GetInterfaces()时遇到以下exception: {System.Runtime.InteropServices.COMException(0x80070490):找不到元素。 (来自HRESULT的exception:0x80070490)位于foo的MbnApi.IMbnInterfaceManager.GetInterfaces(),foo中的.Program.configureConnection() 问题在调用GetInterfaces之前,是否应该检查MBN接口? 我可以简单地捕获此exception,但我找不到任何文档说明此exception与没有接口相同。 我在statckoverflow上发现的最接近的事情就是使用C#在移动宽带api windows 7和Windows 8上挣扎,不知道安装什么意味着Windows 7的行为可能与Windows 8.1不同。

关闭Word文档时出错:“消息filter指示应用程序正忙。”

我正在使用Microsoft Interop将Word Doc保存为HTML文件,当我尝试关闭文档时出现此错误: 消息filter指示应用程序正忙。 (来自HRESULT的exception:0x8001010A(RPC_E_SERVERCALL_RETRYLATER)) 这是我的代码: // word interop setting object visible = true; object readOnly = true; object missing = Type.Missing; object saveChanges = true; object htmlFile = (object)Server.MapPath(@”worddoc.html”); object fileType = (object)Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatFilteredHTML; // open document Microsoft.Office.Interop.Word.Application wordApp = new Microsoft.Office.Interop.Word.Application(); Microsoft.Office.Interop.Word.Document wordDoc = wordApp.Documents.Open(ref url, ref missing, ref readOnly, ref missing, ref missing, […]