473,383 Members | 1,739 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,383 software developers and data experts.

ActiveX Script using IDispatch

I have a Custom DTS Task for SQL Server and I've got it working fine, except
for when I try to access its properties from an ActiveX script. I have
added a new property called Length and a method called Generate that returns
a string. Whenever I get the object in the ActiveX script, the only
properties and methods I can use are for the CustomTask interface, not the
extended properties I've added. Does anyone know why these properties I've
added are not being made available by the IDispatch?

Scott
Nov 16 '05 #1
1 2935
UPDATE:

Simplified customtask that exhibits the problem:

using System;
using System.Runtime.InteropServices;
using Microsoft.SQLServer.DTSPkg80;
using Microsoft.Win32;
using System.Windows.Forms;

[assembly:ClassInterface(ClassInterfaceType.AutoDua l)]

namespace DTS
{

[Guid("[GUID is created by using GUIDGEN.EXE]"), ComVisible(true)]
[ProgId("DTS.SimpleCustomTask")]
public class SimpleCustomTask : CustomTask
{
private string name;
private string description;
private string message;

public SimpleCustomTask()
{
name = "";
description = "SimpleCustomTask description";
}
public void Execute(object pPackage, object pPackageEvents, object
pPackageLog, ref Microsoft.SQLServer.DTSPkg80.DTSTaskExecResult pTaskResult)
{

//Assume failure at the outset
pTaskResult = DTSTaskExecResult.DTSTaskExecResult_Failure;

try
{

Package2 package = (Package2) pPackage;
PackageEvents packageEvents = (PackageEvents) pPackageEvents;
PackageLog packageLog = (PackageLog) pPackageLog;
MessageBox.Show(message);

}

//First catch COM exceptions, and then all other exceptions
catch(System.Runtime.InteropServices.COMException e)
{

Console.WriteLine(e);
}
catch(System.Exception e)
{

Console.WriteLine(e);
}

//Return success
pTaskResult = DTSTaskExecResult.DTSTaskExecResult_Success;
}

public string Description
{
get { return this.description; }
set { this.description = value; }
}

public string Name
{
get { return name; }
set { this.name = value; }
}

public string Message
{
get { return this.message; }
set { this.message = value; }
}

public Microsoft.SQLServer.DTSPkg80.Properties Properties
{
get { return null; }
}

[System.Runtime.InteropServices.ComVisible(false)]
override public string ToString()
{
return base.ToString();
}
//Registration function for custom task.
[System.Runtime.InteropServices.ComRegisterFunction Attribute()]
static void RegisterServer(Type t)
{
try
{
const string TASK_CACHE = "Software\\Microsoft\\Microsoft SQL
Server\\80\\DTS\\Enumeration\\Tasks";
const string CATID_DTSCustomTask =
"{10020200-EB1C-11CF-AE6E-00AA004A34D5}";
string guid = "{" + t.GUID.ToString() + "}";
guid = guid.ToUpper();

Console.WriteLine("RegisterServer {0}", guid);

RegistryKey root;
RegistryKey rk;
RegistryKey nrk;

// Add COM Category in HKEY_CLASSES_ROOT
root = Registry.ClassesRoot;
rk = root.OpenSubKey("CLSID\\" + guid + "\\Implemented Categories",
true);
nrk = rk.CreateSubKey(CATID_DTSCustomTask);
nrk.Close();
rk.Close();
root.Close();

// Add to DTS Cache in HKEY_CURRENT_USER
root = Registry.CurrentUser;
rk = root.OpenSubKey(TASK_CACHE, true);
nrk = rk.CreateSubKey(guid);
nrk.SetValue("", t.FullName);

nrk.Close();
rk.Close();
root.Close();

SimpleCustomTask ct = new SimpleCustomTask();

root = Registry.ClassesRoot;
rk = root.OpenSubKey("CLSID\\" + guid, true);
rk.SetValue("DTSTaskDescription", ct.description);

nrk.Close();
rk.Close();
root.Close();

}
catch(Exception e)
{
System.Console.WriteLine(e.ToString());
}
}

//Unregistration function for custom task.
[System.Runtime.InteropServices.ComUnregisterFuncti onAttribute()]
static void UnregisterServer(Type t)
{
try
{
const string TASK_CACHE = "Software\\Microsoft\\Microsoft SQL
Server\\80\\DTS\\Enumeration\\Tasks";
string guid = "{" + t.GUID.ToString() + "}";
guid = guid.ToUpper();

Console.WriteLine("UnregisterServer {0}", guid);

RegistryKey root;
RegistryKey rk;

// Delete from DTS Cache in HKEY_CURRENT_USER
root = Registry.CurrentUser;
rk = root.OpenSubKey(TASK_CACHE, true);
rk.DeleteSubKey(guid, false);
rk.Close();
root.Close();
}
catch(Exception e)
{
System.Console.WriteLine(e.ToString());
}
}

}
}

