我在學習綁定非託管C++和.NET的基礎知識。所以,我已經從C#編譯並調用了DLL。大。現在我遇到這個奇怪的問題:奇怪的DLL + InterPerServices問題
這裏是我的C++文件,Main.cpp
:
#include <stdio.h>
extern "C" __declspec(dllexport) void DisplayHelloFromDLL()
{
printf ("Hello from the World of 1986!\n");
}
和C#文件,Program.cs
:
using System; using System.Runtime.InteropServices;
namespace FancyApp {
class Program
{
[DllImport("ConsoleApp.dll")]
public static extern void DisplayHelloFromDLL();
static void Main()
{
Console.WriteLine("Hello form the World of 2008!");
DisplayHelloFromDLL();
Console.WriteLine("Press any key to exit");
Console.ReadKey();
}
}
}
夠簡單。構建時,我從C++端獲得ConsoleApp.dll
,從C#獲得FancyApp.exe
。
運行時,它輸出
你好形成2008年的世界!
你好,1986年的世界!
按任意鍵退出
,因爲它應該,除了從VS2008(按F5鍵)發佈模式,我得到
你好形成2008年的世界!
按任意鍵退出
現在,如果我去探險家和而不VS運行的FancyApp.exe
發行版本,它運行良好。
想法?
我已經上傳解決方案的文件夾here(180KB)。
由於printf真的是來自C的日子,那應該是1970年的世界。:) – 2008-12-24 18:10:26