Can anybody provide a direct, straightforward method of creating a DLL with properties and methods exposed to other programs I followed the instructions that I found on the MSDN websites as well as suggestions from forum participants. The DLL should be available both for COM and .NET programs. So far, nothing has worked.
There are numerous variations listed on the MSDN site. No doubt there are reasons for the differing instructions. However, I have not had sufficient success with any of them. Sometimes, just building the project makes the class visible to COM compatible programs. Other times, only after running regasm. Still other times, I have to run regasm, sn and gacutil before the DLLs class gets exposed. Then forums posters tell me: "you shouldn't have to do all that." I agree I shouldn't have to but even that is not sufficient. Even all that does not help because only the class and an enum are visible; the public properties, functions and subs are not available when I try to access the DLL. I've seen similar posts with a similar problems, but I've never seen an effective answer to the problem.
Example of previous similar problem without resolution:
http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=54426&SiteID=1
On the MS Press site I found a pdf file for a book called: Upgrading Microsoft Visual Baisc 6.0 to Microsoft Visual Basic.NET. The instructions it included worked fine in VB2003 as far as getting other programs to recognize the class in the DLL. Unfortunately, again the properties and methods were not available for use (in all cases, the best I could get was recognition of an Enum).
I've even found walkthroughs (usually quite helpful but in this case useless) which do give the result describe in the instructions. Is there anybody who knows the exact steps one must take to create a COM visible .NET dll

