com-interop

Need of ClassInterfaceType.None?

孤街浪徒 提交于 2019-12-01 10:54:22
Didn't quite get the following from MSDN : ClassInterfaceType.None Indicates that no class interface is generated for the class. If no interfaces are implemented explicitly, the class can only provide late-bound access through the IDispatch interface. This is the recommended setting for ClassInterfaceAttribute . Using ClassInterfaceType.None is the only way to expose functionality through interfaces implemented explicitly by the class. Is [ComVisible(true)] a must for COM visibility? See this blog post for the expanation of the first problem. The point is that unless you specify

Need of ClassInterfaceType.None?

你离开我真会死。 提交于 2019-12-01 09:18:04
问题 Didn't quite get the following from MSDN: ClassInterfaceType.None Indicates that no class interface is generated for the class. If no interfaces are implemented explicitly, the class can only provide late-bound access through the IDispatch interface. This is the recommended setting for ClassInterfaceAttribute . Using ClassInterfaceType.None is the only way to expose functionality through interfaces implemented explicitly by the class. Is [ComVisible(true)] a must for COM visibility? 回答1: See

COM methods, Char type and CharSet

和自甴很熟 提交于 2019-12-01 08:42:24
问题 This is a follow-up to my previous question: Does .NET interop copy array data back and forth, or does it pin the array? My method is a COM interface method (rather than a DllImport method). The C# signature looks like this: void Next(ref int pcch, [In, Out, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 0)] char [] pchText); MSDN says: When a managed Char type, which has Unicode formatting by default, is passed to unmanaged code, the interop marshaler converts the character set to ANSI.

Converting C++ string/wchar_t* to C# string?

强颜欢笑 提交于 2019-12-01 08:38:54
问题 Question: I need to call a C# dll from a C++ executable. I use COM, and it works fine for int, long and bool. But I can't get a string along... The IDL file says it's a BSTR, but I can't pass it correctly, and neither retrieve one. I tried using wchar_t* and using sysalloc as I did with VB6, but that doesn't seem to work. Anybody knows how, or what might be wrong ? 回答1: If you're using ATL you can do this: std::string theString = "hello"; CComBSTR bstr(theString.c_str()); DoSomething(bstr); /

Exposing indexer like properties to COM

帅比萌擦擦* 提交于 2019-12-01 08:03:03
问题 I have in existing COM-interface. I wan't to create a .net assembly that exposes a new interface as COM (with a new GUID), but the structure of the interface needs to be the same. How can i create a .net class (C#) that exposes this interface? [ odl, uuid(1ED4C594-DDD7-402F-90DE-7F85D65560C4), hidden, oleautomation ] interface _IFlashPhase : IUnknown { [propget] HRESULT _stdcall ComponentName( [in] short i, [out, retval] BSTR* pVal); [propput] HRESULT _stdcall ComponentName( [in] short i, [in

Creating IStream object in C#

你离开我真会死。 提交于 2019-12-01 06:33:28
问题 I'm writing a project and working with another party DLL. Function from their DLL wants an IStream object to save result, but I can't understand how to create an IStream object. Can anyone help me with my problem? 回答1: You don't create IStream object, because obviously it's an interface. You should rather implement this interface and pass your object. Or simply use an object that already implements it, if such object exists. Already given answer for a similar question gives a nice example how

Is a COMException of 0x80040154 always 'Class not registered'?

依然范特西╮ 提交于 2019-12-01 05:55:37
Does a System.Runtime.InteropServices.COMException of 0x80040154 always mean that the class isn't registered? I'm getting a COMException which says "Retrieving the COM class factory for component with CLSID {29131539-2EED-1069-BF5D-00DD011186B7} failed due to the following error: 80040154." It's trying to load Interop.Domino.dll which is a reference I got from the COM tab of Add Reference called "Lotus Domino Objects" which points to domobj.tlb in the Notes program folder. I wrote the code years ago - it's the only thing I've ever done with interop and it's fair to say that I never really got

COM Exception 80040154 When creating an Excel Application

末鹿安然 提交于 2019-12-01 05:52:18
I'm trying to run my application on a server which does not and will not have Office installed on it. using EXCEL = Microsoft.Office.Interop.Excel; ... EXCEL.Application app = new EXCEL.Application();//Exception thrown here The code is working fine on my own system, but on the server it gives the following 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)). both systems are 32bits,

Passing string array from VB6 to C#.net

♀尐吖头ヾ 提交于 2019-12-01 04:41:53
How to pass a VB6 string array [Assume, s =Array("a", "b", "c", "d")] to C#.Net through COM Interop? I tried to implement passing C# string array to VB and VB string array to C# as below C#->VB working fine but other way (VB=>C#) giving a compile error called "Function or interface marked as restricted, or the function uses an automation type not supported in visual basic" . My code below C# public interface ITest { string[] GetArray(); void SetArray(string[] arrayVal ); } public class Test : ITest { string[] ITest.GetArray() { //Working fine string[] stringArray = { "red ", "yellow", "blue" }

COM Exception 80040154 When creating an Excel Application

十年热恋 提交于 2019-12-01 04:03:18
问题 I'm trying to run my application on a server which does not and will not have Office installed on it. using EXCEL = Microsoft.Office.Interop.Excel; ... EXCEL.Application app = new EXCEL.Application();//Exception thrown here The code is working fine on my own system, but on the server it gives the following exception: Unhandled Exception: System.Runtime.InteropServices.COMException: Retrieving the COM class factory for component with CLSID {...} failed due to the following error: 80040154