我從這個網站 http://www.codeproject.com/Articles/9826/How-to-create-a-DLL-library-in-C-and-then-use-it-w 它創建了一個C代碼,並在C#應用程序消耗創建一個示例應用程序。的DllImport無法在Windows XP SP3,但是可以在Windows 7
#include <stdio.h>
extern "C"
{
__declspec(dllexport) void DisplayHelloFromDLL()
{
printf("Hello from DLL !\n");
}
}
的C#代碼:
using System;
using System.Runtime.InteropServices; // DLL support
class HelloWorld
{
[DllImport("TestLib.dll")]
public static extern void DisplayHelloFromDLL();
static void Main()
{
Console.WriteLine ("This is C# program");
DisplayHelloFromDLL();
}
}
這種運作良好,在Windows 7上我已經建立的代碼上的Visual Studio 2010的Windows 7機器上。當我嘗試在Windows XP上運行exe文件時,它失敗,導致出現以下異常:無法加載DLL'TestLib.dll':無法找到指定的模塊。 (來自HRESULT的異常:0x8007007E)
您是否在XP機器上部署了VS2010 C運行時? –
命名執行環境通常是一個好主意。但是,在這種情況下,這使您的觀點變得模糊不清:這與「Windows 7與Windows XP」無關,而是「開發機器與常規機器」。 @Frédéric已經暗示了這一點。 – IInspectable
@FrédéricHamidi不,我沒有在win xp上部署visual studio 2010。 – Eve