[DllImport("shell32.dll")]
static extern IntPtr FindExecutable(string lpFile, string lpDirectory,
[Out] StringBuilder lpResult);
Private Declare Function FindExecutable Lib "shell32" Alias "FindExecutableA" _
(ByVal lpFile As String, _
ByVal lpDirectory As String, _
ByVal sResult As String) As IntPtr
None.
1) When using VB, one cannot place the declaration for FindExecutable within
the code portion of a form. If one needs to search for an executeable from
within a form, though, it is easy enough to open a module and place the
declaration there. From the form code, make a call to a function in the
module. Within the module function, execute FindExecutable and return any
results to the form routine. steveapub@pineclifftech.com
Please add some!
Please add some!!
Do you know one? Please contribute it!
********** Win32API.cs **********
using System;
using System.Text;
using System.Runtime.InteropServices;
namespace QuickTool
{
public class Win32API
{
[DllImport("shell32.dll", EntryPoint="FindExecutable")]
public static extern long FindExecutableA(
string lpFile, string lpDirectory, StringBuilder lpResult);
public static string FindExecutable(
string pv_strFilename)
{
StringBuilder objResultBuffer =
new StringBuilder(1024);
long lngResult = 0;
lngResult =
FindExecutableA(pv_strFilename,
string.Empty, objResultBuffer);
if(lngResult >= 32)
{
return objResultBuffer.ToString();
}
return string.Format(
"Error: ({0})", lngResult);
}
}
}
********************************
******** Form1.cs ********
private void mnuDynamic_Click(object sender, System.EventArgs e)
{
MenuItem theMenuItem = (MenuItem) sender;
MessageBox.Show(Win32API.FindExecutable(theMenuItem.Text));
}
**********************************