Click here to Skip to main content
15,884,099 members
Home / Discussions / Managed C++/CLI
   

Managed C++/CLI

 
AnswerRe: I want find intersection point between two ellipse or ellipse and circle, can someone please give me useful links or any suggestions. Pin
Beginner Luck5-Jan-16 19:19
professionalBeginner Luck5-Jan-16 19:19 
GeneralRe: I want find intersection point between two ellipse or ellipse and circle, can someone please give me useful links or any suggestions. Pin
Member 113286205-Jan-16 19:41
Member 113286205-Jan-16 19:41 
GeneralRe: I want find intersection point between two ellipse or ellipse and circle, can someone please give me useful links or any suggestions. Pin
Beginner Luck6-Jan-16 14:26
professionalBeginner Luck6-Jan-16 14:26 
Questionto use next and previous button of axwindowsmediaplayer with c++ Pin
Member 121466795-Jan-16 6:57
Member 121466795-Jan-16 6:57 
AnswerRe: to use next and previous button of axwindowsmediaplayer with c++ Pin
John Schroedl19-Feb-16 5:25
professionalJohn Schroedl19-Feb-16 5:25 
QuestionShipping multiple architecture Pin
Super Lloyd4-Dec-15 14:52
Super Lloyd4-Dec-15 14:52 
AnswerRe: Shipping multiple architecture Pin
Brisingr Aerowing4-Dec-15 15:58
professionalBrisingr Aerowing4-Dec-15 15:58 
AnswerRe: Shipping multiple architecture Pin
Brisingr Aerowing4-Dec-15 16:53
professionalBrisingr Aerowing4-Dec-15 16:53 
Here is a class that can help with the idea in my previous post:

C#
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.ComponentModel;

namespace GryphonSoft.Utility.Runtime.InteropServices
{
    /// <summary>
    /// Helper class to manipulate the DLL Search Path.
    /// </summary>
    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); /* 0x00001000 == LOAD_LIBRARY_SEARCH_DEFAULT_DIRS */

        }

        #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

        /// <summary>
        /// Adds a directory from the DLL Search Path.
        /// </summary>
        /// <param name="dir">The directory to add.</param>
        /// <exception cref="Win32Exception">If an error occurred while adding the directory.</exception>
        public static void AddDllDirectory(string dir)
        {
            IntPtr cookie = _AddDllDirectory(dir);

            if (cookie == IntPtr.Zero) throw new Win32Exception();

            _dllPathCookieDict.Add(dir, cookie);

        }

        /// <summary>
        /// Removes a previously added directory from the DLL Search Path.
        /// </summary>
        /// <param name="dir">The directory to remove.</param>
        /// <returns><see langword="true"/> if the directory was removed, <see langword="false"/> otherwise.</returns>
        /// <exception cref="Win32Exception">If an error occurred while removing the directory.</exception>
        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???

GeneralRe: Shipping multiple architecture Pin
Garth J Lancaster4-Dec-15 17:00
professionalGarth J Lancaster4-Dec-15 17:00 
GeneralRe: Shipping multiple architecture Pin
Brisingr Aerowing6-Dec-15 5:43
professionalBrisingr Aerowing6-Dec-15 5:43 
GeneralRe: Shipping multiple architecture Pin
Super Lloyd5-Dec-15 3:59
Super Lloyd5-Dec-15 3:59 
QuestionSemester Project Pin
Member 1214667917-Nov-15 4:06
Member 1214667917-Nov-15 4:06 
AnswerRe: Semester Project Pin
Richard MacCutchan17-Nov-15 4:45
mveRichard MacCutchan17-Nov-15 4:45 
GeneralRe: Semester Project Pin
Member 1214667917-Nov-15 4:54
Member 1214667917-Nov-15 4:54 
GeneralRe: Semester Project Pin
Richard MacCutchan17-Nov-15 5:14
mveRichard MacCutchan17-Nov-15 5:14 
GeneralRe: Semester Project Pin
Member 1214667917-Nov-15 5:17
Member 1214667917-Nov-15 5:17 
GeneralRe: Semester Project Pin
Richard MacCutchan17-Nov-15 5:19
mveRichard MacCutchan17-Nov-15 5:19 
AnswerRe: Semester Project Pin
Ãddiçted Šhŕwñ26-Dec-15 4:02
Ãddiçted Šhŕwñ26-Dec-15 4:02 
QuestionC++ Debug Error Pin
Member 120351389-Nov-15 20:06
Member 120351389-Nov-15 20:06 
SuggestionRe: C++ Debug Error Pin
Richard MacCutchan9-Nov-15 21:48
mveRichard MacCutchan9-Nov-15 21:48 
GeneralRe: C++ Debug Error Pin
Member 120351389-Nov-15 21:54
Member 120351389-Nov-15 21:54 
GeneralRe: C++ Debug Error Pin
Richard MacCutchan9-Nov-15 22:04
mveRichard MacCutchan9-Nov-15 22:04 
GeneralRe: C++ Debug Error Pin
Member 120351389-Nov-15 22:13
Member 120351389-Nov-15 22:13 
GeneralRe: C++ Debug Error Pin
Richard MacCutchan9-Nov-15 22:25
mveRichard MacCutchan9-Nov-15 22:25 
GeneralRe: C++ Debug Error Pin
Member 120351389-Nov-15 22:34
Member 120351389-Nov-15 22:34 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.