471,325 Members | 1,591 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,325 software developers and data experts.

Passing information from Unmanaged to Managed code

Tim
When there is a need to pass some dynamic information between 2 managed
assemblies, the "Dictionary object" in Generic form can be used as a method
parameter to pass the information. The information that needs to be passed
can be stored as Key-Value pairs, and the method signature remains the same.
That way, handling future requirements of passing additional details to the
callee can be handled without changing the method signature.

Is there some such similar way to pass dynamic information from Unmanaged
code (VB6) to managed code. Generics are not visible to COM. So what can be
done such that the method signature does not change, but future requirements
of having to pass additional data can be handled?
Dec 29 '05 #1
7 10114
Tim,

Actually, fully instantiated Generics can be expose to COM. You just
have to specify a type parameter.

In this case, you would have to create a generic type which extends the
generic instance, setting the type parameters, and expose that to COM. Of
course, this means you would have to do it for all generic type parameter
combinations that you want to use.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Tim" <Ti*@discussions.microsoft.com> wrote in message
news:0D**********************************@microsof t.com...
When there is a need to pass some dynamic information between 2 managed
assemblies, the "Dictionary object" in Generic form can be used as a
method
parameter to pass the information. The information that needs to be passed
can be stored as Key-Value pairs, and the method signature remains the
same.
That way, handling future requirements of passing additional details to
the
callee can be handled without changing the method signature.

Is there some such similar way to pass dynamic information from Unmanaged
code (VB6) to managed code. Generics are not visible to COM. So what can
be
done such that the method signature does not change, but future
requirements
of having to pass additional data can be handled?

Dec 29 '05 #2
Tim
Thanks Nicholas for the immediate response. Can you point me to some link
where I can get further information on this subject.

"Nicholas Paldino [.NET/C# MVP]" wrote:
Tim,

Actually, fully instantiated Generics can be expose to COM. You just
have to specify a type parameter.

In this case, you would have to create a generic type which extends the
generic instance, setting the type parameters, and expose that to COM. Of
course, this means you would have to do it for all generic type parameter
combinations that you want to use.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Tim" <Ti*@discussions.microsoft.com> wrote in message
news:0D**********************************@microsof t.com...
When there is a need to pass some dynamic information between 2 managed
assemblies, the "Dictionary object" in Generic form can be used as a
method
parameter to pass the information. The information that needs to be passed
can be stored as Key-Value pairs, and the method signature remains the
same.
That way, handling future requirements of passing additional details to
the
callee can be handled without changing the method signature.

Is there some such similar way to pass dynamic information from Unmanaged
code (VB6) to managed code. Generics are not visible to COM. So what can
be
done such that the method signature does not change, but future
requirements
of having to pass additional data can be handled?


Dec 29 '05 #3
Tim,

I don't have a direct link, but its like any other class. Say you had
this:

public class MyClass<T>
{
public void DoSomething(T obj)
{
}
}

You would have to create a specific type and expose that to COM, like
so:

public class MyClassInt : MyClass<int>
{}

Then, MyClassInt could be exposed to COM. Now, if you have some methods
that are public and take type parameters separate from the ones in the type
declaration, you will have to wrap the whole object, and expose the methods
with the appropriate type.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Tim" <Ti*@discussions.microsoft.com> wrote in message
news:00**********************************@microsof t.com...
Thanks Nicholas for the immediate response. Can you point me to some link
where I can get further information on this subject.

"Nicholas Paldino [.NET/C# MVP]" wrote:
Tim,

Actually, fully instantiated Generics can be expose to COM. You just
have to specify a type parameter.

In this case, you would have to create a generic type which extends
the
generic instance, setting the type parameters, and expose that to COM.
Of
course, this means you would have to do it for all generic type parameter
combinations that you want to use.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Tim" <Ti*@discussions.microsoft.com> wrote in message
news:0D**********************************@microsof t.com...
> When there is a need to pass some dynamic information between 2 managed
> assemblies, the "Dictionary object" in Generic form can be used as a
> method
> parameter to pass the information. The information that needs to be
> passed
> can be stored as Key-Value pairs, and the method signature remains the
> same.
> That way, handling future requirements of passing additional details to
> the
> callee can be handled without changing the method signature.
>
> Is there some such similar way to pass dynamic information from
> Unmanaged
> code (VB6) to managed code. Generics are not visible to COM. So what
> can
> be
> done such that the method signature does not change, but future
> requirements
> of having to pass additional data can be handled?


