469,317 Members | 1,957 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,317 developers. It's quick & easy.

Problem creating CCW

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.InterfaceIsIDispatc h)]
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...
Nov 30 '06 #1
1 3254
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" <sp************@nochanceinhelloffindingmehere.comw rote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
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.InterfaceIsIDispatc h)]
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...

Dec 1 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by RJS | last post: by
6 posts views Thread by Club-B42 | last post: by
5 posts views Thread by יוני גולדברג | last post: by
1 post views Thread by Medora Schauer | last post: by
2 posts views Thread by tech tech | last post: by
2 posts views Thread by JJ | last post: by
8 posts views Thread by Chizl | last post: by
1 post views Thread by Ana RM | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Geralt96 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.