COM visible DLLs: are they only legends?
Lyn*
While the link noted appears to be a very good source of information and actually helped to clarify a few things for me, it still doesn't resolve my problem.
I did "...explicitly define an interface..." several days ago; that didn't help. Naturally the last option was the recommended one "...The last and recommended option is ClassInterfaceType.None..." is preferred but didn't work either. Not even the class no less its methods were visible. Also, can't use ClassInterfaceType and ComClass at the same time but: "...if you're using VB.NET and the ComClass attribute, it uses ClassInterfaceType.None behind the scenes and defines a nested explicit interface for you (to me, it appears to be implying that ClassInterfaceType is not needed if an interface is defined). However, the ComClass attribute also has versioning issues, so it's not recommended to use this as a shortcut." Oh well, not recommended and does not do the job anyway.
I've never found DLLs complicated to write in C++ or even VB until .NET came along. I know it is supposed to provide benefits in the loooooong run. I just hope it is worth all the time wasted trying to find answers to what used to be simple procedures. Now, I know where the term DLL Hell came from - .NET DLL. In the .NET help world everything is a piece of this maybe, a piece of that maybe, or maybe a piece of this other thing (or not), find some glue somewhere (if you can) and hope it works.
If the COM visible DLL is not a legend then I challenge all forum participants to provide one simple, clear-cut, straightforward, step by step explanation of how to create a COM visible .NET DLL. I'm not talking anything exotic - just a simple DLL with fields, properties, functions and subs that can be used by COM and .NET programs (as advertised but never explained).
AlxSharp
Did you finally get to use .NET component as COM components. If yes, please give me the solution because I've been thrue all what you 've been and there is no way I get to use it in an excel VBA module.
I can see properties, functions, subs but I can't creat instance of the object via
set a = new dllname.class
Please help !
thanks
Dominik Ras
Omega147
How about doing it the other way around You post your current solution somewhere and we try to help you find what's wrong.
Ronald S
Create a vb class library.
Select add new item, and click on COMClass
Add a public method to it.
Build the project, the class should now be registered - check the references window in vb6 to find the assembly name there.
Note that .Net does not work through registry entries as COM does - as such, if you want to use this class from .Net you need to add a reference to the assembly you just built, and unless you add it to the GAC every .net program that does reference it will need it's own copy (Visual studio will copy it for you, but if you're using the command line compiler, then you'll need to copy it manually).
Also note that to use the binary from com, it will have to be registered in the machine you want to use it from - use regasm for that.
mojaveson
See if this explains it
http://www.dotnetinterop.com/faq/ q=ClassInterface
Sidon
<Microsoft.VisualBasic.ComClass()>
Public Class MyExampleClass1Implements IMyExampleClass1 'Field
Private m_MyPrivateExampleField As Integer Public Property MyPublicExampleProperty() As Integer Implements IMyExampleClass1.MyPublicExampleProperty
Get
Return m_MyPrivateExampleField
End Get Set(ByVal value As Integer)
m_MyPrivateExampleField = value
End Set
End Property 'New - constructor required as is or class will not register properly
Public Sub New()
MyBase.New()
End Sub
Public Sub MyPublicExampleSub(ByVal s As String) _Implements IMyExampleClass1.MyPublicExampleSub
MsgBox(s)
End Sub Public Function MyPublicExampleFunction(ByVal x As Integer, ByVal y As Integer) _As Integer Implements IMyExampleClass1.MyPublicExampleFunction
MyPublicExampleFunction = x * y
End FunctionEnd
Classweezer24
http://msdn.microsoft.com/library/default.asp url=/library/en-us/vbcon98/html/vbconcreatinganinprocesscomponent.asp
CRasmussen
Three reason that I'd prefer not to: 1) proprietary software, 2) quite long, 3) I have many different versions all based on the varying information I've read on the MSDN site and instructions from posters. Of course, this brings me back to an earlier question: Is there one basic, straightforward way to create a COM class In my previous posts (several threads because I've been looking for this information for more than a week), I mentioned some of the methods tried: COM Class true, visible, etc.; with & w/out GUIDs; regasm'd, sn'd & gacutil'd (or not); w/ interface or w/out; and more. In some cases, the process is self-registering (preferred) in others the utils mentioned above are used.
Isn't there one, basic way create a COM class All the variations serve specific purposes but until the properties, functions & subs are visible (yes, their properties are marked w/ visible true), the COM class is useless. I would imagine that is the essential question. How does one make properties and methods visible to other programs The class has been recognized tho sometimes does and sometimes doesn't show up in the COM list (under Add Reference) in VB6, 2003 & 2005 Express. I could go back to using VB6 since the procedure is much easier to implement.
I know it can be done but so far no has been able to describe the process (a complete working solution; not a repeat of the bits and pieces on MSDN). I have seen other postings about similar problems on this forum and various others on the web. None that I have seen received a working response. So, I know I am not the only person with this problem. Perhaps sample code exists on the exact procedure for doing this. Again, a complete working com class (not disjointed bits & pieces).
BTW, the part about "legend" and "challenge" is a tongue in cheek approach to attract attention. It seems to be working because, of all the threads I've started on this subject, this has gotten the most response.
Holly522
Hope this helps
Making a COM object in VS2005< xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />
Start a vis studio project and make a class library.
In the class library, have an Interface section and then have a a procedure which Implements this (implements keyword). See the example attached.
Tick ON the COM Visible box (you’ll find it eventually)
Start a vis studio command window ( start programs-> vis studio tools)
Use the SN tool to make a strong name key pair -> SN/k democom.snk
Using Project-> Properties -> Signing, select this file as the key file – signs the assembly. If you don’t do this , you cannot put the assembly in the global assembly cache
Build the class library
With the vis studio command window, navigate to the assembly dir
Use REGASM /tlb:democom.tlb democom.dll
This registers the dll and the type library, and it also creates the type library
Use GACUTIL /I democom to insert the democom assembly in the global cache
Now go to VB6, or VBA and add a REFERENCE tot the progect. Democom appears in the list so tick it ON
Article at
http://whidbey.msdn.microsoft.com/library/default.asp url=/library/en-us/dndotnet/html/callnetfrcom.asp
title “Calling a .net Component from a COM components” (Mike Gunderloy)
was used as the basis for this procedure – although the detail of the operations is different
attachments:::
VB6 code to use democom
Private moTempClass As demoCOM.NET_Temperature
Private moTemp As demoCOM.iTemperature
Private Sub Command1_Click()
With moTemp
.Fahrenheit = txtfahrenheit.Text
TxtCelsius.Text = .GetCelsius
End With
End Sub
Private Sub Form_Load()
Set moTempClass = New demoCOM.NET_Temperature
Set moTemp = moTempClass
End Sub
DEMOCOM source VB.Net
Public Interface iTemperature
Property Celsius() As Double
Property Fahrenheit() As Double
Function GetCelsius() As Double
Function GetFahrenheit() As Double
End Interface
Public Class NET_Temperature
Implements iTemperature
Private mdblCelsius As Double
Private mdblFahrenheit As Double
Public Property Celsius() As Double _
Implements iTemperature.Celsius
Get
Celsius = mdblCelsius
End Get
Set(ByVal Value As Double)
mdblCelsius = Value
mdblFahrenheit = ((Value * 9) / 5) + 32
End Set
End Property
Public Property Fahrenheit() As Double _
Implements iTemperature.Fahrenheit
Get
Fahrenheit = mdblFahrenheit
End Get
Set(ByVal Value As Double)
mdblFahrenheit = Value
mdblCelsius = ((Value - 32) * 5) / 9
End Set
End Property
Public Function GetCelsius() As Double _
Implements iTemperature.GetCelsius
GetCelsius = mdblCelsius
End Function
Public Function GetFahrenheit() As Double _
Implements iTemperature.GetFahrenheit
GetFahrenheit = mdblFahrenheit
End Function
End Class
Paully_l
Create a Class library, select view all and open the assemblyinfo.vb file - set the assembly level comvisible attribute to true
On a class with public methods, add the comclass attribute
Build the assembly
Register the built binary with Regasm /tlb (unless the assembly is GAC'd you may also need /codebase for this to work, I'm a bit rusty on that)
That should do it, I've just made it work with command line tools only - check to see if vb6 allows you to use it.