15 мая 2023 года "Исходники.РУ" отмечают своё 23-летие!
Поздравляем всех причастных и неравнодушных с этим событием!
И огромное спасибо всем, кто был и остаётся с нами все эти годы!

Главная Форум Журнал Wiki DRKB Discuz!ML Помощь проекту


Help needed one using OCX requiring license

Simon Dong -- simon.dong@quintus.com
Thursday, January 04, 1996



Hi All,

I am using a OLE control (Sheridan Tab Control to be specific) in my VC4 MFC 
application. It is use as a child window of a non-dialog window. I use the 
Componet Gallery-created wrapper class to create and access the control. It 
runs fine in my work station because I install the Sheridan package so I 
have all the licensing info on my machine. But when I give the app to other 
people and let them register thc OCX using regsvr32.exe on their machines 
the OCX pops up a message box saying it's not licensed for design time use. 
I did some research in MSDN and Adam Henning's 'OLE Control inside and out' 
and realized there's a parameter in CWnd::CreateControl I can pass in a BSTR 
and the license key. Here's what I did.

I queried the IClassFactory2 interface from OCX object using 
::CoGetClassObject() and called the RequestLicKey() to get a copy of the 
runtime license key. I saved it then I created a constant in my code 
containing the key:

const WCHAR strLicKey = {
     ... The value of the key I got using RequestLicKey ...
};

I passed the key as the last parameter in the CWnd::CreateControl call and 
got a crash in the Kernel32, either with or without the OCX package 
installed on the machine. (The OCX is registered when it not installed). I 
know I probably need to call GetLicInfo() to test fLicVerified in the 
LICINFO structure and not pass in the key when it's already being verified, 
but the not licensed for design use message box even poped up when I tried 
to call GetLicInfo(). Beside that what else is wrong. Does anyone has any 
idea or pointer to any examples?

BTW, I also tried in VB. The exe generated by VB runs fine when I uninstall 
the OCX package and register the controls needed.

TIA. Any help is appreciated.

Simon Dong
simon@quintus.com



John & Annette Elsbree -- elsbree@msn.com
Tuesday, January 09, 1996

Simon -

Good detective work. You are *almost* there. The last obstacle is the 
difference between a BSTR and a pointer to WCHAR.

A BSTR can be treated as a WCHAR*, but not the other way around. Here's why: a 
BSTR is actually a pointer to the first WCHAR in the string, but there's 
additional data about the BSTR stored at a negative offset from the pointer. 
If that data isn't present, then any operation that depends on it will have 
unpredictable results.

So:
	BSTR bstr = FunctionReturningBstr();
	WCHAR* pwch = bstr;
	int nLength = wcslen(pwch);

...is ok, but:

	WCHAR* pwch = FunctionReturningWideString();
	BSTR bstr = (BSTR)pwch;	// bogus cast!
	int nLength = SysStringLen(bstr);

...is not.

To create a BSTR from a WCHAR*, call SysAllocString. When you're done with the 
BSTR, be sure to call SysFreeString.

	BSTR bstr = SysAllocString(L"license string here");
	CreateControl(..., bstr);
	SysFreeString(bstr);

That should get you going.

When you use a licensed control in the dialog editor, the license key is 
automatically extracted and encoded in the corresponding DLGINIT resource. 
However, when you're creating controls from code, you do need to manually 
include the license key in your code. Sorry we didn't have this whole 
procedure documented better... we're already working to remedy that.

mfcTeam.m_johnels;	// does not represent Microsoft

----------
From: 	owner-mfc-l@netcom.com on behalf of Simon Dong

I am using a OLE control (Sheridan Tab Control to be specific) in my VC4 MFC 
application. It is use as a child window of a non-dialog window. I use the 
Componet Gallery-created wrapper class to create and access the control. It 
runs fine in my work station because I install the Sheridan package so I 
have all the licensing info on my machine. But when I give the app to other 
people and let them register thc OCX using regsvr32.exe on their machines 
the OCX pops up a message box saying it's not licensed for design time use. 
I did some research in MSDN and Adam Henning's 'OLE Control inside and out' 
and realized there's a parameter in CWnd::CreateControl I can pass in a BSTR 
and the license key. Here's what I did.

I queried the IClassFactory2 interface from OCX object using 
::CoGetClassObject() and called the RequestLicKey() to get a copy of the 
runtime license key. I saved it then I created a constant in my code 
containing the key:

const WCHAR strLicKey = {
     ... The value of the key I got using RequestLicKey ...
};

I passed the key as the last parameter in the CWnd::CreateControl call and 
got a crash in the Kernel32, either with or without the OCX package 
installed on the machine. (The OCX is registered when it not installed). I 
know I probably need to call GetLicInfo() to test fLicVerified in the 
LICINFO structure and not pass in the key when it's already being verified, 
but the not licensed for design use message box even poped up when I tried 
to call GetLicInfo(). Beside that what else is wrong. Does anyone has any 
idea or pointer to any examples?

BTW, I also tried in VB. The exe generated by VB runs fine when I uninstall 
the OCX package and register the controls needed.




| Вернуться в корень Архива |