com

What's the difference in these ways of creating the static instance for a singleton?

此生再无相见时 提交于 2019-12-03 06:23:19
问题 I have had a bug recently that only manifested itself when the library was built as a release build rather than a debug build. The library is a .NET dll with a COM wrapper and I am using CoCreateInstance to create a class from the dll in an unmanaged c++ app. When I finally tracked the bug down it was caused by accessing a singleton object. I had the singleton instance declared like so: private static readonly MyObjectType s_instance = new MyObjectType; and then accessed it with: public

How to use Office from Visual Studio C#?

白昼怎懂夜的黑 提交于 2019-12-03 05:48:57
The technique for adding a reference to the COM interop of Office in Visual Studio is to go to: References Add Reference Select the COM tab Select Microsoft Office 11.0 Object Library And magically named reference appears: Microsoft.Office.Core The Project.csproj file shows the details of the reference: <COMReference Include="Microsoft.Office.Core"> <Guid>{2DF8D04C-5BFA-101B-BDE5-00AA0044DE52}</Guid> <VersionMajor>2</VersionMajor> <VersionMinor>3</VersionMinor> <Lcid>0</Lcid> <WrapperTool>primary</WrapperTool> <Isolated>False</Isolated> </COMReference> And the project is checked into source

Can I detect errors while using a .Net WebBrowser control?

倾然丶 夕夏残阳落幕 提交于 2019-12-03 05:46:44
I have an .Net Froms application that displays web pages through a WebBrowser control. Is there anyway that I can detect if the control shows a ' Page not found ' or ' Cannot display webpage ' error? There doesn't seem to be any error event handlers. The WebBrowser windows forms control is wrapper around Internet Explorer and it doesn't expose all the functionality of the underlying ActiveX control and particularly the NavigateError event. Here's a workaround: First add reference to SHDocVw.dll to your project (COM tab of Add Reference window). Then you can do the following to capture errors:

What is the ($Foo)PS project in my $Foo ATL solution for?

你离开我真会死。 提交于 2019-12-03 05:40:25
问题 Creating an ATL project in MSVC seems to create not one but two projects; the latter named the same as the former but with PS appended to its name. What is the purpose of this second project and how can I tell whether I need it? 回答1: COM supports making interface method calls across two different threads, two different processes or two different machines. This is called marshaling . Two different threads is the most common case, a COM server is often not thread-safe. COM implements thread

Allowing connection to .NET COM server with mismatching integrity level

杀马特。学长 韩版系。学妹 提交于 2019-12-03 04:09:50
I'm having an issue with a COM based client-server setup. The COM server is written in C# (.NET 4.0) and runs as a (registered) local server. Depending on which application connects to the server, other clients will receive a Server execution failed (Exception from HRESULT: 0x80080005 (CO_E_SERVER_EXEC_FAILURE) The underlying issue is explained here (in the section COM is integrity aware) . The way I understand it, it is being caused by the fact that an elevated application creates the server with a higher integrity level. When another non-elevated application then connects, it is not allowed

Why is COM interop preferred over P/Invoke in .NET?

余生长醉 提交于 2019-12-03 04:06:57
In our project we are reusing lot's of Delphi code through COM in our asp.net application. Like this: legacy delphi dll => delphi COM wrapper => .Net interop => asp.net (mvc) We have some issues regarding access violations, unloading of dll's, etc... I have now ported some to use the legacy dll directly through P/Invoke code. When I look at resources regarding COM and P/Invoke, people almost always advice to use COM. Why is that? Doesn't P/Invoke have the following benefits: checked out code will always use the correct dll‘s instead of the last registered COM Multiple versions can run side by

scriptable objects in internet explorer content plugin

大城市里の小女人 提交于 2019-12-03 03:39:33
While there are many guides for Browser Helper Objects, i have a hard time finding resources on how to implement scriptable objects (i.e. besides the main control) for content plugins (i.e. embedded in website). To avoid misunderstandings: the question is about scriptable objects that a plugin object may return to the scripts in a website, e.g. from a method call. While i guess scriptability in general for these probably works via the usual IDispatch , i don't see how events are to be handled (i.e. for attachEvent ). Are you supposed to implement that manually (e.g. handle calls to attachEvent

COM / OLE / ActiveX / IDispatch confusion

时光怂恿深爱的人放手 提交于 2019-12-03 03:23:50
I can't wrap my head around the differences among these terms. Are COM and ActiveX synonyms? Is ActiveX object just a COM object that exposes IDispatch? Lots of older MSDN pages mention IDispatch without any COM context. Does it have a separate history, and was just introduced under the COM 'umbrella' later in its lifecycle? Where does OLE fit in? Is its (considerable) presence in MFC naming and MSDN in general - all just legacy? Wikipedia gives some insight, but not much. I couldn't find a more in depth reference. Ofek Shilon Found some quotes from COM Programming by Example : Another thing

How to get system image list icon index of an IShellItem?

ぃ、小莉子 提交于 2019-12-03 03:09:17
Given a Windows Vista or newer IShellItem , how do i get the system image list icon index associated with that item? For example (pseudo-code) : IShellItem networkFolder = SHGetKnownFolderItem(FOLDERID_NetworkFolder, 0, 0, IShellItem); Int32 iconIndex = GetSmallSysIconIndex(networkFolder); Int32 GetSmallSysIconIndex(IShellItem item) { //TODO: Ask Stackoverflow } Background In the olden days (Windows 95 and newer), we could ask the shell to give us the system imagelist index for an item's icon. We did it using SHGetFileInfo . The SHGet­File­Info function gets the icon by asking the shell

How can I wrap a COM object in a native .NET class?

醉酒当歌 提交于 2019-12-03 01:54:06
I'm using an extensive existing COM API (could be Outlook, but it's not) in .NET (C#). I've done this by adding a "COM Reference" in Visual Studio so all the "magic" is done behind the scenes (i.e., I don't have to manually run tlbimp ). While the COM API can now be "easily" used from .NET, it is not very .NET friendly. For example, there are no generics, events are strange, oddities like IPicture , etc. So, I'd like to create a native .NET API that is implemented using the existing COM API. A simple first pass might be namespace Company.Product { class ComObject { public readonly global: