.NET Framework - COM References problem in C# VS2008
Asked By Milan
20-Nov-09 03:01 PM

Hi Volks,
I just try using/generating COM under C# .NET VS2008 and I have 3 questions:
1. why in some projects I see GUID defined for every interface and class and
in some projects is only written [ComVisible(true)] ? Why both approaches are
allowed ?
2. I did register COM "MyClassLibrary.dll" with:
regasm MyClassLibrary.dll /tlb: MyClassLibrary.TLB
and in another project(but in the same solution) I needed reference to
MyClassLibrary.dll COM object but in COM Tab von "Add Reference" Dialog there
was only MyClassLibrary.TLB and not MyClassLibrary.dll !?
In order to use COM I needed to go to location where COM MyClassLibrary.dll
is located and to add it as assembly reference. In the normal COM programming
one expect to use COM and OS should find (through Registry entry) exact COM
location, right ?
Why In COM Tab where the list of all COM are is not listed
MyClassLibrary.dll ?
3. in a couple of examples projects I saw in Object Browser (after double
click on COM reference) that name of COM in "Object Browser" tool is not any
more "Some_COM_Name" but "Interop.Some_COM_name", why ?
Any help is appretiated!
BR,
Milan
Windows Installer
(1)
Registry
(1)
Library
(1)
Dialog
(1)
Tab
(1)
ComVisible
(1)
Volks
(1)
Zoki
(1)
Wilson, Phil replied to Milan

