DllNotFoundException for native plugin

I have a win32 native plugin DLL using pinvoke technology and created by visual studio 2015 in windows. I tested it with visual studio 2015 C# code and it worked fine. The dll only depends on dlls in C:\Windows\System32 which is reported by dependency walker. Unity build settings is windows X86 and version is 5.3.4f1(64bit).

I kept getting DllNotFoundException whether I provided full path of the dll or copied it to C:\Program Files\Unity\Editor.

I read several threads about DllNotFoundException and didn’t find a solution. I appreciate all helps.

Here is my test code.

C++ code
#pragma once

#ifdef TESTDLL_EXPORTS
#define CONNECTION_API __declspec(dllexport)
#else
#define CONNECTION_API __declspec(dllimport)
#endif

#ifdef __cplusplus
extern “C”
{
#endif

CONNECTION_API float FooPluginFunction() { return 5.0F; }

#ifdef __cplusplus
}
#endif

C# code
private const string dllpath = “TestDll.dll”;
[DllImport(dllpath)]
private static extern float FooPluginFunction();

public bool Test() {
FooPluginFunction ();
return true;
}

#pragma once

#ifdef TESTDLL_EXPORTS
#define CONNECTION_API __declspec(dllexport)
#else
#define CONNECTION_API __declspec(dllimport)
#endif

#ifdef __cplusplus
extern "C"
{
#endif

CONNECTION_API float FooPluginFunction() { return 5.0F; }

#ifdef __cplusplus
}
#endif

C# code
private const string dllpath = "TestDll.dll";
[DllImport(dllpath)]
private static extern float FooPluginFunction();

public bool Test() {
FooPluginFunction ();
return true;
}

Fixed

This issue is that 64bits editor cannot use 32bits native dll. Here is some discussion: