Click here to Skip to main content
15,898,588 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to get map from dll c++

C++ code
C++
extern "C" __declspec(dllexport) map<string, int> createMap(string &fileName) {
	ifstream infile(fileName);
	vector<string> bitsLine;
	bool headerEnded = false;
	string line;
	int i = 0;
	int length = 0;

	while (getline(infile, line)) {
		if (headerEnded) {
			bitsLine = split(line, ',');
			signalsMap.insert({ bitsLine.at(0), length });
		}
		else {
			if (line.find("HEADER_END") != std::string::npos) {
				headerEnded = true;
			}
		}
		length = infile.tellg();
		i++;
	}
	return signalsMap;
}


What I have tried:

C# code
Dictionary<string, int>  x =  createMap("C:/users/asalah/source/repos/WindowsFormsApp3/WindowsFormsApp3/RR_Test2_3.csv");
Posted
Updated 12-Nov-18 3:37am

Hi,
I think basically what you need to do is to use STL/CLR to map your native c++ container into .Net contains. You can find a good example and useful information at the below link:

How to: Convert from a STL/CLR Container to a .NET Collection | Microsoft Docs[^]

For your attention:
adapter (STL/CLR) | Microsoft Docs[^]

Please do not hesitate to leave a comment if it didn`t work then I will try to improve my solution.

Cheers,
AH
 
Share this answer
 
v2
Your best bet is using C++/CLI (and possibly directly fill the Dictionary, without using the std::map at all). See, for instance c++ - Cpp/Cli Convert std::map to .net dictionary - Stack Overflow[^].
 
Share this answer
 
Comments
Ameer Salah 30-Oct-18 8:14am    
Thanks a lot man,
Why when I trying to make it Dictionary<string, int>
I got string is not valid generic arguments
CPallini 30-Oct-18 8:28am    
I guess you have to use Dictionary<String ^, int> (I am NOT a CLI/C++ expert).

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900