473,389 Members | 1,142 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,389 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 10220
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: lolomgwtf | last post by:
I have a managed C++ method that wraps unmanaged code and creates a managed object holding data retrieved form an unmanged one. I want create an instance of this managed class in C#, pass it to...
2
by: Chris | last post by:
Hi, I seem to be having a problem I can't quite figure out. Currently, I have the following code (below). In the SendMsg function, I create a 'Qtkmsg' which converts the string 'text' into a...
2
by: lolomgwtf | last post by:
I have a managed C++ method that wraps unmanaged code and creates a managed object holding data retrieved form an unmanged one. I want create an instance of this managed class in C#, pass it to...
2
by: Sasha Nikolic | last post by:
I have one unmanaged and one managed class in the same vc++ project. Managed object creates one instance of unmanaged class and needs to pass a callback reference so that unmanaged class can...
17
by: mr.resistor | last post by:
hey i am having a few problems calling a C DLL from C#. i am using a simple function that takes an array of floats and an integer as an input, but i cannot seem to get it to work. when i try to...
0
by: Haxan | last post by:
Hi, I have an unmanaged application that converts a function pointer to a delegate and then pass this as a parameter(delegate) to a managed function which then invokes it. Currently Im able to...
12
by: Haxan | last post by:
Hi, I have my main application class(unmanaged) that has a none static member function that I need to pass as a delegate to managed C# method. In one of the methods of this class(unmamanged),...
8
by: Notre Poubelle | last post by:
Hello, I have some legacy unmanaged C++ code in which I've introduced some managed C++ using the new CLI feature of VS 2005. My managed C++ code invokes a number of methods on a new C#class...
17
by: =?Utf-8?B?U2hhcm9u?= | last post by:
Hi Gurus, I need to transfer a jagged array of byte by reference to unmanaged function, The unmanaged code should changed the values of the array, and when the unmanaged function returns I need...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.