interop

C# + COM Interop, deterministic release

旧街凉风 提交于 2019-12-18 12:24:26
问题 COM objects usually have deterministic destruction: they are freed when the last reference is released. How is this handled in C# - COM Interop? The classes don't implement IDisposable , so I see no way to trigger an explicit IUnknown::Release. A casual test shows that unreferenced COM objects get collected lazily (i.e. the garbage collector is triggering the release). What should I do for OCM objects that need to be released aggresively? (e.g. holding large or shared critical ressources)?

Reg Free Com with VB6 on Windows 7

99封情书 提交于 2019-12-18 12:16:31
问题 I have some .NET code I use from VB6 code. I have always developed this on an XP machine by creating a VB6.exe.manifest file that listed the dependent .NET assemblies. For example, say my 2 .NET assemblies are Some.Assembly.A.dll and Some.Assembly.B.dll, here is what VB6.EXE.manifest looks like (I use version=1.1.0.0 below because that is the version I set on the .NET AssemblyVersion in AssemblyInfo.cs): <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <assembly xmlns="urn:schemas

How does COM select how to marshal an interface?

China☆狼群 提交于 2019-12-18 12:06:19
问题 As I get it there're three ways to implement marshalling in COM: typelib marshalling proxy/stub marshalling implementing IMarshal by the object now how does the component consumer (user) choose which one will be used? Does it decide on its own and use the preferred way or does it call some built-in function and it solves the problem for it? I currently experience the following: my component implements a custom interface ICustomInterface that is also implemented by a component from another

Visual Studio 2010 64-bit COM Interop Issue

依然范特西╮ 提交于 2019-12-18 11:48:03
问题 I am trying to add a VC6 COM DLL to our VS2010RC C# solution. The DLL was compiled with the VC6 tools to create an x86 version and was compiled with the VC7 Cross-platform tools to generate a VC7 DLL. The x86 version of the assembly works fine as long as the consuming C# project's platform is set to x86. It doesn't matter whether the x64 or the x86 version of the DLL is actually registered. It works with both. If the platform is set to 'Any CPU' I receive a BadImageFormatException on the load

C++ Interop: How do I call a C# class from native C++, with the twist the class is non-static?

北慕城南 提交于 2019-12-18 11:44:19
问题 I have a large application written in native C++. I also have a class in C# that I need to call. If the C# class was static, then it would be trivial (there's lots of examples on the web) - just write the mixed C++/CLI wrapper, export the interfaces, and you're done. However, the C# class is non-static, and can't be changed to static as it has an interface (the compiler will generate an error if you attempt to make the C# class static). Has anyone run into this problem before - how do I

Using C/inline assembly in C#

心已入冬 提交于 2019-12-18 11:16:11
问题 Is there some method of using C source mixed with inline asm (this is not C++ code) in a C# app? I'm not picky about how it gets done, if it requires compiling the C/asm into a DLL alongside the C# app, so be it. I'm aware there's no provision for using assembly inside C#, hence this question. Sample code of what I'm trying to incorporate: SomeFunc(unsigned char *outputData, unsigned char *inputData, unsigned long inputDataLength) { _asm { //Assembly code that processes inputData and stores

How can I write to an Excel spreadsheet using Linq?

泄露秘密 提交于 2019-12-18 11:12:09
问题 I'm writing an app where I need to retrieve some rows from a DB and dump them into an Excel spreadsheet. I'm using Linq to retrieve these rows. Is it possible to dump these rows directly into their counterparts in the Excel sheet (where one cell in Excel corresponds to one cell from the DB)? 回答1: There's no direct way to connect these two. It sounds like you want LINQ to SQL to handle the query generation, but not the O/R mapping (because Excel wouldn't know what to do with the objects that

.NET Interop IntPtr vs. ref

不问归期 提交于 2019-12-18 11:11:56
问题 Probably a noob question but interop isn't one of my strong points yet. Aside from limiting the number of overloads is there any reason I should declare my DllImports like: [DllImport("user32.dll")] public static extern int SendMessage(IntPtr hWnd, int msg, int wParam, IntPtr lParam); And use them like this: IntPtr lParam = Marshal.AllocCoTaskMem(Marshal.SizeOf(formatrange)); Marshal.StructureToPtr(formatrange, lParam, false); int returnValue = User32.SendMessage(_RichTextBox.Handle,

Create advanced filter

风流意气都作罢 提交于 2019-12-18 09:38:11
问题 I am trying to create an advanced filter in Excel from C# to copy unique data from one sheet to another, at least I get it in Excel and if I use Interop like this : Excel.Range rang = sheet2.get_Range("A2"); Excel.Range oRng = sheet.get_Range("I2", "I" + (lst.Count + 1)); oRng.AdvancedFilter(Excel.XlFilterAction.xlFilterCopy, CriteriaRange: Type.Missing, CopyToRange: rang, Unique: true); Works fine but I'm doing all my application with EPPlus and it will be better if I can do the same without

linking dilemma (undefined reference) between MinGW and MSVC. MinGW fails MSVC works

我只是一个虾纸丫 提交于 2019-12-18 09:08:09
问题 I'm trying to port an old C .dll library originally done with MSVC that uses BEA Tuxedo library to use MinGW. I have encountered a situation where MSVC compiles and links one file but MinGW fails. The actual problem is in linking stage. There comes 'undefined reference' error. Here's the minimal example to create a dll: (tpsetunsol_test.c) #include <atmi.h> void __stdcall msghandler(char *pszMessage, long lMessageLen, long lFlags) { } int Inittpsetunsol() { int ret = 0; tpsetunsol(msghandler)