I want to use a C++CLI (Managed C++) .dll to interface between Powershell v3 x86 and a (Unmanaged) C++ application.
I've tried to load a very simple "Hello World" program written in C++CLI using both Add-Type
and [System.Reflection.Assembly]::LoadWithPartialName()
in powershell but I get the error: "Could not load file or assembly"
I then wrote a C# wrapper for the C++CLI class, successfully loaded it into Powershell using the same method, but when I make a call that references the C++CLI code I get the same error. The C# code itself seems to not take any issue with calls to the C++CLI .dll, but Powershell does.
Accessor.h:
using namespace System;
namespace Accessor {
static public ref class Greeting
{
public:
static void HelloWorld();
};
}
Accessor.cpp:
#include "Accessor.h"
void Accessor::Greeting::HelloWorld()
{
Console::WriteLine("Hello World!\n");
}
Wrapper.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Accessor;
namespace AccessWrap
{
static public class Wrapper
{
static public void HelloWorld()
{
Greeting.HelloWorld();
}
}
}
What is the correct way to accomplish this? I've tried many other methods I've found online but none have worked for me.
Edit: This is the exact error I get when trying to load the C++CLI .dll directly: http://imgur.com/HF5VRkf
FileLoadException
, which usually has details on why the assembly can't be loaded. – Jeroen MostertCOR_E_BADIMAGEFORMAT
, which usually (but not always) indicates that a 32-bit process is attempting to load a 64-bit DLL or vice versa. You'll have to investigate that possibility first. – Jeroen Mostert