com-interop

How to mark .NET objects exposed to COM-interop as single threaded?

你。 提交于 2019-12-09 10:51:45
问题 When defining a COM-visible class in C++ I can define the supported threading model in the header file (the threading(single) line): [ coclass, default(IComInterface), threading(single), vi_progid("Example.ComClass"), progid("Example.ComClass.1"), version(1.0), uuid("72861DF5-4C77-43ec-A4DC-ED04396F0CCD") ] Is there a comparable way of setting the threading model in .NET (for example an attribute)? I currently define my COM-class as such: [Guid("67155A91-2948-43f5-B07F-5C55CDD240E5")]

tlbimp.exe converts HWND to _RemotableHandle

試著忘記壹切 提交于 2019-12-09 04:24:28
Our COM component interface has the next method: HRESULT CreatePluginWindow([in] HWND hParent, [in] RECT* prcView); We are going to use it in .NET application but interop for this interface is looking like this: void CreatePluginWindow(ref interop.alfrontx._RemotableHandle hParent, ref interop.alfrontx.tagRECT prcView) According my investigation there is no way to use this method without unsafe code. I'd not like to change COM interface in order to use other than HWND type for hParent, because it's used in many C++ components. I'd not like to make changes in interop because they are compiled

import txt files using excel interop in C# (QueryTables.Add)

早过忘川 提交于 2019-12-08 21:42:41
I am trying to insert text files into excel cell using Querytables.Add; no error, but the worksheet is empty. except for the single cell manipulation using Value2 property. I already using macro to record the object used. Can you help me on this(I am using vs2008, C# , excel 2003 and 2007; both shown empty cell). Below is my code; thanks for your help Application application = new ApplicationClass(); try { object misValue = Missing.Value; wbDoc = application.Workbooks.Open(flnmDoc, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue,

COM Interop (how to pass an array to the com) via classic ASP

回眸只為那壹抹淺笑 提交于 2019-12-08 21:16:46
问题 I need to create a com object for my classic asp, since i can create a .net Assembly and have it 'Interop' with com, so i proceeded to create a .net Assembly like this:- using System; using System.Collections.Generic; using System.Runtime.InteropServices; using System.Linq; using System.Text; using System.Data.SqlClient; using System.Data; using System.Configuration; using System.Web; namespace LMS { [ComVisible(true)] public class Calc { public int Add(int val1, int val2, out string[]

c# how to convert IntPtr to struct?

放肆的年华 提交于 2019-12-08 19:39:45
问题 A simple ATL com server: STDMETHODIMP CMyMath::get_Version(sVersionStruct **ppVer) { sVersionStruct* pVer = reinterpret_cast<sVersionStruct*>(CoTaskMemAlloc(sizeof(sVersionStruct))); if (!pVer) { return E_OUTOFMEMORY; } else { *pVer = ver_; *ppVer = pVer; return S_OK; } return S_OK; } STDMETHODIMP CMyMath::put_Version(sVersionStruct* ver) { ver_ = *ver; return S_OK; } idl definition: typedef [ uuid(72A4AA5B-6AD0-4249-B4CB-2FFB08301608) ] struct tagVersionStruct { int majorVersion; int

Why is it that ArrayList works with COM Interop, but IList<T> doesn't?

别来无恙 提交于 2019-12-08 18:41:50
问题 I've noticed that if I make a .NET component that exposes an ArrayList, then that ArrayList passes through COM Interop and is available in scripted languages such as VBScript. Generics, such as IList<T> do not seem to work. Why is this and is there any way to make a generic type successfully flow through COM Interop to a scripting engine? 回答1: Generics were added in .NET 2.0 and COM existed before .NET 1.0. (And was the technology .NET aimed to replace.) COM never had generics, and therefore

Does .NET interop copy array data back and forth, or does it pin the array?

纵饮孤独 提交于 2019-12-08 15:53:22
问题 I have this COM method signature, declared in C#: void Next(ref int pcch, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 0)] char[] pchText); I call it like this: int cch = 100; var buff = new char[cch]; com.Next(ref cch, buff); Does the .NET interop layer first copy the whole array to a temporary unmanaged memory buffer, then copy it back? Or does the array get automatically pinned and passed by reference? For the sake of trying, I did this in the COM object (C++): *pcch = 1; pchText[0]

using classes inside a COM exe from .Net

本小妞迷上赌 提交于 2019-12-08 11:12:24
问题 I have a .exe file I've been given which has COM classes inside it -- these are from C++, not .net ComVisible types I'd like to use those classes inside my .net project, but I can't add a reference to the exe; when I try I get DIALOG BOX: --------------------------- Microsoft Visual Studio --------------------------- A reference to 'C:\Program Files\blah\blah.exe' could not be added. Please make sure that the file is accessible, and that it is a valid assembly or COM component. --------------

How to use COM to pass a string from c# to c++?

混江龙づ霸主 提交于 2019-12-08 09:12:07
问题 when i try to call c# code from c++, i followed instructions from this article http://support.microsoft.com/kb/828736 part of my c# is : [Guid("6A2E9B00-C435-48f8-AEF1-747E9F39E77A")] public interface IGameHelper { void getInfo(out string result); } public class GameHelper : IGameHelper { void getInfo(out string result) { result = new StringBuilder().Append("Hello").ToString(); } } part of my c++ code: #import "../lst/bin/Release/LST.tlb" named_guids raw_interfaces_only using namespace LST;

How to use embedded registration-free manifest for ActiveX component from managed code like C#?

﹥>﹥吖頭↗ 提交于 2019-12-08 09:07:02
问题 I would like to use a specific version of ActiveX component that is not registered system- or user-wide. Everything works as expected if I use manifest files. However embedded manifest works only for C++ client code only. Here is dependency declaration <dependency> <dependentAssembly> <assemblyIdentity type="win32" name="MapWinGIS.ocx" version="4.9.1.0" /> </dependentAssembly> </dependency> If I use SxStrace, I see the following INFO: Parsing Manifest File C:\OSGeo4W\bin\TestApplication.exe.