G
Guest
I have an application that uses PInvoke to call into native DLLs. My
DLLimport attribute only has the name of the DLL that I need to import (i.e.
I leave it up to the OS to search the PATH for the DLL.) This all works
great when the user's PATH variable is setup correctly.
Unfortunately, there are times when the user's PATH is too full or whatever
to have the correct search path for my application.
What I was wondering is if there is a way to set the PATH variable to have
the correct search directory after my application starts up (yet before any
call to DLLImport). This way I can guarantee that the search is correct for
the running instace of my application.
I tried this at the beginning of my application to no avail:
System.Diagnostics.ProcessStartInfo info =
System.Diagnostics.Process.GetCurrentProcess().StartInfo;
string origpath = info.EnvironmentVariables["path"];
string newpath = "C:\\mypath;" + origpath;
info.EnvironmentVariables["path"] = newpath;
****
I know I could create a separate executable that sets the Environment
variables and calls StartProcess to launch my application. I was hoping that
my application could set this path infromation without requiring another
executable to launch my application.
Thanks!
DLLimport attribute only has the name of the DLL that I need to import (i.e.
I leave it up to the OS to search the PATH for the DLL.) This all works
great when the user's PATH variable is setup correctly.
Unfortunately, there are times when the user's PATH is too full or whatever
to have the correct search path for my application.
What I was wondering is if there is a way to set the PATH variable to have
the correct search directory after my application starts up (yet before any
call to DLLImport). This way I can guarantee that the search is correct for
the running instace of my application.
I tried this at the beginning of my application to no avail:
System.Diagnostics.ProcessStartInfo info =
System.Diagnostics.Process.GetCurrentProcess().StartInfo;
string origpath = info.EnvironmentVariables["path"];
string newpath = "C:\\mypath;" + origpath;
info.EnvironmentVariables["path"] = newpath;
****
I know I could create a separate executable that sets the Environment
variables and calls StartProcess to launch my application. I was hoping that
my application could set this path infromation without requiring another
executable to launch my application.
Thanks!