473,387 Members | 1,569 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,387 software developers and data experts.

Passing a SortedList from C# to MC++

hi,

i am writing a dll in MC++ for using from C#. For the dll function say
'TestFunc', i need to get a SortedList<string,stringas an argument.
I am not very clear about using SortedList in MC++. Please guide me on
this.

thanks in advance,
Abin

Aug 21 '06 #1
12 2508

<ab*****@gmail.comwrote in message
news:11*********************@74g2000cwt.googlegrou ps.com...
| hi,
|
| i am writing a dll in MC++ for using from C#. For the dll function say
| 'TestFunc', i need to get a SortedList<string,stringas an argument.
| I am not very clear about using SortedList in MC++. Please guide me on
| this.
|
| thanks in advance,
| Abin
|

You can't pass a generic type to a MC++ function, generics require C++/CLI.

Willy.
Aug 21 '06 #2
Aby

Can i port an mc++ app to c++/cli, so that generics can b used.
sorry if i sound stupid !

thanks once again,
Abin

Aug 22 '06 #3
Aby wrote:
Can i port an mc++ app to c++/cli, so that generics can b used.
sorry if i sound stupid !

thanks once again,
Abin
Hi Abin,

Yes you can, but at some time you have to make the transition to a
"unmanaged data structure".

What kind of container does your c++ dll expect? If it is something
native (e.g. an array of PODs), I would copy your sorted list into a c#
array and call your dll through interop.

If it is something else, e.g. std::map or a MFC container, I see 3
possibilities:
1) Extend the interface of the c++ dll with a function that takes an
array of PODs. Then you can call it through interop.

2) Extend the interface of the c++ dll with a managed function that
takes a SortedList<string,string>. Then call it like any other managed
assembly. However, I guess that you will have to deploy the framework
along with your c++ dll

3) Write a thin COM wrapper for the needed functionality which you can
access very easy from c#

HTH,
Andy

Aug 22 '06 #4

"Andreas Mueller" <me@privacy.netwrote in message
news:4l************@individual.net...
| Aby wrote:
| Can i port an mc++ app to c++/cli, so that generics can b used.
| sorry if i sound stupid !
| >
| thanks once again,
| Abin
| >
|
| Hi Abin,
|
| Yes you can, but at some time you have to make the transition to a
| "unmanaged data structure".
|
| What kind of container does your c++ dll expect? If it is something
| native (e.g. an array of PODs), I would copy your sorted list into a c#
| array and call your dll through interop.
|
| If it is something else, e.g. std::map or a MFC container, I see 3
| possibilities:
| 1) Extend the interface of the c++ dll with a function that takes an
| array of PODs. Then you can call it through interop.
|
| 2) Extend the interface of the c++ dll with a managed function that
| takes a SortedList<string,string>. Then call it like any other managed
| assembly. However, I guess that you will have to deploy the framework
| along with your c++ dll
|
| 3) Write a thin COM wrapper for the needed functionality which you can
| access very easy from c#
|
| HTH,
| Andy
|

C++/CLI is managed C++ and is capable to consume and handle generic types,
guess you are confusing C++/CLI with C++/ISO.

Willy.
Aug 22 '06 #5

"Aby" <ab*****@gmail.comwrote in message
news:11**********************@74g2000cwt.googlegro ups.com...
|
| Can i port an mc++ app to c++/cli, so that generics can b used.
| sorry if i sound stupid !
|
| thanks once again,
| Abin
|

Sure, only problem is that no tool is available to port your MC++ source to
C++/CLI, so you'll have to do it manually.
Anyway here is a small sample t give you an idea what it looks like on the
interface level...

// C++/CLI DLL
// Compile with: cl /LD /clr:safe gensub.cpp
#using <system.dll>
using namespace System;
using namespace System::Collections::Generic;

public ref class GenList
{
public:
void TestFunc(SortedList<String^, String^^sl)
{
for each(KeyValuePair<String^, String^kvp in sl)
{
Console::WriteLine(kvp.Value);
}
}

};

C# snip calling a C++ function that accepts a SortedList generic type

SortedList<string, stringsl = new SortedList<string, string>();
sl.Add("Hello", "world");
GenList gl = new GenList();
gl.TestFunc(sl);

Willy.
Aug 22 '06 #6
Willy Denoyette [MVP] wrote:

<snip />
C++/CLI is managed C++ and is capable to consume and handle generic types,
guess you are confusing C++/CLI with C++/ISO.
No I didn't. My point was:
If he wants to make his dll consume generic containers, he either has to
convert the whole DLL to use C++/CLI or provide a gateway from managed
to unmanaged C++ inside the dll. Both convert the dll into a managed dll
and may have impact on other users of it, e.g. different deployment.

Therefore I outlined other posibilities:
-extension of the dll interface using PODs and arrays to enable simple
interop
-COM wrapper that acts as a facade.

Both leave the c++ dll unmanaged and don't have much impact on the
alrady existing code.

Cheers,
Andy

----------
You can email me directly by removing the NOSPAm below
xm**********@gmxNOSPAm.netNOSPAm
Aug 22 '06 #7
Aby
hi,
huh! now i understand what i need. My managed dll was written in
VC++2003 and change it to use C++/CLI will take many days. So i am
going for a managed function that accepts SortedList<string,string>
(soln 2 suggested by Andy). I added the function

