Skip to content

Commit

Permalink
Loading native dll's correctly for UWP release mode (microsoft#1234)
Browse files Browse the repository at this point in the history
* Loading native dll's correctly for UWP release mode

* nit's

* decouple process bitness with OS Architecture
  • Loading branch information
mayankbansal018 authored and smadala committed Oct 31, 2017
1 parent 7e091aa commit 84b2196
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 11 deletions.
14 changes: 3 additions & 11 deletions src/Microsoft.TestPlatform.ObjectModel/Navigation/NativeMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -556,19 +556,11 @@ internal static class DiaSourceObject

public static IDiaDataSource GetDiaSourceObject()
{
var currentDirectory = new ProcessHelper().GetCurrentProcessLocation();
var nativeDllDirectory = new ProcessHelper().GetNativeDllDirectory();

IntPtr modHandle = IntPtr.Zero;
if (IntPtr.Size == 8)
{
modHandle = LoadLibraryEx(Path.Combine(currentDirectory, "x64\\msdia140.dll"), IntPtr.Zero, 0);
}
else
{
modHandle = LoadLibraryEx(Path.Combine(currentDirectory, "x86\\msdia140.dll"), IntPtr.Zero, 0);
}
IntPtr modHandle = LoadLibraryEx(Path.Combine(nativeDllDirectory, "msdia140.dll"), IntPtr.Zero, 0);

if(modHandle == IntPtr.Zero)
if (modHandle == IntPtr.Zero)
{
throw new COMException(string.Format(Resources.Resources.FailedToLoadMsDia));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,18 @@ public interface IProcessHelper
/// <returns>Location of test engine.</returns>
string GetTestEngineDirectory();

/// <summary>
/// Gets the location of native dll's, depending on current process architecture..
/// </summary>
/// <returns>Location of native dll's</returns>
string GetNativeDllDirectory();

/// <summary>
/// Gets current process architecture
/// </summary>
/// <returns>Process Architecture</returns>
PlatformArchitecture GetCurrentProcessArchitecture();

/// <summary>
/// Gets the process id of test engine.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ namespace Microsoft.VisualStudio.TestPlatform.PlatformAbstractions
/// </summary>
public partial class ProcessHelper : IProcessHelper
{
private static readonly string ARM = "arm";

/// <inheritdoc/>
public object LaunchProcess(string processPath, string arguments, string workingDirectory, IDictionary<string, string> envVariables, Action<object, string> errorCallback, Action<object> exitCallBack)
{
Expand Down Expand Up @@ -162,5 +164,23 @@ public int GetProcessId(object process)
var proc = process as Process;
return proc?.Id ?? -1;
}

/// <inheritdoc/>
public PlatformArchitecture GetCurrentProcessArchitecture()
{
if (IntPtr.Size == 8)
{
return PlatformArchitecture.X64;
}

return PlatformArchitecture.X86;
}

/// <inheritdoc/>
public string GetNativeDllDirectory()
{
var isArm = Environment.GetEnvironmentVariable("PROCESSOR_ARCHITECTURE").Contains("ARM");
return Path.Combine(this.GetCurrentProcessLocation(), this.GetCurrentProcessArchitecture().ToString(), isArm ? ARM : string.Empty);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,17 @@ public int GetProcessId(object process)
{
throw new NotImplementedException();
}

/// <inheritdoc/>
public string GetNativeDllDirectory()
{
throw new NotImplementedException();
}

/// <inheritdoc/>
public PlatformArchitecture GetCurrentProcessArchitecture()
{
throw new NotImplementedException();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,23 @@ public int GetProcessId(object process)
{
return -1;
}

/// <inheritdoc/>
public PlatformArchitecture GetCurrentProcessArchitecture()
{
if (IntPtr.Size == 8)
{
return PlatformArchitecture.X64;
}

return PlatformArchitecture.X86;
}

/// <inheritdoc/>
public string GetNativeDllDirectory()
{
// For UWP the native dll's are to be kept in same directory
return this.GetCurrentProcessLocation();
}
}
}

0 comments on commit 84b2196

Please sign in to comment.