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

Questions on Usage of a .NET Component from VB6 and VBScript

We are dealing with .NET server component and COM clients written with VB6 and VBScript. And there are some problems we faced (please see code below).

1. Managed type System Drawing.Color is automatically marshaled to VB type OLE_COLOR only in case of early binding. (see DealWithColor() method).

2. For class Component public variable DateTime dt can be used in both early and late binding cases, whereas public variable Color clr causes failure in late binding and works fine in early binding.

3. Method public void Info(MyPointClass pt) works fine with VB6 for both early and late binding but fails in VBScript.

Expand|Select|Wrap|Line Numbers
  1.     [ComVisible(true)]
  2.     public struct MYPOINT
  3.     {
  4.         // These are now private!
  5.         private int xPos;
  6.         private int yPos;
  7.  
  8.         [MarshalAs(UnmanagedType.BStr)]
  9.         private string name;
  10.  
  11.         // Add some members to the MYPOINT struct.
  12.         public void SetPoint(int x, int y) { xPos = x; yPos = y; }
  13.         public void DisplayPoint() { MessageBox.Show(string.Format("X: {0} Y: {1}", xPos, yPos), name); }
  14.     }
  15.  
  16.     [ComVisible(true)]
  17.     [ClassInterface(ClassInterfaceType.AutoDual)]
  18.     public class MyPointClass
  19.     {
  20.         private int xPos;
  21.         private int yPos;
  22.         private string name;
  23.  
  24.         public void SetPoint(string name, int x, int y) { this.name = name; xPos = x; yPos = y; }
  25.         public void DisplayPoint() { MessageBox.Show(string.Format("X: {0} Y: {1}", xPos, yPos), name); }
  26.     }
  27.  
  28. [ComVisible(true)]
  29. [ClassInterface(ClassInterfaceType.AutoDual)]
  30. public class Component
  31. {
  32.       // Success in Early Binding. Failure in Late Binding (Both VB6 and VBScript)
  33.     public Color clr;
  34.  
  35.       // Success in Early Binding and Late Binding (Both VB6 and VBScript)
  36.       public DateTime dt;
  37.  
  38.     // Success in Early Binding. Failure in Late Binding (Both VB6 and VBScript)
  39. public Color DealWithColor(Color col)
  40.       {
  41.           MessageBox.Show(col.ToString(), "DealWithColor() Method");
  42.           return col;
  43.       }
  44.  
  45. // Success in Early Binding. TODO Late
  46. public void Info(ref MYPOINT pt)
  47.       {
  48.           pt.DisplayPoint();
  49.       }
  50.  
  51.       // Success in Early Binding and Late Binding (Both VB6 and VBScript)
  52.       public void Info (object pt)
  53.       {
  54.           (pt as MyPointClass).DisplayPoint();
  55.       }
  56.  
  57. // Success in Early Binding and in Late Binding VB6. Failure in VBScript.
  58.       public void Info (MyPointClass pt)
  59.       {
  60.           pt.DisplayPoint();
  61.       }
  62. }
  63.  
  64.  
Expand|Select|Wrap|Line Numbers
  1.     'Late Binding via VB6
  2.    '''''''''''''''''''''''''''''''''''
  3.     Dim ptc As CallNetFromVB6.MyPointClass
  4.     Dim col1 As OLE_COLOR
  5.     Dim objLate As Object
  6.     Set objLate = CreateObject("CallNetFromVB6.Component")
  7.  
  8.     objLate.dt = Now                 'Success
  9.  
  10.     Set ptc = New CallNetFromVB6.MyPointClass
  11.     ptc.SetPoint "From Class", 11, 22
  12.     objLate.Info_2 ptc                      'Success
  13.  
  14.     objLate.clr = vbRed                 'Fail 
  15.     col1 = objLate.DealWithColor(col)     'Fail 
  16.  
  17.  
  18.     'Late Binding via VBScript
  19.     ''''''''''''''''''''''''''''''''''
  20.     Set objLate = CreateObject("CallNetFromVB6.Component")
  21.     Set ptLate = CreateObject("CallNetFromVB6.MyPointClass")
  22.  
  23.     objLate.dt = Now                 'Success
  24.  
  25.     Set ptc = New CallNetFromVB6.MyPointClass
  26.     ptc.SetPoint "From Class", 11, 22
  27.     objLate.Info_2 ptc                       'Fail
  28.  
  29.     objLate.clr = vbRed                 'Fail 
  30.     col1 = objLate.DealWithColor(col)     'Fail 
  31.  
  32.  
Thanks.

Igor Ladnik
Barak Cohen
Oct 15 '08 #1
1 1750
Frinavale
9,735 Expert Mod 8TB
Now that you've determined how .NET's Interop is not properly Marshaling your VB6 and VBScript components, consider Marshaling your VB6 and VBScript components yourself:

Write a wrapper class around the VB and VBScript components that will handle the Marshaling instead of leaving this up to .NET to do.

-Frinny
Oct 16 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

25
by: Lin Ma | last post by:
Hi, I am wondering if I am doing right. Please advise. I create a system with 8 major steps and each step can go different direction. General speaking, a lot of if statements and functions...
4
by: John Stemper | last post by:
I'm looking for some good articles or hints on accessing a .Net component that I've written from old ASP/VBScript. I've gotten as far as referencing the typelib in the global.asa file but when I...
4
by: Ramesh | last post by:
hi, Let me ask some basic questions. Can anybody explain me about the following questions: 1. When we have to create sn key? Whenever we compiled Component we have to create or it is a one time...
1
by: Peter Rilling | last post by:
I created a COM+ component (ServicedComponent) in .NET. The component has a single method Connect() which returns a reference to a SqlConnection object. This component works fine when the world is...
19
by: MP | last post by:
I'm interested to learn how to use mdb files via ado/adox via vb6 Since I'm not using Access are those types of questions o.t. here? I see very few ado questions here. But there's a lot more...
5
by: pepwelcome | last post by:
Hi, here is a question about custom components. ==== Before I learn ASP.net I program with ASP and VBscript, and I write codes like this: "<script language=vbscript src="usercheck.vb">" and so I...
5
by: Volker Hetzer | last post by:
Hi! I've done my first little COM component (using the clr) and after signing, regasm and gacutil I can call it from vbscript. set X = createobject("ComComponent.Class1") msgBox X.Testfunktion(2)...
4
by: =?Utf-8?B?V2lsbWVyIEhlcm5hbmRleg==?= | last post by:
An ActiveX component created using ATL under Visual Studio 2003, and it is used in a ASP, runs perfectly under administrator or power users group, however this same object does not run under the...
1
by: ShadowLocke | last post by:
This is an HTML application that allows you to monitor the CPU Usage (as seen in task manager) for any one task either on the local computer or a remote computer using vbscript. It then alerts you...
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: 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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.