473,799 Members | 2,727 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

c# interop question-- QueryInterface trouble

Hi everyone,

I've recently ported a COM component into .Net using a runtime callable
wrapper. The component in question is SQL Server's DTS package, if that
helps.

The import worked well enough....now I'm having some trouble using the
component. Specifically, this code below from VB6, which works:

Dim oTask As DTS.Task
Dim oCustomTask0 As DTS.ExecuteSQLT ask2
Set oTask = goPackage.Tasks .New("DTSExecut eSQLTask")
Set oCustomTask0 = oTask.CustomTas k
......doesn't work in my C# app. Here's how I've ported it:

DTS.Task oTask;
DTS.ExecuteSQLT ask2 oCustomTask0;
oTask = goPackage.Tasks .New("DTSExecut eSQLTask");
oCustomTask0 = (DTS.ExecuteSQL Task2) oTask.CustomTas k; //<----blows up here

On the last line above, where I do a cast, I get a runtime error telling me
QueryInterface failed. I'm not sure why it would fail in C#, when the
equivalent code in VB6 worked. Would anyone have an idea what I've done
wrong? Thanks!
Nov 17 '05 #1
4 3290
Jim Bancroft wrote:
Hi everyone,

I've recently ported a COM component into .Net using a runtime callable
wrapper. The component in question is SQL Server's DTS package, if that
helps.

The import worked well enough....now I'm having some trouble using the
component. Specifically, this code below from VB6, which works:

Dim oTask As DTS.Task
Dim oCustomTask0 As DTS.ExecuteSQLT ask2
Set oTask = goPackage.Tasks .New("DTSExecut eSQLTask")
Set oCustomTask0 = oTask.CustomTas k
.....doesn't work in my C# app. Here's how I've ported it:

DTS.Task oTask;
DTS.ExecuteSQLT ask2 oCustomTask0;
oTask = goPackage.Tasks .New("DTSExecut eSQLTask");
oCustomTask0 = (DTS.ExecuteSQL Task2) oTask.CustomTas k; //<----blows up here

On the last line above, where I do a cast, I get a runtime error telling me
QueryInterface failed. I'm not sure why it would fail in C#, when the
equivalent code in VB6 worked. Would anyone have an idea what I've done
wrong? Thanks!


Why do you need cast in [ oCustomTask0 =
(DTS.ExecuteSQL Task2)oTask.Cus tomTask;], based on your VB code, I don't
see you need a cast here. Is "CustomTask " defined in the default
interface DTS.Tas implement?
Nov 17 '05 #2
Hi,

I'm doing the cast because if I don't, I get this error when compiling:

Cannot implicitly convert type 'Microsoft.SqlS erver.DTSPkg80. CustomTask' to
'Microsoft.SqlS erver.DTSPkg80. ExecuteSQLTask2

So, I figured a cast was the way to go. CustomTask inherits from DTS.Task,
if that helps.

Here's the hierarchy, if you're interested:
http://msdn.microsoft.com/library/de...thobj_9nhw.asp


Why do you need cast in [ oCustomTask0 =
(DTS.ExecuteSQL Task2)oTask.Cus tomTask;], based on your VB code, I don't
see you need a cast here. Is "CustomTask " defined in the default interface
DTS.Tas implement?

Nov 17 '05 #3
The fact that it's not a casting exception leads me to believe that your not doing anything wrong (unless you modified the type
library before importing) and that the wrapper is at fault.

Another possibility:

Your casting to a class it seems, and not an interface. In my experience I've found that marshalled members, in some cases, must be
cast to an interface and not a class. Try breaking on that line in a debugger and see what Type oTask.CustomTas k is and try
explicitly casting to that. I'd imagine it will be an interface instead.

GL

--
Dave Sexton
dave@www..jwaon line..com
-----------------------------------------------------------------------
"Jim Bancroft" <as******@nowhe re.com> wrote in message news:Ol******** ******@TK2MSFTN GP10.phx.gbl...
Hi everyone,

I've recently ported a COM component into .Net using a runtime callable wrapper. The component in question is SQL Server's DTS
package, if that helps.

The import worked well enough....now I'm having some trouble using the component. Specifically, this code below from VB6, which
works:

