Quantcast
Channel: .NET Framework Class Libraries forum
Viewing all articles
Browse latest Browse all 8156

C# Windows application to conditionally run a native DLL

$
0
0
Hi Team,

I want my C# Windows application to conditionally run a native method, conditionally choosing to run either the x86 or the x64 version of the dll(Native dll in c++). Whenever I try to load the 64 bit dll I get the below error:

BadImageFormatException "An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)"

But it works fine in case of x86(i.e 32 Bit dll's) in case of selecting any cpu. My Machine is x64(i.e 64 bit).

Code is as follows:

var x86 = "vddk5_x86";
var x64 = "vddk6_x64";
var vddkPath = string.Concat(AppDomain.CurrentDomain.BaseDirectory, x86);
//var vddkPath = string.Concat(AppDomain.CurrentDomain.BaseDirectory, x64);
Environment.SetEnvironmentVariable("PATH", vddkPath);
            
VixError vixError = VixDiskLib.VixDiskLib_InitEx(VixDiskLib.VIXDISKLIB_VERSION_MAJOR, VixDiskLib.VIXDISKLIB_VERSION_MINOR,
                                      null,
                                     null,//(a, b) => _stringBuilder.AppendLine(string.Format("Warning VixDiskLib_InitEx:  {0}", a)),
                                     null,// (a, b) => _stringBuilder.AppendLine(string.Format("Panic VixDiskLib_InitEx:  {0}", a)),
                                     null, null);

When i specify the target either x64 or x86 it is giving Exception "Unable to load DLL 'vixDiskLib.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)".


Viewing all articles
Browse latest Browse all 8156

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>