Academic Company Events NI Developer Zone Support Solutions Products & Services Contact NI MyNI
2 ratings:
 3.5 out of 5     Rate this Document

Dynamically Add ActiveX Controls that Require Run Time Licenses in Visual C#

Primary Software: Measurement Studio>>Visual Basic Support
Primary Software Version: 7.0
Primary Software Fixed Version: N/A
Secondary Software: N/A

Problem: I am using the Measurement Studio ActiveX controls to develop in Visual Basic.NET or Visaul C#. I need to add run time license information for dynamically added controls. How should I do this?

Solution: Create an ActiveX control that requires a run time license with the following steps:

Note: Assume your control is AxMyProject.AxMyLicensedControl and the
license key for the control is gnvlslnjskvlmlgnnimh

1.Find the code creates the ActiveX control, such as:

AxMyProject.AxMyLicensedControl myControl = new
AxMyProject.AxMyLicensedControl();


(This will create a new instance of the control through AxHostm. Do not
create a new instance of the control through COM (New
MyProject.MyLicensedControl), because it will not work on the form or allow
you to add the license easily.)

2.Determine and note the Runtime License Key for the control. Here it is for this example:
gnvlslnjskvlmlgnnimh.

3.Add the following code below
" AxMyProject.AxMyLicensedControl  

myControl = new AxMyProject.AxMyLicensedControl();"

System.Reflection.FieldInfo f =
typeof(AxHost).GetField("licenseKey",
System.Reflection.BindingFlags.NonPublic |
System.Reflection.BindingFlags.Instance);
f.SetValue(myControl, "gnvlslnjskvlmlgnnimh");

(This code inserts the run time license into the control. It creates an
instance of FieldInfo which is part of the property bag OCXState. This
property bag is full of specific ActiveX control information. In this case,
we are getting the field licenseKey and setting it for myControl. You
will need to do this for each instance of any ActiveX control that requires
a run time license.)

4.Build the application and run it.

Note: You will need to add the license to every instance of every
ActiveX control that requires a run time license. So, if you were to create a
second instance of MyLicensedControl you would have to add the license to
that instance as well. Also, make sure that you have the correct license key for
your control. Determining this will be specific to the control. One way to
determine the key is with the following KB article: Q151771 LICREQST.EXE Requesting a License Key from an Object (linked below).



Related Links: Microsoft Knowledge Base Article : HOW TO: Dynamically Add ActiveX Controls that Require Run-Time Licenses in Visual Basic .NET
Microsoft Knowledge Base Article : LICREQST.EXE Requesting a License Key from an Object

Attachments:





Report Date: 02/02/2004
Last Updated: 10/20/2004
Document ID: 3617IR5B

Your Feedback! poor Poor  |  Excellent excellent   Yes No
 Document Quality? 
 Answered Your Question? 
  1 2 3 4 5
Please Contact NI for all product and support inquiries.submit