0

I wrote an external DLL in C and uses PInvoke to import it into a project in C #. Everything works on my computer, however, an error is displayed on each other computer. First, I will paste the codes below.

The code calling the function from an external DLL in C #:

[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");
   }
} 

Code in 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);
    }
}

And error :/:

"System.DllNotFoundException: Can not load DLL 'SimpleScanA0DLL.dll': Can not find the specified module. (Exception from HRESULT: 0x8007007E) in SimpleScanA0.A0DLL.ScanB (String filename, Int32 mode, Int32 dpi, Int32 width, Int32 height) in SimpleScanA0.A0DLL.StartScanA0 () in C: \ Users \ A.Kordecki \ Documents \ simplescan \ A0Scann \ A0DLL.cs: line 21 "

How Can I solve this? Please help.

Rai Vu
  • 1,595
  • 1
  • 20
  • 30
  • Does the dll exist on the other pcs? – TheGeneral Feb 02 '18 at 09:08
  • I'm not so sure what the bevaviour vould be, when the C DLL is compiled using Visual Studio (or other) environment (debug/release) libraries. This can also cause the mentioned problem. See dependency walker what DLL are used by the C DLL. – Julo Feb 02 '18 at 09:12
  • I solved this problem. In my solution was different settings for release and debbug. For debbug was right but it don`t work I don`t know why but for release it finally works. I tested it on 3 computers for now. I guess Visual Studio doesn`t allow to change settings for this two ways of debbuging together. – konto zprzypadku Feb 02 '18 at 10:12

0 Answers0