Dec 29 '05 #4
Tim
Hi Nicholas,

When I tried using Generics in the interface declaration, and then
used RegAsm to register the assembly, I got an error.

When I was searching the Net for more info on the subject, I came across Sam
Gentile's blog:
http://samgentile.com/blog/articles/12367.aspx.

I faced the same error as he has talked about. Any resolution?

"Nicholas Paldino [.NET/C# MVP]" wrote:
Tim,

I don't have a direct link, but its like any other class. Say you had
this:

public class MyClass<T>
{
public void DoSomething(T obj)
{
}
}

You would have to create a specific type and expose that to COM, like
so:

public class MyClassInt : MyClass<int>
{}

Then, MyClassInt could be exposed to COM. Now, if you have some methods
that are public and take type parameters separate from the ones in the type
declaration, you will have to wrap the whole object, and expose the methods
with the appropriate type.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Tim" <Ti*@discussions.microsoft.com> wrote in message
news:00**********************************@microsof t.com...
Thanks Nicholas for the immediate response. Can you point me to some link
where I can get further information on this subject.

"Nicholas Paldino [.NET/C# MVP]" wrote:
Tim,

Actually, fully instantiated Generics can be expose to COM. You just
have to specify a type parameter.

In this case, you would have to create a generic type which extends
the
generic instance, setting the type parameters, and expose that to COM.
Of
course, this means you would have to do it for all generic type parameter
combinations that you want to use.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Tim" <Ti*@discussions.microsoft.com> wrote in message
news:0D**********************************@microsof t.com...
> When there is a need to pass some dynamic information between 2 managed
> assemblies, the "Dictionary object" in Generic form can be used as a
> method
> parameter to pass the information. The information that needs to be
> passed
> can be stored as Key-Value pairs, and the method signature remains the
> same.
> That way, handling future requirements of passing additional details to
> the
> callee can be handled without changing the method signature.
>
> Is there some such similar way to pass dynamic information from
> Unmanaged
> code (VB6) to managed code. Generics are not visible to COM. So what
> can
> be
> done such that the method signature does not change, but future
> requirements
> of having to pass additional data can be handled?


Dec 30 '05 #5
Tim
Hi Nicholas,

I want to expose a method to COM that has the following signature:
TestMethod(Dictionary<int, string> testData)

When the RegAsm utility is used to register a type that has the above
mentioned method, the following error is thrown:
Warning: Type library exporter encountered a generic type instance in a
signature. Generic code may not be exported to COM. RegAsm: error RA0000 : An
error occurred while saving the exported type library: Access is denied.
<Exception from HRESULT: 0x80070005 <E_ACCESSDENIED>>

Is there any equivalent of 'Dictionary' type that I can use in the method
signature and export to COM? If I use Hashtable, I would be paying a heavy
price in terms of performance - due to boxing and unboxing issues. Any other
way out?
"Nicholas Paldino [.NET/C# MVP]" wrote:
Tim,

I don't have a direct link, but its like any other class. Say you had
this:

public class MyClass<T>
{
public void DoSomething(T obj)
{
}
}

You would have to create a specific type and expose that to COM, like
so:

public class MyClassInt : MyClass<int>
{}

Then, MyClassInt could be exposed to COM. Now, if you have some methods
that are public and take type parameters separate from the ones in the type
declaration, you will have to wrap the whole object, and expose the methods
with the appropriate type.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Tim" <Ti*@discussions.microsoft.com> wrote in message
news:00**********************************@microsof t.com...
Thanks Nicholas for the immediate response. Can you point me to some link
where I can get further information on this subject.

"Nicholas Paldino [.NET/C# MVP]" wrote:
Tim,

Actually, fully instantiated Generics can be expose to COM. You just
have to specify a type parameter.