The ActiveX Script fails on the "Message" assigment:

Function Main()
Dim oPackage
Dim oCT
set oPackage = DTSGlobalVariables.Parent
set oCT = oPackage.Tasks("DTSTask_DTS.SimpleCustomTask_1").C ustomTask
oCT.Message = "Hello World"
Main = DTSTransformStat_SkipInsert
End Function

Change the "set oCT" line to "set oCT =
CreateObject("DTS.SimpleCustomTask")" and it works but of course that is
creating the object once for each record which defeats the purpose of having
the task in the first place.

Obviously I'm having a COM interoperability problem. Anyone know how to
fix?

Scott

"Wm. Scott Miller" <Sc**********@spam.killer.wvinsurance.gov> wrote in
message news:uz**************@TK2MSFTNGP11.phx.gbl...
I have a Custom DTS Task for SQL Server and I've got it working fine, except for when I try to access its properties from an ActiveX script. I have
added a new property called Length and a method called Generate that returns a string. Whenever I get the object in the ActiveX script, the only
properties and methods I can use are for the CustomTask interface, not the
extended properties I've added. Does anyone know why these properties I've added are not being made available by the IDispatch?

Scott

Nov 16 '05 #2

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

Similar topics

0
by: Paul H. Milenkovic | last post by:
I think the problem is with ActiveX controls developed in Delphi -- I am having the same CONNECT_E_CANNOTCONNECT error message at that same point when I try to use ActiveX control I have developed in...
4
by: angel | last post by:
Hi I want to write an ActiveX by using python. And I know how do, but I don't know how python to access DHTML Document.If using cpp, it can be done by following source. /****/...
7
by: NewbieJon | last post by:
I am attempting to send the variable "sComputerName" from my ActiveX script to "GetInfo.asp" using javascript. (Having been advised this is the way to get my ActiveX variable into my ASP script) ...
5
by: Chris | last post by:
Greetings, I'm trying to late bind a ActiveX DLL that was made with VB6 in C#. Can you give me an example or URL of this? I've been trying to google it, just cant find a straight answer. Thanks!
3
by: Michiel | last post by:
Hello, I have an ActiveX control which I can call fine from HTML pages, using the object tag like <OBJECT ID="UserControl1" WIDTH="0" HEIGHT="0"...
1
by: John Gabriel | last post by:
I have set up a website and am testing ASPs. I have created a very simple ActiveX component with two interfaces: AboutBox() - displays About details calcpi() - returns 3.14159 Here is my...
1
by: thinktwice | last post by:
i could create it successfully, but i can't manipulate it <html> <body> <object height="50% width="50%" classid="clsid:XXXX....." id = obj> <script language= javascript> obj.gridVisible=...
5
by: Mercdev | last post by:
I have an ActiveX control inherited from UserControl. This control is hosted in IE(version 6 or later). How i can navigate IE from this control. I know that i need to obtain IWebBrowser2 interface...
0
by: miarfej | last post by:
Hi to all.. i am just new here, hoping to find some suggestions. I am writing a code in VC++. It is about creating an activeX control using MFC. This control exposes the properties and methods of...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.