interop

Why use FinalReleaseComObject instead of ReleaseComObject?

*爱你&永不变心* 提交于 2019-11-28 04:54:49
I know the basic difference as ReleaseComObject only decreases some counter by one and FinalReleaseComObject decreases it to zero. So what I usually hear is, call FinalReleaseComObject because then you are sure that the COM object is really released. But this makes me wonder, there is a point to this counter right? Aren't you breaking that mechanism if you always call FinalReleaseComObject . If that counter is not one before you call ReleaseComObject , is there not probably a reason for it? What could cause it to be higher than one when it should not be? Thanks in advance. PS: My COM

How well does WPF blend with XNA in real life?

对着背影说爱祢 提交于 2019-11-28 04:46:02
I understand that there are several ways to blend XNA and WPF within the same application. I find it enticing to use WPF for all GUI and HUD stuff in my XNA games. Does anyone have any practical experience on how well this approach works in real life using .NET 3.5 SP1 ? Any pitfalls (such as the "airspace problem" )? Any hint on what appoach works best? Kris Erickson There is an addition in 3.5 SP1 that allows better interaction between DirectX and WPF (D3DImage), and one way to get to that is through XNA. Here are some details: http://jmorrill.hjtcentral.com/Default.aspx?tabid=428&EntryID

File not found when loading dll from vb6

孤街浪徒 提交于 2019-11-28 04:25:32
问题 I am declaring and calling a dll function using the following syntax in VB6: 'Declare the function Private Declare Sub MYFUNC Lib "mylib.dll" () 'Call the function MYFUNC Calling the function results in the error File not found: mylib.dll . This happens when the application is run from the vb6 IDE or from a compiled executable. The dll is in the working directory, and I have checked that it is found using ProcMon.exe from sysinternals. There are no failed loads, but the Intel Fortran dlls are

Install MathLink program with arbitrary PATH environment

风流意气都作罢 提交于 2019-11-28 04:18:56
问题 Is it possible to use Install[] to start a MathLink program with a custom PATH environment variable? I am trying to use mEngine to connect Mathematica to MATLAB on Windows. It only works if mEngine.exe is launched when the PATH environment variable includes the path to the MATLAB libraries. Is it possible to modify the PATH for launching this program only , without needing to modify the system path? Or is there another way to launch mEngine.exe ? 回答1: @acl's solution to wrap mEngine.exe in a

Understanding the Running Object Table

霸气de小男生 提交于 2019-11-28 04:06:59
问题 I'm attempting to use the running object table to get a DTE a specific instance of Visual Studio. I was intending to use the technique described on MSDN. I've managed to get one of the instances to list, but not the others. public static void PrintRot() { IRunningObjectTable rot; IEnumMoniker enumMoniker; int retVal = GetRunningObjectTable(0, out rot); if (retVal == 0) { rot.EnumRunning(out enumMoniker); IntPtr fetched = IntPtr.Zero; IMoniker[] moniker = new IMoniker[1]; while (enumMoniker

Activator.CreateInstance(<guid>) works inside VSIDE but not externally

爷,独闯天下 提交于 2019-11-28 03:52:14
问题 I have a bunch of COM objects which all implement the same interface, and need to create one of them as chosen at runtime from a list of options. Since I know the CLSID for each of the implementing COM servers, this should be easy. However, for a certain subset of COM libraries, I can only make this work if I'm running inside of the VS2010 IDE. Here is the entire program I'm using to test with: using System; namespace ComTest { class Program { static void Main(string[] args) { var clsid = "

Possible to call a managed DLL from unmanaged C++?

醉酒当歌 提交于 2019-11-28 03:23:03
问题 Is it possible to call CLR DLL (one for example which is made with C#) from unmanaged C++ code? I need a DLL that is not managed to call into it somehow, maybe even via some proxy C++ process that is built with C++ / CLI? 回答1: The CLR DLL would have to be built as a COM visible assembly. If you have control of the C#, it's a simple rebuild, otherwise, is pretty much impossible to use it directly. 回答2: @SWeko gave you the best answer if you can modify the original DLL and your unmanaged code

Marshalling .NET generic types

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-28 01:54:42
Here is a C# program that tries Marshal.SizeOf on a few different types: using System; using System.Runtime.InteropServices; [StructLayout(LayoutKind.Sequential)] class AClass { } [StructLayout(LayoutKind.Sequential)] struct AStruct { } [StructLayout(LayoutKind.Sequential)] class B { AClass value; } [StructLayout(LayoutKind.Sequential)] class C<T> { T value; } class Program { static void M(object o) { Console.WriteLine(Marshal.SizeOf(o)); } static void Main() { M(new AClass()); M(new AStruct()); M(new B()); M(new C<AStruct>()); M(new C<AClass>()); } } The first four calls to M() succeed, but

C# - How to copy a single Excel worksheet from one workbook to another?

依然范特西╮ 提交于 2019-11-28 01:53:06
I have a need to copy a worksheet from one workbook into another and I'm a bit stuck. The premise is that I have a "master" workbook that stores the templates for a number of reports and I then need to create a blank copy of a specific worksheet and add it into a new workbook. This is what I have so far: private void CreateNewWorkbook(Tables table) { Excel.Application app = null; Excel.Workbook book = null; Excel.Worksheet sheet = null; try { string startPath = System.IO.Path.GetDirectoryName(System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName); string filePath = System.IO.Path

Excel.Range.Find method

谁说我不能喝 提交于 2019-11-28 01:14:29
问题 I am using Excel interop object and trying to find a date in a specified range by below method Excel.Range rngFind = WS.get_Range(strFromRange, strToRange).Find(strFind, Type.Missing, Excel.XlFindLookIn.xlFormulas, Excel.XlLookAt.xlPart, Excel.XlSearchOrder.xlByRows, Excel.XlSearchDirection.xlNext, false, false, false); but i get rngFind as null always my strFind = "Sep-08" i tried with both Excel.XlFindLookIn.xlFormulas and Excel.XlFindLookIn.xlValues my excel file looks like this Sep-08 Oct