In this case, you would have to create a generic type which extends
the
generic instance, setting the type parameters, and expose that to COM.
Of
course, this means you would have to do it for all generic type parameter
combinations that you want to use.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Tim" <Ti*@discussions.microsoft.com> wrote in message
news:0D**********************************@microsof t.com...
> When there is a need to pass some dynamic information between 2 managed
> assemblies, the "Dictionary object" in Generic form can be used as a
> method
> parameter to pass the information. The information that needs to be
> passed
> can be stored as Key-Value pairs, and the method signature remains the
> same.
> That way, handling future requirements of passing additional details to
> the
> callee can be handled without changing the method signature.
>
> Is there some such similar way to pass dynamic information from
> Unmanaged
> code (VB6) to managed code. Generics are not visible to COM. So what
> can
> be
> done such that the method signature does not change, but future
> requirements
> of having to pass additional data can be handled?


Dec 30 '05 #6

"Tim" <Ti*@discussions.microsoft.com> wrote in message
news:B3**********************************@microsof t.com...
Hi Nicholas,

I want to expose a method to COM that has the following signature:
TestMethod(Dictionary<int, string> testData)

When the RegAsm utility is used to register a type that has the above
mentioned method, the following error is thrown:
Warning: Type library exporter encountered a generic type instance in a
signature. Generic code may not be exported to COM. RegAsm: error RA0000 :
An
error occurred while saving the exported type library: Access is denied.
<Exception from HRESULT: 0x80070005 <E_ACCESSDENIED>>

Is there any equivalent of 'Dictionary' type that I can use in the method
signature and export to COM? If I use Hashtable, I would be paying a heavy
price in terms of performance - due to boxing and unboxing issues. Any
other
way out?


You can't expose none "automation compatible" types to COM, generics are not
automation compatible neither are they CLS compliant, so you should not use
them on public interfaces!
As for your remark about an hastable, same remark here a hastable cannot be
marshaled by the default interop marshaler. When passing data to COM the
data has to marshaled from managed to unmanaged memory, the price of
marshaling is much higher than boxing/unboxing, this is the price you have
to pay when crossing the managed/unmanaged boundary. So what you need to do
is convert your container (whatever) to a COM automation compatible type,
say an array (SAFEARRAY in COM), or you can use Custom marshaling to marshal
to a non automation compliant type which can further be used in your COM
server.

Willy.
Dec 30 '05 #7
Tim
Thanks Willy, for pointing out the Safearray option.

"Willy Denoyette [MVP]" wrote:

"Tim" <Ti*@discussions.microsoft.com> wrote in message
news:B3**********************************@microsof t.com...
Hi Nicholas,

I want to expose a method to COM that has the following signature:
TestMethod(Dictionary<int, string> testData)

When the RegAsm utility is used to register a type that has the above
mentioned method, the following error is thrown:
Warning: Type library exporter encountered a generic type instance in a
signature. Generic code may not be exported to COM. RegAsm: error RA0000 :
An
error occurred while saving the exported type library: Access is denied.
<Exception from HRESULT: 0x80070005 <E_ACCESSDENIED>>

Is there any equivalent of 'Dictionary' type that I can use in the method
signature and export to COM? If I use Hashtable, I would be paying a heavy
price in terms of performance - due to boxing and unboxing issues. Any
other
way out?


You can't expose none "automation compatible" types to COM, generics are not
automation compatible neither are they CLS compliant, so you should not use
them on public interfaces!
As for your remark about an hastable, same remark here a hastable cannot be
marshaled by the default interop marshaler. When passing data to COM the
data has to marshaled from managed to unmanaged memory, the price of
marshaling is much higher than boxing/unboxing, this is the price you have
to pay when crossing the managed/unmanaged boundary. So what you need to do
is convert your container (whatever) to a COM automation compatible type,
say an array (SAFEARRAY in COM), or you can use Custom marshaling to marshal
to a non automation compliant type which can further be used in your COM
server.

Willy.

Jan 2 '06 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Sasha Nikolic | last post: by
17 posts views Thread by mr.resistor | last post: by
8 posts views Thread by Notre Poubelle | last post: by
17 posts views Thread by =?Utf-8?B?U2hhcm9u?= | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.