外部DLL在C中写入并在C#中使用

时间:2018-02-02 09:03:41

标签: c# c dllimport

我在C中编写了一个外部DLL,并使用PInvoke将其导入到C#中的项目中。一切都在我的计算机上工作,但是,每台其他计算机上都会显示错误。首先,我将粘贴下面的代码。

从C#中的外部DLL调用函数的代码:

[DllImport("SimpleScanA0DLL.dll", CharSet = CharSet.Ansi)]
private static extern int ScanB( string filename, int mode, int dpi, int width, int height);

public void StartScanA0()
{
   string test = "test.bmp";
   int k = ScanB( test, 0, 200, 400, 600);
   if(k == -99)
   {
       slog.Info("Bląd przy otwieraniu biblioteki skanera.\n");
   } 
   else if (k == 0)
   {
       slog.Info("Skanowanie zakonczylo sie powodzeniem.\n");
   }
   else
   {
       slog.Info("Wystapil nieznany błąd.\n");
   }
} 

C代码:

extern "C"
{
    _declspec(dllexport) int __stdcall ScanB(char* filename, int mode, int dpi, int width, int height)
    {
        char m = 'C';
        if (mode == 0) {
            m = 'G';
        }
        return Scan(filename, m, dpi, width, height);
    }
}

错误:/:

  

“System.DllNotFoundException:无法加载DLL”SimpleScanA0DLL.dll“:   找不到指定的模块。 (HRESULT的例外情况:   0x8007007E)在SimpleScanA0.A0DLL.ScanB(String filename,Int32模式,   Int32 dpi,Int32宽度,Int32高度)in   C:\ Users \ A.Kordecki中的SimpleScanA0.A0DLL.StartScanA0()   Documents \ simplescan \ A0Scann \ A0DLL.cs:第21行“

我该如何解决这个问题?请帮忙。

0 个答案:

没有答案