Click here to Skip to main content
15,891,567 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a winapp with the wmPlayer in it which is using it's own dll's to actually function.
But, when i move my app in another folder that dont contains the 2 dll asociated with the player in it, my application freeze for 1min and auto closes by default.
I want a way to pop out a MessageBox with my custom error, to remind myself (user) about this little step; to add the dll's with the application inside same folder.

edited#1
My Compiled exe is having this issue. Not the VS project.
When i put it With the 2 dll's in the same folder, then all is fine, indiferent of the folder location on my hdd. The problem arise when i forget to move the dll's into application's folder.
My code is working fine. The problem is that the 'player' object is requesting those dll's when the form is initializing. I dont think it is even passing after InitializeComponent();

Check what ive tried:
I've tried with 2 threads.
I've tried with {try catch}.
No (good) results.

Thank you.


public Form1()
{
    InitializeComponent();
    di = new DirectoryInfo(path);

    Thread thread1 = new Thread(new ThreadStart(A));
    Thread thread2 = new Thread(new ThreadStart(B));
    thread1.Start();
    thread2.Start();
    thread1.Join();
    thread2.Join();
}

void A()
{
    bool Interop = false;
    bool AxInterop = false;
    foreach (var file in di.GetFiles())
    {
        //Interop.WMPLib.dll
        //AxInterop.WMPLib.dll
        if (file.Name == "Interop.WMPLib.dll")
        {
            Interop = true;
        }
        if (file.Name == "AxInterop.WMPLib.dll")
        {
            AxInterop = true;
        }
    }
    if (Interop & AxInterop) { }
    else
    {
        MessageBox.Show("Error: Interop.WMPLib.dll or AxInterop.WMPLib.dll is missing to run this player.\r\n Please put the 2 dll with this application in the same folder.");
    }
}


What I have tried:

I've tried with 2 threads.
I've tried with {try catch}.
No (good) results.
Posted
Updated 13-Jan-19 5:56am
v5
Comments
Richard MacCutchan 13-Jan-19 5:03am    
Why are you using threads and GetFiles? You could just try and load the actual DLLs to see if they are present.
_Q12_ 13-Jan-19 11:32am    
I am sorry if i was't clear enough.
My Compiled exe is having this issue. Not the VS project.
I will modify right now my original question, actually.
And if you are referring to the compiled exe as i originally intended, then yes, when i put it With the 2 dll's in the same folder, then all is fine, indiferent of the folder location on my hdd.
Richard MacCutchan 13-Jan-19 12:31pm    
Well, that is how it is supposed to work. When you try to access a DLL, Windows will search for it in the system library folders, folders specified in the PATH variable, and lastly the folder containing the executable. If the DLL is not found then the program will fail.
Richard MacCutchan 13-Jan-19 12:35pm    
What is the value of "path" that you use to get the directory info? Also stop using threads to do this, they serve no purpose.
_Q12_ 13-Jan-19 12:54pm    
string path = Application.StartupPath;
and then i use it: DirectoryInfo di = new DirectoryInfo(path);
My code is working fine. The problem is that the 'VideoPlayer' object is requesting those dll's when the form is initializing. I dont think it is even passing after InitializeComponent();
Like you said, "Windows will search for it(dll) in the system library folders" (which are located...where?)(probably i should move these dll's there to never have this problem in the future?) I wish i can move them in a custom folder, like a main from which every copy of my application, will 'know' where to look.
Another thing about my application is that i copy it where i need it to be - mostly in movies folders, to make a list of movies there, cycle them, sort,preview, etc.

1 solution

This more easy code should do the Job:
// exePath is defined by you...

//...  or determined  this waay
string exePath =System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location);

// Do the dll's exists in exe path
bool Interop =  File.Exists(Path.Combine(exePath, "Interop.WMPLib.dll"));
bool AxInterop=  File.Exists(Path.Combine(exePath, "AxInterop.WMPLib.dll"));
 
Share this answer
 
v3
Comments
_Q12_ 13-Jan-19 11:55am    
ive edited my original question and added this:
My Compiled exe is having this issue. Not the VS project.
When i put it With the 2 dll's in the same folder, then all is fine, indiferent of the folder location on my hdd. The problem arise when i forget to move the dll's into application's folder.
My code is working fine. The problem is that the player object is requesting those dll's when the form is initializing. I dont think it is even passing after InitializeComponent();

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900