COM is interface-based, so good practice is to declare interfaces and
methods with interface ids and class guids. In C++ you had no choice but to
do this. In C# you can decide not to, and use ComVisible, and get a load of
stuff (like an interface) generated for you that is fairly invisible if
you are new to COM, and will make debugging harder IMO.
I think the rest of your question can be answered by saying that a managed
code reference to a Win32 COM object starts as a reference to its type
library, and then via a generated interop assembly (converted from the tlb)
and that is what your code calls. In Win32 COM Dlls the typelibrary is often
embedded in the Dll but it does not have to be.You do not need the actual COM
Dll to do development, just the type lib. Testing you need both of course.
However, if you are not using any Win32 code at all, and you are calling from
managed code to managed code then you are not expected to be using COM at
all, just normal Add Reference to an assembly. So the only actual COM
reference you can add is to the type library (and an interop assembly). I
do not believe managed code->interop assembly->CCW->managed code actually
works, so do not bother with COM at all if all your calls are managed code to
managed code.
--
Phil Wilson
The Definitive Guide to Windows Installer
http://www.apress.com/book/view/1590592972
Milan replied to Wilson, Phil
Hi Wilson,
the "Type Library" is not always denoted with extension ".TLB", right ? so
how to know if something is type library or not ?
Is it possible from .TBL to generate manage assemblies for .NET ?
and do I have to register both .TBL and .dll files if .dll has actual C++
COM definition ?
BR,
Zoki
Wilson, Phil replied to Milan
Type libraries are always .tlb, but many tools let you refer to a Win32 COM
DLL with its type library embedded in the resources.
Generating a managed assembly from a type library is exactly what tlbimp
does, the result being a COM interop assembly.
--
Phil Wilson
The Definitive Guide to Windows Installer
http://www.apress.com/book/view/1590592972
ContentAlignment (1) GraphicsUnit (1) EventHandler (1) FontStyle (1) CheckBox (1) TextBox (1) Is this a Windows Forms application? If so, there ishould be a region titled is not totally packed with InitializeComponent() { System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(InvoiceForm)); this.textBox17 = new System.Windows.Forms.TextBox(); this.textBox15 = new System.Windows.Forms.TextBox(); this.textBox7 = new System.Windows.Forms.TextBox(); this.textBox6 = new System.Windows.Forms.TextBox(); this.textBox5 = new System.Windows.Forms.TextBox(); this.textBox4 = new System Windows.Forms.TextBox(); this.textBox3 = new System.Windows.Forms.TextBox(); this.textBox2 = new System.Windows.Forms.TextBox(); this.textBox1 = new System.Windows.Forms
nested ShowDialog() behavior. I believe that the ShowDialog mothod shows a Form as a modal dialog, so you can not perform any action on any other Forms until you close the modal dialog. But I found the way to violate this rule. Let's say there are 3 enter key. 6.Now you have two ThirdForms. Assume that the ThirdForm is exit-confirming dialog, and popuped multiply. This is problem, and I do not like this behavior. I'd top-most or so. . . Any suggestions are really grateful. Thanks!!!! C# Discussions Visual Studio (1) Windows 7 (1) EventHandler (1) Exception (1) EventArgs (1) Class (1) VB (1) XP (1) try scenario, but definitely the same root cause): https: / / connect.microsoft.com / VisualStudio / feedback / details / 581382 / windows-taskbar-can-activate-a-non-modal-window-when-a-modal-window-is-active-wpf-winforms of thing, in the form of an extension method: public static void SafeShowDialog(this Form dialog, Form parent) { EventHandler handler = (sender, e) = > { dialog.Activate(); }; try { parent.Activated + = handler; dialog.ShowDialog(parent); } finally { parent.Activated - = handler; } } As an extension method, you can just change calls
is vb.net? VB.NET Discussions Visual Studio 2010 (1) Visual Studio (1) Silverlight (1) Windows 7 (1) Office (1) Vista (1) Linux (1) Error (1) HI again all I see crap that you could use as well :) - - Tom Shelton http: / / msdn.microsoft.com / en-us / library / 9s96f6ft(v = vs.71).aspx http: / / msdn.microsoft.com / en-us / library / system.drawing.printing.printdocument(v = VS.80).aspx http: / / www.vbdotnetheaven.com / has several articles No, check out sqlite - particularly it is a single dll, you reference in the references dialog and you have a complete file based rdbms. With transaction support and everythign. You can add it by right-clicking References and selecting "Add Reference". Scroll down in the .NET tab until you get find it - select it then click OK. I do not have the can be bothersome to access a specific name within the structure. For example, accessing System.Windows.Forms.Cursor.Current is a lot to type. Every time. For this reason, "Imports" are add Imports per file or at project level. So you can write this: Imports System.Windows.Forms class c sub bla cursor.current = . . . . end sub end class The name "cursor" is not found inside Sub bla, not inside class c, but inside the namespace System.Windows.Forms. That's why and how it works. You can also import a Class like
Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using WIA; using System.Runtime.InteropServices; using System.Configuration; namespace Scan { public partial class ToFileTime().ToString(); string FileName = "c: \ tempimage_" + scanTime + ".jpg"; img[ScanCount].SaveFile(FileName); C# Discussions System.Windows.Forms.ButtonBase.WndProc (1) System.Windows.Forms.Control.WmMouseUp (1) System.Windows.Forms.Button.OnMouseUp (1) System.Windows.Forms.Control.WndProc (1) System.Windows.Forms.Control.OnClick (1) System.Windows.Forms.Button.WndProc (1) System Windows.Forms.Button.OnClick (1) System.Threading.ThreadHelper.ThreadStart (1) Hello, I know that WIA is
VS 2003 as follows. . . A first chance exception of type 'System.NullReferenceException' occurred in system.windows.forms.dll Additional information: Object reference not set to an instance of an object. the call stack at this time looks like- (Word-wrap may make this look nasty) system.windows.forms.dll! System.Windows.Forms.ListView.ListViewItemCollection.get_Item(int displayIndex = 0x97) + 0x147 bytes system.windows.forms.dll! System.Windows.Forms.ListView.ListViewItemCollection.CopyTo (System.Array dest = {System.Array}, int index = 0x97) + 0x30 bytes system windows.forms.dll! System.Windows.Forms.ListView.OnHandleDestroyed(System.EventArgs e = {System.EventArgs}) + 0x12f bytes system.windows.forms.dll!System.Windows.Forms.Control.WmDestroy (System.Windows.Forms.Message m = {System.Windows.Forms