com

Is it better to use the [using] statement in C# or the [dispose] method? Does this apply to external (COM) objects?

a 夏天 提交于 2020-01-23 12:29:13
问题 What is better, the using directive, or the dispose directive when finished with an object? using(FileStream fileStream = new FileStream( "logs/myapp.log", FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) { using(StreamReader streamReader = new StreamReader(fileStream)) { this.textBoxLogs.Text = streamReader.ReadToEnd(); } } On the other hand, when I'm dealing with System.Net.Mail, I'm told I need to Dispose() of the object to release any stray locks. Is there any consistent guidance?

Errors when calling certain Excel VBA macros from C#

血红的双手。 提交于 2020-01-23 08:13:46
问题 I have been struggling and searching on this problem to no avail... I have a few test macros that work perfectly when run from Excel, but either fail or don't work when called from C#, using the interop... I am using MS Visual Studio 2012 (on 64 bit Windows 7) to create a console application that will call the VBA macro TestMacro() written in Excel 2007. Here is the C# code to call the macro: (I basically copied what was done here Run Office Macros by Using Automation from Visual C# .NET)

Volume Shadow Copy in C++

痞子三分冷 提交于 2020-01-23 08:10:07
问题 I'm developing an application which will need to copy files that are locked. I intend on using the Volume Shadow Copy service in Windows XP+ but I'm running into a problem with the implementation. I am currently getting E_ACCESSDENIED when attempting calling CreateVssBackupComponents() which I believe is down to not having backup privileges so I am adjusting the process privilege token to include SE_BACKUP_NAME which succeeds but I still get the error. My code so far (error checking removed

Volume Shadow Copy in C++

徘徊边缘 提交于 2020-01-23 08:09:27
问题 I'm developing an application which will need to copy files that are locked. I intend on using the Volume Shadow Copy service in Windows XP+ but I'm running into a problem with the implementation. I am currently getting E_ACCESSDENIED when attempting calling CreateVssBackupComponents() which I believe is down to not having backup privileges so I am adjusting the process privilege token to include SE_BACKUP_NAME which succeeds but I still get the error. My code so far (error checking removed

How to get pointer to IUnknown in C#

让人想犯罪 __ 提交于 2020-01-22 18:52:13
问题 .NET interop wraps COM objects into .NET objects (runtime-callable wrappers, RCWs), which hide the usual interface querying. In order to register a COM object representing a filter graph with the Running Objects Table, I need the (native) address of its IUnknown interface (see How can I reverse engineer a DirectShow graph?). So the question is: How can I get a COM object's IUnknown pointer in C#? 回答1: Use Marshal.GetIUnknownForObject(). 来源: https://stackoverflow.com/questions/3941349/how-to

Export generic code (List<T>)to COM [duplicate]

北慕城南 提交于 2020-01-22 02:58:05
问题 This question already has answers here : What are alternatives to generic collections for COM Interop? (4 answers) Closed 6 years ago . COM doesn't support generics?What would be the best way to replicate this List<T> so that it's COM visible in the tlh file. EDIT:: c#:: [ComVisible(true)] [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] [Guid("FA677671-5E26-4307-AD2B-19BF1E7AFF8B")] public interface IEvents { IEvents[] CreateListeners(); } in C++ i have, CComSafeArray<CSharp::IEvents>

properties of c# class is not visible at visual basic 6.0

℡╲_俬逩灬. 提交于 2020-01-21 09:01:27
问题 I have created a class in c# and made the com visible property is true. But, i could not see the its properties at visual basic 6.0. what could be a problem? please help me 回答1: Define a public interface that is also ComVisible, and have your class implement that. Then use tlbexp.exe to generate a type libary from your C# assembly: tlbexp ComServer.dll /out:ComServer.tlb You need to add a reference to the type library from VB6, not the assembly. How does VB6 know where your assembly actually

How to extract a GUID from a Win32 DLL or OCX

杀马特。学长 韩版系。学妹 提交于 2020-01-21 08:28:08
问题 We have a .NET app that needs to examine a folder that may contain COM libraries (DLL and OCX.) When we do encounter a COM library one thing we need to accomplish is to extract the GUID from the COM DLL or OCX. Is there a straightforward way to do this with .NET without using 3rd party libraries? 回答1: This should work for you. It requires a reference to c:\windows\system32\tlbinf32.dll , but I'm assuming that is okay because it isn't a third party component. Imports TLI 'from c:\windows

How to extract a GUID from a Win32 DLL or OCX

蹲街弑〆低调 提交于 2020-01-21 08:27:04
问题 We have a .NET app that needs to examine a folder that may contain COM libraries (DLL and OCX.) When we do encounter a COM library one thing we need to accomplish is to extract the GUID from the COM DLL or OCX. Is there a straightforward way to do this with .NET without using 3rd party libraries? 回答1: This should work for you. It requires a reference to c:\windows\system32\tlbinf32.dll , but I'm assuming that is okay because it isn't a third party component. Imports TLI 'from c:\windows

IntelliSense in custom COM classes in VBA

旧巷老猫 提交于 2020-01-21 06:37:07
问题 Is there a way to get IntelliSense in own built COM classes in VBA? E.g. in the example below I would like to get "Number" showing up, whenever I press on the dot (or ctrl+space for shortcut): I suppose, if this is somehow resolved, I would also get some info concerning the public functions of the objects here: Thus, what are the suggestions? Suggestion 1 : 回答1: Simple example could look like this. c# class library named IntellisenseDemo code using System; using System.Runtime.InteropServices