0

I want to use a C++ dll IN a c# code example (using the c++ dll):

    class Program
    {
        [DllImport(@"netcoreapp3.1\savedecrypter.dll", CallingConvention = CallingConvention.Cdecl)]
        public static extern string decryptSave(string o);

        static void Main(string[] args)
        {
            string ja = "dhsabdasji";
            string show = decryptSave(ja);
            Console.WriteLine(show);
            Console.ReadLine();
        }

    }
**and this is the EXAMPLE C++ dll code(im just a newbie in c++ btw)**
 extern "C"
 {
      __declspec(dllexport) string decryptSave(string path21)
      {
          
          return path21;

      }


 }

i got an error when trying to call it "System.DllNotFoundException: 'Unable to load DLL 'netcoreapp3.1\savedecrypter.dll' or one of its dependencies: The specified module could not be found. (0x8007007E)'" can anyone fix this for me? Would appreciate if somebody could do so.

edit : now i have enabled native code debbuging, it show this error :

Unhandled Exception: System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

Elytride
  • 1
  • 1
  • maybe just `@"savedecrypter.dll"` ? – Marc Gravell Jun 24 '20 at 09:19
  • did you try to add savedecrypter.dll's location into system's path then just @"savedecrypter.dll"? – VietDD Jun 24 '20 at 09:29
  • Try with absolute path or with two '\\'. Also I'm not sure if your dll would do what was intended to. Please take a look at https://stackoverflow.com/questions/32991274/return-string-from-c-dll-export-function-called-from-c-sharp – dovahin Jun 24 '20 at 10:01

1 Answers1

0

Is possible that your 'savedecrypter' DLL has a call to another DLL that is missing in your machine. Check if you have all the required drivers, this is a common mistake when you are working with third-party 'black-box' DLL's.

  • now i receive this error Unhandled Exception: System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt. – Elytride Jun 25 '20 at 14:58