|
I am writing a managed WPF Application. It is compiled against 'AnyCPU' as is common with C#.
I would like to add/develop a C++/CLI component to my app.
However C++/CLI is bound to an architecture (x86/x64/arm).
Is there a... relatively easy way for me to ship all 3 architecture and have the system load the right DLL at runtime?
|
|
|
|
|
You can try using the AddDllDirectory[^] method as the start of your application and add a directory containing the library for the current architecture. Just read the notes lower on the page on how to add the path to the default paths.
What do you get when you cross a joke with a rhetorical question?
The metaphorical solid rear-end expulsions have impacted the metaphorical motorized bladed rotating air movement mechanism.
Do questions with multiple question marks annoy you???
|
|
|
|
|
 Here is a class that can help with the idea in my previous post:
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.ComponentModel;
namespace GryphonSoft.Utility.Runtime.InteropServices
{
public static class DllSearchPath
{
#region Fields
private static Dictionary<string, IntPtr> _dllPathCookieDict;
private static SetDefaultDllDirectories_Delegate _SetDefaultDllDirectories;
private static AddDllDirectory_Delegate _AddDllDirectory;
private static RemoveDllDirectory_Delegate _RemoveDllDirectory;
#endregion
#region Constructor
static DllSearchPath()
{
_dllPathCookieDict = new Dictionary<string, IntPtr>(StringComparer.OrdinalIgnoreCase);
IntPtr kernel32 = LoadLibrary("Kernel32.dll");
_SetDefaultDllDirectories = Marshal.GetDelegateForFunctionPointer<SetDefaultDllDirectories_Delegate>(GetProcAddress(kernel32, "SetDefaultDllDirectories"));
_AddDllDirectory = Marshal.GetDelegateForFunctionPointer<AddDllDirectory_Delegate>(GetProcAddress(kernel32, "AddDllDirectory"));
_RemoveDllDirectory = Marshal.GetDelegateForFunctionPointer<RemoveDllDirectory_Delegate>(NativeMethods.GetProcAddress(kernel32, "RemoveDllDirectory"));
_SetDefaultDllDirectories(0x00001000);
}
#endregion
#region Delegates
private delegate bool SetDefaultDllDirectories_Delegate(int DirectoryFlags);
private delegate IntPtr AddDllDirectory_Delegate(string NewDirectory);
private delegate bool RemoveDllDirectory_Delegate(IntPtr Cookie);
#endregion
#region P/Invoke
[DllImport("Kernel32.dll")]
internal static extern IntPtr LoadLibrary(string lpFileName);
[DllImport("Kernel32.dll")]
internal static extern IntPtr GetProcAddress(IntPtr hModule, string lpProcName);
#endregion
#region Public API
public static void AddDllDirectory(string dir)
{
IntPtr cookie = _AddDllDirectory(dir);
if (cookie == IntPtr.Zero) throw new Win32Exception();
_dllPathCookieDict.Add(dir, cookie);
}
public static bool RemoveDllDirectory(string dir)
{
IntPtr cookie;
if(!_dllPathCookieDict.TryGetValue(dir, out cookie))
{
return false;
}
if (!_RemoveDllDirectory(cookie)) throw new Win32Exception();
_dllPathCookieDict.Remove(dir);
return true;
}
#endregion
}
}
Alter the namespace as needed.
I just threw this together in a utility library I am writing, as I think it might be useful in other places as well.
Feel free to use it any way you want. I am going to tri-license the library under the GPLv3, LGPLv3 and MIT licenses, so it is free for commercial use.
What do you get when you cross a joke with a rhetorical question?
The metaphorical solid rear-end expulsions have impacted the metaphorical motorized bladed rotating air movement mechanism.
Do questions with multiple question marks annoy you???
|
|
|
|
|
Nice Brisingr ! with not too much work you could publish it as an article here (I know Im bookmarking it or squirreling this code away)
|
|
|
|
|
I am planning on writing an article on the library when I get it closer to completion. That may be a while, though.
What do you get when you cross a joke with a rhetorical question?
The metaphorical solid rear-end expulsions have impacted the metaphorical motorized bladed rotating air movement mechanism.
Do questions with multiple question marks annoy you???
|
|
|
|
|
interesting....
though I thought of handling the AppDomain.CurrentDomain.AssemblyResolve event and load my assembly with a path of my choosing.
Finding out whether the app is running as x86, x64, arm with GetType().Module.GetPEKind(out pek, out ifm);
|
|
|
|
|
Hi guys ! I need suggestion for making a semester project. Can anyone give a source code of some exception c program that can run in visual studio 2013 ultimate.
Please help me out with it,quickly.
|
|
|
|
|
Sorry, this site does not provide code to order, especially for homework projects.
|
|
|
|
|
you can not even give an idea ?????
|
|
|
|
|
OK, create a program to store account and password details in encrypted form.
|
|
|
|
|
will you guide me a bit about it ? please
|
|
|
|
|
If you do not even know where to start with your project then I suggest you go and talk to your teacher about it.
|
|
|
|
|
well if its just a semester project you can make some management application like for a shopping centre ,or a library .There are many options
|
|
|
|
|
Hi Everyone I am trying to compile my assignment but I am having some problem with compiling I believe that something about line 24-27
This is the error message
---------------------------
Microsoft Visual C++ Runtime Library
---------------------------
Debug Error!
Program: ...2015\Projects\OCC\IC20_AdamsLotApp\Debug\IC20_AdamsLotApp.exe
abort() has been called
(Press Retry to debug the application)
---------------------------
Abort Retry Ignore
---------------------------
modified 10-Nov-15 17:41pm.
|
|
|
|
|
You need to use the debugger to gather more information, especially about the content of the variables that may cause the error. Also please mark the lines where the error occurs.
|
|
|
|
|
Please check out the image below
http://i.imgur.com/NeaItgZ.jpg
|
|
|
|
|
Very interesting; what does it mean?
|
|
|
|
|
|
If you really want help with this issue then please do what I suggested in my first response.
|
|
|
|
|
I have attached the image please check out and let me know what you need
|
|
|
|
|
I mean you need to run your program under the debugger to trap exactly where the error occurs, what the error is, and what variables, pointers etc. are possibly causing the fault. Without that information it is impossible to guess what may be going wrong.
|
|
|
|
|
http://i.imgur.com/mkoBXWc.jpg
please check out the image
|
|
|
|
|
That is as a good as sending a picture of your care and saying "it won't start".
|
|
|
|
|
http://i.imgur.com/vO4uFTL.jpg
Look at this error message DO I have any mistake by using enum ? i guess ?
|
|
|
|
|
Don't you have and compiler ? Why don't you just compile and debug the code ?
|
|
|
|