VC ++ 调用 C# dll

  1. 在VS 2015 中加载时,选择公共语言运行时编译,
  2. 然后程序中使用。动态库函数是GetProductList()
cpp 复制代码
string CConnectApi::GetProductList(char * a_szdata, int page, int pageSise)
{
	try
	{
		int ipage = page;
		int iSise = pageSise;
		String ^s_key = System::Runtime::InteropServices::Marshal::PtrToStringAnsi((IntPtr)a_szdata);
		Tool ^ s_helper = gcnew Tool();
		////GetProductList(string uri,int page,int pageSise)
		::System::String ^ s_encrypt = s_helper->GetProductList(s_key, ipage, iSise);
		char* szretdata = (char*)(void*)System::Runtime::InteropServices::Marshal::StringToHGlobalAnsi(s_encrypt);

		return szretdata;
	}
	catch (const std::exception&)
	{
		SaveInfoToFile("调用动态库,获取文件列表失败");
		return "";
	}

}