[req]Everything Search IPC C# demo code?

Plug-in and third party software discussion.
Post Reply
mazzzzz
Posts: 2
Joined: Thu Jun 11, 2009 6:07 pm

[req]Everything Search IPC C# demo code?

Post by mazzzzz » Fri Jun 12, 2009 9:29 pm

Hey guys, I guess the title says it all. I code in C#, and was wondering if anyone could provide some demo code that would retrieve results from the everything index??

Thanks,
Max

David
Site Admin
Posts: 430
Joined: Tue Mar 17, 2009 1:42 am

Re: [req]Everything Search IPC C# demo code?

Post by David » Thu Oct 29, 2009 10:58 am

Using the same dll as the Clarion module from:
http://support.voidtools.com/Everything/Clarion

Form1.cs:

Code: Select all

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace WindowsApplication1
{
	public partial class Form1 : Form
	{
		[StructLayout(LayoutKind.Sequential)]
		public class EVERYTHING_RESULT
		{
			public const int EVERYTHING_RESULT_FULLPATHFILENAME_SIZE = 260;

			[MarshalAs(UnmanagedType.ByValTStr, SizeConst = EVERYTHING_RESULT_FULLPATHFILENAME_SIZE)]
			public string FullPathFileName;

			public int PathPartLength;
			public int FileNamePartOffset;

			public int SizeHigh;
			public int SizeLow;

			public int Attributes;

			public int CreationYear;
			public int CreationMonth;
			public int CreationDayOfWeek;
			public int CreationDay;
			public int CreationHour;
			public int CreationMinute;
			public int CreationSecond;
			public int CreationMilliseconds;

			public int LastAccessYear;
			public int LastAccessMonth;
			public int LastAccessDayOfWeek;
			public int LastAccessDay;
			public int LastAccessHour;
			public int LastAccessMinute;
			public int LastAccessSecond;
			public int LastAccessMilliseconds;

			public int LastWriteYear;
			public int LastWriteMonth;
			public int LastWriteDayOfWeek;
			public int LastWriteDay;
			public int LastWriteHour;
			public int LastWriteMinute;
			public int LastWriteSecond;
			public int LastWriteMilliseconds;

		}
		
		[DllImport("Everything.dll")]
		public static extern int Everything_SetSearch(string c);
		[DllImport("Everything.dll")]
		public static extern void Everything_Query();
		[DllImport("Everything.dll")]
		public static extern int Everything_GetTotResults();
		[DllImport("Everything.dll")]
		public static extern int Everything_GetNumResults();
		[DllImport("Everything.dll")]
		public static extern void Everything_GetResult(int index, [Out, MarshalAs(UnmanagedType.LPStruct)]EVERYTHING_RESULT results);
		[DllImport("Everything.dll")]
		public static extern int Everything_GetLastError();

		public Form1()
		{
			InitializeComponent();
		}

		private void button1_Click(object sender, EventArgs e)
		{
			int i;
			
			Everything_SetSearch(textBox1.Text);
			Everything_Query();
			
			listBox1.Items.Clear();

			Text = textBox1.Text + " - " + Everything_GetTotResults() + " Results";
			
			for (i = 0; i < Everything_GetTotResults(); i++)
			{
				EVERYTHING_RESULT result = new EVERYTHING_RESULT();
				
				Everything_GetResult(i,result);
				
				listBox1.Items.Insert(i,result.FullPathFileName);
			}
		}
	}
}
Form1.Designer.cs:

Code: Select all

namespace WindowsApplication1
{
	partial class Form1
	{
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.IContainer components = null;

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
		protected override void Dispose(bool disposing)
		{
			if (disposing && (components != null))
			{
				components.Dispose();
			}
			base.Dispose(disposing);
		}

		#region Windows Form Designer generated code

		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.button1 = new System.Windows.Forms.Button();
			this.listBox1 = new System.Windows.Forms.ListBox();
			this.textBox1 = new System.Windows.Forms.TextBox();
			this.SuspendLayout();
			// 
			// button1
			// 
			this.button1.Location = new System.Drawing.Point(250, 12);
			this.button1.Name = "button1";
			this.button1.Size = new System.Drawing.Size(84, 20);
			this.button1.TabIndex = 0;
			this.button1.Text = "Search";
			this.button1.UseVisualStyleBackColor = true;
			this.button1.Click += new System.EventHandler(this.button1_Click);
			// 
			// listBox1
			// 
			this.listBox1.FormattingEnabled = true;
			this.listBox1.Location = new System.Drawing.Point(12, 38);
			this.listBox1.Name = "listBox1";
			this.listBox1.Size = new System.Drawing.Size(322, 199);
			this.listBox1.TabIndex = 2;
			// 
			// textBox1
			// 
			this.textBox1.Location = new System.Drawing.Point(12, 12);
			this.textBox1.Name = "textBox1";
			this.textBox1.Size = new System.Drawing.Size(232, 20);
			this.textBox1.TabIndex = 3;
			// 
			// Form1
			// 
			this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
			this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
			this.ClientSize = new System.Drawing.Size(349, 251);
			this.Controls.Add(this.textBox1);
			this.Controls.Add(this.listBox1);
			this.Controls.Add(this.button1);
			this.Name = "Form1";
			this.Text = "Form1";
			this.ResumeLayout(false);
			this.PerformLayout();

		}

		#endregion

		private System.Windows.Forms.Button button1;
		private System.Windows.Forms.ListBox listBox1;
		private System.Windows.Forms.TextBox textBox1;
	}
}


David
Site Admin
Posts: 430
Joined: Tue Mar 17, 2009 1:42 am

Re: [req]Everything Search IPC C# demo code?

Post by David » Fri Oct 30, 2009 11:51 am

An updated SDK is available from:
http://forum.voidtools.com/viewtopic.php?f=10&t=541

sbraun
Posts: 2
Joined: Mon Nov 23, 2009 1:16 am

Re: [req]Everything Search IPC C# demo code?

Post by sbraun » Mon Nov 23, 2009 1:19 am

David,

I downloaded the Search Everything SDK. When I run the C# sample I get the following error after I enter search criteria and press the search button:

System.DllNotFoundException was unhandled
Message="Unable to load DLL 'Everything.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)"
Source="WindowsApplication1"
TypeName=""
StackTrace:
at WindowsApplication1.Form1.Everything_SetSearch(String lpSearchString)
at WindowsApplication1.Form1.button1_Click(Object sender, EventArgs e) in C:\Users\sbraun\Desktop\Everything-SDK\example\CSharp\Form1.cs:line 96
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at WindowsApplication1.Program.Main() in C:\Users\sbraun\Desktop\Everything-SDK\example\CSharp\Program.cs:line 20
at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:


I copied the everything.dll found in the Everything-SDK\dll folder to the bin\debug directory of the sample. Now I get the following:

System.BadImageFormatException was unhandled
Message="An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)"
Source="WindowsApplication1"
StackTrace:
at WindowsApplication1.Form1.Everything_SetSearch(String lpSearchString)
at WindowsApplication1.Form1.button1_Click(Object sender, EventArgs e) in C:\Users\sbraun\Desktop\Everything-SDK\example\CSharp\Form1.cs:line 96
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at WindowsApplication1.Program.Main() in C:\Users\sbraun\Desktop\Everything-SDK\example\CSharp\Program.cs:line 20
at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:

Any thoughts on what I am doing wrong?

Thanks,
Shannon

David
Site Admin
Posts: 430
Joined: Tue Mar 17, 2009 1:42 am

Re: [req]Everything Search IPC C# demo code?

Post by David » Mon Nov 23, 2009 7:12 am

Are you trying to compile your project for the x64 platform target?
The everything.dll is only 32bit.

sbraun
Posts: 2
Joined: Mon Nov 23, 2009 1:16 am

Re: [req]Everything Search IPC C# demo code?

Post by sbraun » Tue Nov 24, 2009 3:32 am

Thanks David.

I am running a Windows 7 64bit OS... the Build:Platform Target was set to Any. I changed it to x86, compiled and ran the sample with no problem.

Thanks again, Everything Search is a great piece of work.

kalai
Posts: 1
Joined: Tue Aug 30, 2011 10:44 am

Re: [req]Everything Search IPC C# demo code?

Post by kalai » Tue Aug 30, 2011 10:52 am

David,
The above Code Works fine but i want to search file in Network share folder.please give a acceptable solution.
Thanks in Advance

Yoat
Posts: 1
Joined: Sun Oct 23, 2011 8:42 pm

Re: [req]Everything Search IPC C# demo code?

Post by Yoat » Sun Oct 23, 2011 8:49 pm

I'm able to build an run the C# demo code (thanks to this thread) and I get results but they aren't correct. See screenshot comparing concurrently running demo code and Everything native app. Note that the same search term was used but different result counts were reported as well as vastly different results. I'm guessing the input is getting mangled in my searches, but I wanted to post in case anybody has seen this or understands it better than I.
Thanks for any help you can provide.
http://i.imgur.com/iPy2I.png

----------------

NEVERMIND

I manually edited the call to Everything_SetSearch() to be Everything_SetSearchW() for test purposes and forgot to change it back. I'll leave this here in case anybody else makes the same dumb mistake.

I realized this by noticing that any search term with an ODD number of characters returned 0 results and a term with EVEN characters returned results, but they were incorrect results. It does work perfectly, as expected.

Thanks a lot, David!

Post Reply