External DLL write in C and use in C#

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.

c#
c
dllimport
asked on Stack Overflow Feb 2, 2018 by konto zprzypadku • edited Feb 2, 2018 by Rai Vu

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0