creating a COM object Template

PrimeLine

New member
Joined
Jan 16, 2006
Messages
4
Programming Experience
1-3
Hi, Can someone direct me to where i can find help on how to create a COM object using VB.net 2005. I just need the template. I try using the project wizard but at registerying the object, got an error about entry point. so i am sure i am missing something.
Any help would be appreciated.

Jack
 
You tried to register with RegSvr32.exe, which is for unmanaged COMs, in .Net you use RegAsm.exe.
http://msdn2.microsoft.com/library/h627s4zy(en-us,VS.80).aspx

Create a new "Class Library", go into Project Properties, Application Page, "Assembly Information..." dialog box, check "Make assembly COM-Visible".

Now you can register it with RegAsm.
Use a strong name if you need to add it to GAC (Global Assembly Cache) with GACutil.exe. Note in that case you use a local dll copy for development, but application will use the assembly in GAC during runtime. It seems the preferred .Net custom is to use local assemblies though.
To make it available for late binding add ProgID and Guid attributes (from System.Runtime.InteropServices) to the class.
 
unmanage code

I guess what i am trying to do is create unmanage code using vb.net 2005. I guess it is called the classic Com, used in VB6.0 when you have a class and with that you have function and you compile to a dll that you use regsvr32 to register and once that is done, you can reference it and use the functionality in your code. that is what i am trying to recreate, I am not sure if the Assembly is what i am looking for.
Thank You
Jack
 
That is exactly what you get with a .Net Class Library project, I don't think you need COM at all. Should you still need an unmanaged version, you can export with RegAsm to a Type Library (.tlb), in that case you may or may not have to define your own custom interface for that class.
But I think you will manage just fine with a basic Class Library.
 
here is what i am trying to do. The link will show what i am trying to do . first section of the vb.net code:
http://www.equisys.com/technotes/technotes.asp?ztnpage=/technotes/ztn1476.htm

I wanted to take that vb.net father and turn it into a COM ('MyFaxObject) so i can use SQL to call the fax.

EXEC @hr = sp_OACreate 'MyFaxObject.CMessages', @MailObject OUT
IF @hr <> 0 BEGIN
EXEC sp_OAGetErrorInfo @MailObject, @ErrorSrc OUT, @ErrorDescription OUT
SET @StatusMessage = 'Failed to complete, could not create message manager object ' + IsNull(@ErrorSrc, '') + ' ' + IsNull(@ErrorDescription, '')

GOTO EXIT_ON_ERROR
END
set
@MessageTemplateID = 1
IF (@MessageTemplateID > 0) BEGIN
set @FaxNumber = '123-4567'
set @CustomerName = 'Fax DEPARTMENT'
set @CompanyName = 'Corp'
SET @Message = 'This is a test'
SET @MessageSent = 1

EXEC @hr = sp_OAMethod @MailObject, 'SendFax', @MessageSent OUTPUT, @FaxNumber, @CustomerName, @CompanyName, @Message
IF @hr <> 0 BEGIN
EXEC sp_OAGetErrorInfo @MailObject, @ErrorSrc OUT, @ErrorDescription OUT
SET @StatusMessage = 'Failed to send message, SendMail function failed for email ' + @Email + ' ' + IsNull(@ErrorSrc, '') + ' ' + IsNull(@ErrorDescription, '')

END

MyComObject does not seem to register. need entry point. how can i trun the same code in the link into a COM object?

 
Anybody know if a .Net class library have to be "COM" to be used in SQL ?
 
Back
Top