Dim oTask As DTS.Task
Dim oCustomTask0 As DTS.ExecuteSQLT ask2
Set oTask = goPackage.Tasks .New("DTSExecut eSQLTask")
Set oCustomTask0 = oTask.CustomTas k
.....doesn't work in my C# app. Here's how I've ported it:

DTS.Task oTask;
DTS.ExecuteSQLT ask2 oCustomTask0;
oTask = goPackage.Tasks .New("DTSExecut eSQLTask");
oCustomTask0 = (DTS.ExecuteSQL Task2) oTask.CustomTas k; //<----blows up here

On the last line above, where I do a cast, I get a runtime error telling me QueryInterface failed. I'm not sure why it would fail
in C#, when the equivalent code in VB6 worked. Would anyone have an idea what I've done wrong? Thanks!

Nov 17 '05 #4
Thanks for the help. I think I've found out what's wrong. It seems there's
a problem with DTS in versions of SQL Server 2000 without Service Pack 2
installed:

http://www.sqldts.com/default.aspx?6,222,286,0,1
I'm off to update my installation now. Hope that fixes things!

Thanks everyone!

-Jim
"Dave" <NO*********@do tcomdatasolutio ns.com> wrote in message
news:ux******** ******@TK2MSFTN GP09.phx.gbl...
The fact that it's not a casting exception leads me to believe that your
not doing anything wrong (unless you modified the type library before
importing) and that the wrapper is at fault.

Another possibility:

Your casting to a class it seems, and not an interface. In my experience
I've found that marshalled members, in some cases, must be cast to an
interface and not a class. Try breaking on that line in a debugger and
see what Type oTask.CustomTas k is and try explicitly casting to that. I'd
imagine it will be an interface instead.

GL

Nov 17 '05 #5

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

Similar topics

1
1203
by: Rich S. | last post by:
Hello, I have imported an ActiveX control and I'm trying to use it inside a C# class. The problem is that since the event handlers are required to be "static" functions, I can't reference the instance members of my class from inside them. As of now, it gives me compile errors because I am referencing non-static members from the static event handlers.
26
10681
by: Vish | last post by:
Hi, I am trying to expose my .NET 2.0 class as a COM type using the following attributes for the attributes I have the "Register for COM Interop" build property set to true. I also have two functions in the class to register and unregister the COM with the
1
1096
by: Altman | last post by:
I have just recently started playing around with VB.Net and I created a small app that used an existing com dll written in VC++ 6.0. I then noticed that it created a file called interop.mycom.dll. I also noticed that the exe file would not run without this file. I did some searching and found out that this is a wrapper to the com dll. I don't mind this except I have a few questions on this. If I modify my com dll, does this mean I have...
1
3175
by: Reg | last post by:
Hello, I have a WCF Web Service using wsHttpDualBinding because I need a callback to Java client. I read Mr. A.Gupta's blog that if WCF Service uses wsHttpDualBinding for interop working is not guaranteed. I also tried to config wsHttpDualBinding in WCF Service Config file as follows:
3
2469
by: =?Utf-8?B?VGVycnk=?= | last post by:
I have made up a contrived example show the problem I am having. I have some ReadOnly interfaces: Public Interface IROPerson ReadOnly Property FirstName() As String ReadOnly Property LastName() As String ReadOnly Property Friends() As IROPersons End Interface Public Interface IROPersons Function Count() As Integer
1
1593
by: =?Utf-8?B?VGVycnkgQWxsZW4=?= | last post by:
When referencing the Microsoft Graph 11.0 Object Library in a C# applicaion using Visual Studio 2005 it uses the path below. C:\WINDOWS\assembly\GAC\Microsoft.Office.Interop.Graph\12.0.0.0__71e9bce111e9429c\Microsoft.Office.Interop.Graph.dll I have both Office 2003 and 2007 installed on my machine but wish to only reference the version 11 COM components. Do to my situation I need to use both versions of Office, but the intended...
11
2355
by: michelqa | last post by:
When executing some win32 messages in c# I get unexpected results. The following example is suppose to return the handle of an image in a button control of another application but it return a negative handle...is anybody know why it return an invalid handle like "-989523277" ?? IntPtr ImageHandle = Win32.SendMessage(Handle,BM_GETIMAGE,IntPtr.Zero,IntPtr.Zero); MessageBox.Show(ImageHandle.ToString());
0
9550
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10269
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10248
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9085
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6811
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5597
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4148
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3764
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2942
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.