Problem creating CCW

K

Kev

Gidday,

I am stuck trying to create a COM Callable Wrapper for the class (shell
only) below.

As you can see I have tried to define my interface and it would be all good
if I wasn't passing my enum into the main functions (which are marked public
static). I am unable to create an interface for the enum, and I can't mark
it as public static so not sure how to get the compiler to swallow it.

I'd rather not have to pass the enum to the functions as an integer as I
think this will break intellisense when calling the function (meaning I
don't think it will display the enumerated list which is a nice feature).
Also, I want this component to be stateless so I need to be able to specify
the crypto provider (the enumerated value) as part of the function call.
Lastly, I prefer a declarative approach so not really interested in just
enabling COM functionality under Project -> Properties.

Here's what I have so far (roughly - bit of a cut and paste so forgive any
obvious errors):

using System;
using System.Text;
using System.Runtime.InteropServices;
using System.Security.Cryptography;
namespace SomeNamespace.Encryption
{
#region COM Callable Wrapper (CCW)
[Guid("F8B65FF9-7D84-4b27-BEC7-8FFF31AA6C5E"),
InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
public interface _Symmetric
{
[DispId(1)] string EncryptString(enumCryptoServiceProvider
enumCryptoProvider, string strClearText, string strKey, string strSalt);
[DispId(2)] string DecryptString(enumCryptoServiceProvider
enumCryptoProvider, string strCipherText, string strKey, string strSalt);
// This wont work because you can't create an interface to a type
//[DispId(3)] enum enumCryptoServiceProvider;
}
#endregion
[Guid("F8B75FD9-7D84-4b27-BEC7-8FFF31AA6C5E"),
ClassInterface(ClassInterfaceType.None), ProgId("App.Class")]
public class Symmetric : _Symmetric
{
#region Declarations and enumerations
public enum enumCryptoServiceProvider : int
{//}
public Symmetric()
{
//return;
}
#endregion
#region Encryption routines
private static SymmetricAlgorithm
GetCryptoProvider(enumCryptoServiceProvider enumCryptoProvider)
{//}
private static void ConfigureOptions(SymmetricAlgorithm objCrypto, string
strKey, string strSalt)
{//}
public static string EncryptString(enumCryptoServiceProvider
enumCryptoProvider, string strClearText, string strKey, string strSalt)
{//}
public static string DecryptString(enumCryptoServiceProvider
enumCryptoProvider, string strCipherText, string strKey, string strSalt)
{//}
#endregion
}
}
Hope all this makes sense.... and thanks in advance...
 
K

Kev

I take it from the overwhelming volume of replies that either nobody has any
idea what I am talking about (probably my fault), or nobody has an answer.

Well guess what, I do. I figured out the problem was that the methods I
wanted to display through my interface were declared public static which is
not allowed for interfaces (try finding that bit of info easily... took me a
while...).

However, I wanted those methods to be public static... so I was stuck on how
to have them public static while also allowing use from VB6 and COM. In the
end I compromised and reverted my original crypto class back to before I
applied the CCW. I then created a new class with the same name but ending
with _COM and added the two methods I wanted to expose to COM with the same
method signature (parameters etc) but only the public modifier (no static).

In each method I simply passed the parameters to the public static methods
in the .Net class and passed the returned string back to the caller. Simple,
1 line of code in each mothod.

Then I applied the CCW to that class. Because it only had public methods the
compiler was nice and happy.

The end result is a .Net component that can have the methods called without
an object instance, and the same methods available via COM but requiring an
object instance. Like I said, a compromise. But one I can live with as I
rarely do COM these days.

If anybody has any interest in this I'll post the code.

Cheers

Kev said:
Gidday,

I am stuck trying to create a COM Callable Wrapper for the class (shell
only) below.

As you can see I have tried to define my interface and it would be all
good if I wasn't passing my enum into the main functions (which are marked
public static). I am unable to create an interface for the enum, and I
can't mark it as public static so not sure how to get the compiler to
swallow it.

I'd rather not have to pass the enum to the functions as an integer as I
think this will break intellisense when calling the function (meaning I
don't think it will display the enumerated list which is a nice feature).
Also, I want this component to be stateless so I need to be able to
specify the crypto provider (the enumerated value) as part of the function
call. Lastly, I prefer a declarative approach so not really interested in
just enabling COM functionality under Project -> Properties.

Here's what I have so far (roughly - bit of a cut and paste so forgive any
obvious errors):

using System;
using System.Text;
using System.Runtime.InteropServices;
using System.Security.Cryptography;
namespace SomeNamespace.Encryption
{
#region COM Callable Wrapper (CCW)
[Guid("F8B65FF9-7D84-4b27-BEC7-8FFF31AA6C5E"),
InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
public interface _Symmetric
{
[DispId(1)] string EncryptString(enumCryptoServiceProvider
enumCryptoProvider, string strClearText, string strKey, string strSalt);
[DispId(2)] string DecryptString(enumCryptoServiceProvider
enumCryptoProvider, string strCipherText, string strKey, string strSalt);
// This wont work because you can't create an interface to a type
//[DispId(3)] enum enumCryptoServiceProvider;
}
#endregion
[Guid("F8B75FD9-7D84-4b27-BEC7-8FFF31AA6C5E"),
ClassInterface(ClassInterfaceType.None), ProgId("App.Class")]
public class Symmetric : _Symmetric
{
#region Declarations and enumerations
public enum enumCryptoServiceProvider : int
{//}
public Symmetric()
{
//return;
}
#endregion
#region Encryption routines
private static SymmetricAlgorithm
GetCryptoProvider(enumCryptoServiceProvider enumCryptoProvider)
{//}
private static void ConfigureOptions(SymmetricAlgorithm objCrypto, string
strKey, string strSalt)
{//}
public static string EncryptString(enumCryptoServiceProvider
enumCryptoProvider, string strClearText, string strKey, string strSalt)
{//}
public static string DecryptString(enumCryptoServiceProvider
enumCryptoProvider, string strCipherText, string strKey, string strSalt)
{//}
#endregion
}
}
Hope all this makes sense.... and thanks in advance...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top