-2

I have a C ++ source and I want to use it in my C# project. I created a DLL file from it. C++ source has dozens of .h and .cpp files, but I only need 4 methods. So I defined my methods this way.

void _SC1200_H_ voc_init_decode(short vocrate);
void _SC1200_H_ voc_init_encode(short vocrate);
void _SC1200_H_ voc_encode(Shortword sp_in[], unsigned char out[], short npp_flag);
void _SC1200_H_ voc_docode(unsigned char input[], Shortword sp_out[]);

When we disassemble the Dll file we can see the methods.

Dump of file d:\Debug\Melpe.dll

File Type: DLL

  Section contains the following exports for Melpe.dll

    00000000 characteristics
    618A1F5A time date stamp Mon Nov  8 23:12:26 2021
        0.00 version
           1 ordinal base
           4 number of functions
           4 number of names

    ordinal hint RVA      name

          1    0 0001C28F voc_docode = @ILT+650(_voc_docode)
          2    1 0001C28A voc_encode = @ILT+645(_voc_encode)
          3    2 0001C1F9 voc_init_decode = @ILT+500(_voc_init_decode)
          4    3 0001C1FE voc_init_encode = @ILT+505(_voc_init_encode)

  Summary

       1C000 .data
        1000 .idata
        A000 .rdata
        2000 .reloc
        1000 .rsrc
       36000 .text
       1B000 .textbss

In the C # project, we called the methods this way.

[DllImport("D:\\Debug\\Melpe.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern void voc_init_decode(short vocrate);
[DllImport("D:\\Debug\\Melpe.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern void voc_init_encode(short vocrate);
[DllImport("D:\\Debug\\Melpe.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern void voc_encode(byte[] sp_in, byte[] output, bool npp_flag);
[DllImport("D:\\Debug\\Melpe.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern void voc_docode(byte[] input, byte[] sp_out);

And I used the method like this.

short voc_rate = 2400;
voc_init_decode(voc_rate);

But I faced this error.

System.DllNotFoundException: 'Unable to load DLL 'D:\Debug\Melpe.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)'

Thank you if you guide me. I do not know where I went wrong.

MD. RAKIB HASAN
  • 3,670
  • 4
  • 22
  • 35
Pedram
  • 1
  • 1

1 Answers1

0

The most likely problem is trying to call a 32-bit DLL from a 64-bit program (the opposite doesn't work either).

Other possibilities are that you got the DLL path wrong, or the DLL depends on some other DLL that is missing on your system.

Ben Voigt
  • 277,958
  • 43
  • 419
  • 720