Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Apr 22nd, 2008, 3:35 AM   #1
sardaukar
Newbie
 
Join Date: Oct 2006
Posts: 2
Rep Power: 0 sardaukar is on a distinguished road
Unhappy .NET (1.1) assembly as COM component

Hello.

I want to use an assembly as a COM component in SQL Server 2000, and so far have bee unsuccessful.

This is the assembly code:
using System;
using System.Text;
using System.Security.Cryptography;
using System.Runtime.InteropServices;

namespace EXSExtSHA1Call
{
	[ComVisible(true),
	GuidAttribute("89BB4535-5A89-43a0-89C5-19A4697E5C5C")]
	[ProgId("EXSExtSHA1Call.HostFunctions")]
	[ClassInterface(ClassInterfaceType.AutoDual)]
	public class HostFunctions
	{       
		[ComVisible(true)]
		public string GenerateHash (string plainText)
		{
			HashAlgorithm algo = new SHA1Managed();

			byte[] plainTextBytes = Encoding.UTF8.GetBytes(plainText);

			byte[] hashBytes = algo.ComputeHash(plainTextBytes);

			string hashValue = Convert.ToBase64String(hashBytes);

			return hashValue;
		}
	}
}

I have strong signed it (i.e., used "sn -k" to generate a key and added the key file path to the AssemblyInfo) and used regasm on the resulting DLL to register it as a COM component, which works. However, the following code in SQL Server 2000
DECLARE @object int
DECLARE @hr int
DECLARE @src varchar(255), @desc varchar(255)
DECLARE @return varchar(255)

EXEC @hr = sp_OACreate 'EXSExtSHA1Call.HostFunctions', @object OUT
IF @hr <> 0
BEGIN
   EXEC sp_OAGetErrorInfo @object, @src OUT, @desc OUT 
   SELECT hr=convert(varbinary(4),@hr), Source=@src, Description=@desc
   RETURN
END

SET @src = 'Test'

EXEC @hr = sp_OAMethod @object, 'GenerateHash', @return OUT
IF @hr <> 0
BEGIN
   EXEC sp_OAGetErrorInfo @object, @src OUT, @desc OUT 
   SELECT hr=convert(varbinary(4),@hr), Source=@src, Description=@desc
   RETURN
END
ELSE
PRINT @return

fails with 0x80020006 ODSOLE Extended Procedure Unknown name. If I don't call the method (if I just instatiate the object) it works.

My thought is I'm missing something in the way I refer to the 'GenerateHash' method in the COM call, because OLEVIEW shows, for this component:

[
  uuid(6F24A563-2273-355E-8E7D-B6D2F5FC9E15),
  hidden,
  dual,
  nonextensible,
  custom(0F21F359-AB84-41E8-9A78-36D110E6D2F9, EXSExtSHA1Call.HostFunctions)

]
dispinterface _HostFunctions {
    properties:
    methods:
        [id(00000000), propget,
          custom(54FC8F55-38DE-4703-9C4E-250351302B1C, 1)]
        BSTR ToString();
        [id(0x60020001)]
        VARIANT_BOOL Equals([in] VARIANT obj);
        [id(0x60020002)]
        long GetHashCode();
        [id(0x60020003)]
        _Type* GetType();
        [id(0x60020004)]
        BSTR GenerateHash([in] BSTR plainText);
};

Please help...
sardaukar is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
quick assembly question jbo423 Assembly 4 Nov 12th, 2007 7:21 AM
Using .NET 1.1 with Visual Studio 2005 ReggaetonKing C# 2 Aug 2nd, 2007 12:34 AM
Assembly Language DaWei Coder's Corner Lounge 0 Apr 26th, 2007 10:15 PM
Chekit out: Luban the new component oriented scritping language peterx Coder's Corner Lounge 11 Feb 24th, 2005 12:45 AM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 8:56 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC