473,230 Members | 1,570 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,230 software developers and data experts.

Activator.CreateInstanceFrom(..) question


Hi all,
I'm trying to use some functionality from the Windows Desktop
Search Managed DLL "WDSQuery.dll" within a library I'm writing. I
can't be guaranteed this DLL will be present on the target machine so
I'm trying to write code to take this into account. So far, I seem to
be able to create an ObjectHandle. I then call the ObjectHandle's
Unwrap() method to return an object that I can work with. I don't know
if I'm doing this part right or not but it compiles and runs w/o
throwing any exceptions. When I try to call a method from this object,
I get a System.Runtime.InteropServices.COMException exception with
error code 0x80040E14. I've found some mention of this code resulting
from an SQL error but I'm tested the exact same input to this
ExecuteQuery method in another project that assumes the WDSQuery.dll
is available and all works fine.

Am I going about this all the wrong way? I would like to create an
Object then call one of its methods without knowing ahead of time if
the DLL is present.

Thanks... I pasted some sample code below.

[InterfaceType(1)]
[Guid("A227843C-1D92-48BC-AED6-DCA566F1790E")]
public interface ISearchDesktop
{
/*_Recordset */ object ExecuteQuery(string lpcwstrQuery, string
lpcwstrColumn, string lpcwstrSort, string lpcwstrRestriction);
/*_Recordset */ object ExecuteSQLQuery(string lpcwstrSQL);
}
public class Test
{
System.Runtime.Remoting.ObjectHandle hObject;
ISearchDesktop myInterface;

public Test()
{
try
{
hObject = Activator.CreateComInstanceFrom("WDSQuery.dll",
"Microsoft.Windows.DesktopSearch.Query.SearchDeskt opClass");

myInterface = (ISearchDesktop)hObject.Unwrap();

string lpcwstrQuery = "microsoft"; // search term
string lpcwstrColumn = "DocTitle,DocFormat";
string lpcwstrSort = "DocTitle";
string lpcwstrRestriction = String.Empty;

object o = myInterface.ExecuteQuery(lpcwstrQuery, lpcwstrColumn,
lpcwstrSort, null);

}
catch (System.IO.FileNotFoundException e){ }
catch (System.TypeLoadException e){}
catch (System.Runtime.InteropServices.COMException e){}
}
}
Feb 13 '06 #1
2 3930
Michael,

Why don't you just distribute WDSQuery.dll with your app, and make it a
private assembly (meaning, it is in the same directory as your app)?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Michael H" <gf*****@gmail.com> wrote in message
news:2e********************************@4ax.com...

Hi all,
I'm trying to use some functionality from the Windows Desktop
Search Managed DLL "WDSQuery.dll" within a library I'm writing. I
can't be guaranteed this DLL will be present on the target machine so
I'm trying to write code to take this into account. So far, I seem to
be able to create an ObjectHandle. I then call the ObjectHandle's
Unwrap() method to return an object that I can work with. I don't know
if I'm doing this part right or not but it compiles and runs w/o
throwing any exceptions. When I try to call a method from this object,
I get a System.Runtime.InteropServices.COMException exception with
error code 0x80040E14. I've found some mention of this code resulting
from an SQL error but I'm tested the exact same input to this
ExecuteQuery method in another project that assumes the WDSQuery.dll
is available and all works fine.

Am I going about this all the wrong way? I would like to create an
Object then call one of its methods without knowing ahead of time if
the DLL is present.

Thanks... I pasted some sample code below.

[InterfaceType(1)]
[Guid("A227843C-1D92-48BC-AED6-DCA566F1790E")]
public interface ISearchDesktop
{
/*_Recordset */ object ExecuteQuery(string lpcwstrQuery, string
lpcwstrColumn, string lpcwstrSort, string lpcwstrRestriction);
/*_Recordset */ object ExecuteSQLQuery(string lpcwstrSQL);
}
public class Test
{
System.Runtime.Remoting.ObjectHandle hObject;
ISearchDesktop myInterface;

public Test()
{
try
{
hObject = Activator.CreateComInstanceFrom("WDSQuery.dll",
"Microsoft.Windows.DesktopSearch.Query.SearchDeskt opClass");

myInterface = (ISearchDesktop)hObject.Unwrap();

string lpcwstrQuery = "microsoft"; // search term
string lpcwstrColumn = "DocTitle,DocFormat";
string lpcwstrSort = "DocTitle";
string lpcwstrRestriction = String.Empty;

object o = myInterface.ExecuteQuery(lpcwstrQuery, lpcwstrColumn,
lpcwstrSort, null);

}
catch (System.IO.FileNotFoundException e){ }
catch (System.TypeLoadException e){}
catch (System.Runtime.InteropServices.COMException e){}
}
}

Feb 13 '06 #2
On Mon, 13 Feb 2006 09:29:45 -0500, "Nicholas Paldino [.NET/C# MVP]"
<mv*@spam.guard.caspershouse.com> wrote:

-> Michael,
->
-> Why don't you just distribute WDSQuery.dll with your app, and
make it a
-> private assembly (meaning, it is in the same directory as your
app)?
I may have to distribute it but it was more of a general question.
I just approached it like this.

try
{
WdsAssembly = System.Reflection.Assembly.LoadFrom("WDSQuery.dll" );

Type t = WdsAssembly.GetType(
"Microsoft.Windows.DesktopSearch.Query.SearchDeskt opClass", false,
true);

object SearchDesktopClass = System.Activator.CreateInstance(t);

System.Reflection.MethodInfo ExecuteQuery =
t.GetMethod("ExecuteQuery");

Object[] Parameters = new Object[4];
...
...
...
Object o2 = ExecuteQuery.Invoke(SearchDesktopClass, Parameters);
...
...
}
catch (System.Exception)
{
...
}
Feb 15 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Mike Malter | last post by:
I am just starting to work with reflection and I want to create a log that saves relevant information if a method call fails so I can call that method again later using reflection. I am...
7
by: Ian Frawley | last post by:
Hi I have used the Activator class a number of times in my Windows apps and Windows Services and was thinking of using it again in one of my web services that I have been developing. I have been...
1
by: Johnny R | last post by:
Hello, I'm loading a Class from Assemly DLL using Activator.CreateInstance. That loaded Class is executed in a worker Thread with no loop. What actually happends when class is loaded using...
1
by: Dan Dorey | last post by:
My goal is to pass in an assembly and have the method return an instance of any classes that inherit from the generic type T. My problem is that I'm unable to cast from the result of...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.