void TestFunc( SortedList <String,String*a_list );

--but this gives an error 'System::Collections::SortedList' : cannot
use this type here without a top-level '*'

can u show the correct way ?

thanks,
Abin

Aug 22 '06 #8


"Andreas Mueller" <me@privacy.netwrote in message
news:4l************@individual.net...
| Willy Denoyette [MVP] wrote:
|
| <snip />
|
| C++/CLI is managed C++ and is capable to consume and handle generic
types,
| guess you are confusing C++/CLI with C++/ISO.
|
| No I didn't. My point was:
| If he wants to make his dll consume generic containers, he either has to
| convert the whole DLL to use C++/CLI or provide a gateway from managed
| to unmanaged C++ inside the dll. Both convert the dll into a managed dll
| and may have impact on other users of it, e.g. different deployment.
|
| Therefore I outlined other posibilities:
| -extension of the dll interface using PODs and arrays to enable simple
| interop
| -COM wrapper that acts as a facade.
|
| Both leave the c++ dll unmanaged and don't have much impact on the
| alrady existing code.
|
| Cheers,
| Andy
|

Sorry but the OP never mentioned unmanage C++ as target, he is talking about
a DLL built with MC++ which produces managed code without generics support,
where did you see "unmanaged" in his original posting?

Willy.
@gmxNOSPAm.netNOSPAm
Aug 22 '06 #9
Willy Denoyette [MVP] wrote:
Sorry but the OP never mentioned unmanage C++ as target, he is talking about
a DLL built with MC++ which produces managed code without generics support,
where did you see "unmanaged" in his original posting?
Thats's correct, I read over the "M" and assumed VSC++. May bad!
Cheers,
Andy
--
You can email me directly by removing the NOSPAm below
xm**********@gmxNOSPAm.netNOSPAm
Aug 22 '06 #10
Aby
hi,
huh! now i understand what i need. My managed dll was written in
VC++2003 and change it to use C++/CLI will take many days. So i am
going for a managed function that accepts SortedList<string,string>
(soln 2 suggested by Andy). I added the function

void TestFunc( SortedList <String,String*a_list );

--but this gives an error 'System::Collections::SortedList' :
cannot
use this type here without a top-level '*'

can u show the correct way ?

thanks,
Abin

Aug 22 '06 #11


"Aby" <ab*****@gmail.comwrote in message
news:11**********************@75g2000cwc.googlegro ups.com...
| hi,
| huh! now i understand what i need. My managed dll was written in
| VC++2003 and change it to use C++/CLI will take many days. So i am
| going for a managed function that accepts SortedList<string,string>
| (soln 2 suggested by Andy). I added the function
|
| void TestFunc( SortedList <String,String*a_list );
|
| --but this gives an error 'System::Collections::SortedList' :
| cannot
| use this type here without a top-level '*'
|
| can u show the correct way ?
|
| thanks,
| Abin
|

You can't use SortedList which is a generic type in MC++ (vs2003) as was I
said before, only option you have is to port to C++/CLI, or pass a non
generic container type. Also you should definitely consider porting to
C++/CLI, MC++ is dead-end (IMO since it was released).
Please see my other reply for an example using C++/CLI.
Willy.
Aug 22 '06 #12
Aby
Thank u Willy and Andy for ur help.
i have begun to use C++/CLI.

Regards,
Abin

Aug 23 '06 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: gerrod | last post by:
Hi - Does anyone know a way to created a SortedList (in the System.Collections namespace) that will sort on VALUES instead of KEYS... ? The scenario is this - I have a SortedList containing...
3
by: Michael C | last post by:
Hi all, I'm using a SortedList to store data, and want the keys to be compared in case insensitive order, so that mySList is the same as mySList
2
by: Pekka | last post by:
Could somebody say why the piece of code below does not work? My purpose is to renumber keys in a SortedList (after removal of an item) so that the keys would always contain an unbroken sequence of...
3
by: Marc Castrechini | last post by:
First off this is a great reference for passing data between the Data Access and Business Layers:...
2
by: Prez | last post by:
I started writing .net code yesterday and I am grasping it well enough. I have a few questions about SortedLists. I am using managed C++ if that makes any difference. Of the examples I...
4
by: SHEBERT | last post by:
Here is an example of a SortedList that works as a datasource to the ComboBox and a generic SortedList<that does not works as a datasource to the ComboBox. Why? If I use List and generic List<>,...
1
by: lg2530 | last post by:
template<class T> struct NODE { T data; NODE<T> * next; }; template<typename T> NODE<T>* QuickSortList( NODE<T>* list ) {}
1
by: raylopez99 | last post by:
I seem to get name collision between the Generic collection SortedList and C++.NET Framework collection SortedList. How to resolve? Here are the libraries that seem to clash:...
6
by: n3tx | last post by:
Hi! I have a problem with sortedlist, i guess i dont understand how it works. I have a method called GetPublishingPlaces that returns an IList<PublishingPlace> (ex. contains 11 rows) I want...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
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
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,...

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.