0
我有一個用於第三方應用程序的DLL,通常通過命名管道與它通信。但是NP只在其他應用程序啓動時才起作用。我可以直接從dll調用一個方法來查看它的版本。從.NET調用C++方法
C++ VS2012
#ifdef MTFST_EXPORTS
#define MTFST_API __declspec(dllexport)
#else
#define MTFST_API __declspec(dllimport)
#endif
#define LIBRARY_VERSION "3.0"
....
using namespace std;
MTFST_API char *__stdcall FST_LibraryVersion()
{
return LIBRARY_VERSION;
}
我嘗試下面的代碼,但它不工作。 .NET 4.
internal class Program
{
[DllImport("Library.dll")]
private static extern char[] FST_LibraryVersion();
private static void Main(string[] args)
{
Console.WriteLine(new string(FST_LibraryVersion()));
}
}
嘗試使用編譯模式 '在任何CPU',代替X86或64,或與X86彙編 – Gisway
.NET代碼值爲anycpu。 C++ lib是x86。 –
您的C++函數返回'IntPtr',而不是'char []'。請參閱:http://stackoverflow.com/questions/370079/pinvoke-for-c-function-that-returns-char – 2013-07-24 16:30:56