From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

Measurement Studio for VC++

cancel
Showing results for 
Search instead for 
Did you mean: 

How can I create CWKnob Dynamically in VC++

I;ve been trying to create a control dynamically (cwknob for example and ran into some trouble.

1. I can't seem to be able to create and destroy a CWknob unless the variable is a pointer (app crashes).
2. When I do use a pointer it crashes from time to time , mainly under win98.

I'm using componentworks starter kit (v6.0) under VC++.
Any idea why?

I attached part of the code for example.
0 Kudos
Message 1 of 3
(2,838 Views)
If the class has a member variable for the control, you should be able to dynamically create the control without having to make the variable a pointer and using new. For example, you should be able to change your example like this:

// Define:
CNiKnob m_knob;

// Create:

WCHAR pwchLicenseKey[] =
{
0x0069, 0x0065, 0x006E, 0x0070, 0x0070, 0x006D,
0x0062, 0x006B, 0x006E, 0x0069, 0x006F, 0x0061,
0x006C, 0x006E, 0x006B, 0x0065, 0x0062, 0x0064,
0x0065, 0x006D, 0x006A, 0x0066, 0x006B, 0x0063,
0x0068, 0x0062, 0x0064, 0x0065, 0x0066, 0x006B,
0x006F, 0x006B, 0x006D, 0x006F, 0x006B, 0x0066,
0x0066, 0x0066, 0x0066, 0x0070, 0x0063, 0x006A,
0x006E, 0
x006D, 0x0070, 0x006D, 0x0066, 0x0069,
0x0069, 0x006D, 0x0061, 0x006D, 0x006B, 0x006E,
0x0064, 0x006F, 0x006A, 0x006A, 0x0069, 0x0066,
0x006F, 0x006B, 0x0063, 0x0065
};

CComBSTR license(pwchLicenseKey);
m_knob.Create(_T(""), WS_VISIBLE, CRect(10, 10, 200, 200), this, 0, NULL, FALSE, license);

I noticed that you're using the ActiveX wrappers that are automatically generated by Visual C++. Since you have Measurement Studio 6.0, I recommend that you look at the Measurement Studio libraries for Visual C++. These libraries were designed to be used natively in C++ and I think that you will find them to be better to develop with than the automatically generated wrappers.

- Elton
0 Kudos
Message 2 of 3
(2,838 Views)
Hello

You can also check out this document for more information about obtaining the license value for the controls, and how to use it.
How Do I Create Controls Dynamically in Visual C++ When Using MFC without the Demo Mode Message Wind...

Hope this helps

Bilal Durrani
NI
Bilal Durrani
NI
0 Kudos
Message 3 of 3
(2,838 Views)