-1
在我的C#项目中,我必须包含一个C++库。无法在C中调用C++方法#
我有我的C两种方法++库如下:
APICLIENT_API std::map<std::string, std::string> logInWithParams(const char* url, const char* loginID, const char* password, const char* salt, const char* timeStamp, const char* refererURL, int iterations);
static APICLIENT_API int logIn(int iterations);
我能够与访问以下实施登录方法在C#:
[DllImport(@"F:\MySp\MySp\bin\APIClient.dll", EntryPoint = "[email protected]@[email protected]@[email protected]", CallingConvention = CallingConvention.Cdecl)]
public static extern int logIn(int g);
但无法调用logInWithParams方法的任何意思。以下是我所尝试过的。
[DllImport(@"F:\MySp\MySp\bin\APIClient.dll", EntryPoint = "[email protected]@[email protected]@[email protected]@Z", CallingConvention = CallingConvention.Cdecl)]
public static extern System.Collections.Generic.Dictionary<string, string> logInWithParams([MarshalAs(UnmanagedType.LPStr)]string a, [MarshalAs(UnmanagedType.LPStr)]string b, [MarshalAs(UnmanagedType.LPStr)]string c, [MarshalAs(UnmanagedType.LPStr)]string d, [MarshalAs(UnmanagedType.LPStr)]string e, [MarshalAs(UnmanagedType.LPStr)]string f, int g);
C#Implementaion:
System.Collections.Generic.Dictionary<string, string> strMe = new Dictionary<string, string>();
strMe = APICaller.logInWithParams("https://api.net/api/0.1/session/login", "[email protected]", "123123", "", "1403762225", "https://api.mini.net/", 4096);
错误:无法元帅返回值“:泛型类型不能被封。
我还没有编写C++代码,我只需将其包含在我的C#项目中。 我是C++中整合C++库的新手。请帮助解决此问题。
您如何期望C++知道'Dictionary'是什么?你可能必须为此使用'C++/CLI'。 –
leppie
使用C++/CLI将'std :: map'映射到您需要的'Generic.Dictionary'数据类型。 C#不理解C++库对象。或者,你可以将'map'分解为某种类型的“原始”内存,然后导入该函数。 – Niall