質問

I do not know anything about C++, but I figured out enough to get a .dll written for a specific purpose, because there was some code I could not get C# to do.

So I created this DLL using Visual Studio 2013 -> Win32 Project -> Dynamic Link Library as the type, selected "Empty Project", etc.

Now I go over to my C# program and I have pinvoke sections to call this dll by name (Legacy.dll). I compile the DLL from C++, and copy/paste it from the /release folder to the /bin/release and /bin/debug folder of my C# application, and run the C# application.

It works fine. I have no issues.

However, when I send the files - the .dll and the .exe to other people, it tells them it cannot find the very same DLL. But it is clearly there, it is clearly working for me....

So what could be the problem? I am compiling both the C# program and the DLL to 32-bit.

UPDATE

The problem was that my users had the C++ libraries, but it had been sneakily updated to need the 2013 ones, which did not appear in my first search. I had to do an EXPLICITLY specific search to find this.

正しい解決策はありません

他のヒント

What's your operating system? Are you running a 32 bit or a 64 bit version of Windows? For .NET programs to load 32 bit native DLLs you'll have to ensure that you set the architecture of your .NET project to "32 bit" as well. By default it's on "Any CPU", which will pick the architecture based on the computer running the program. If you run the program on a 64 bit system, it will expect the native DLL to be 64 bit as well (which will cause the problem).

I know this sounds silly, but are you checking for the DLL in your C# program? (Sometimes users can be... 'interesting')

For example:

void Initialize()
{
   var path = Path.Combine(Environment.CurrentDirectory, "Legacy.dll");

   if(!File.Exists(path))
   {
     // Alert the user that the accompanying DLL is missing...
   }
}

Other than that I would check architecture. Are you on 32-bit while they are on 64-bit OSes?

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top