分享
 
 
 

关于MSFlexgrid控件(注册)的一个小问题

王朝知道·作者佚名  2010-12-07
窄屏简体版  字體: |||超大  
 
分類: 電腦/網絡 >> 程序設計 >> 其他編程語言
 
問題描述:

在MFC框架下:我在C*View的OnCreate()有如下代码:

int CGridView::OnCreate(LPCREATESTRUCT lpCreateStruct)

{

if (CView::OnCreate(lpCreateStruct) == -1)

return -1;

//-----------------------------------------------------------------------------------

CRect* rect = new CRect();

this->GetClientRect(rect);

m_pEditGrid->Create(NULL,WS_CHILD|WS_VISIBLE,*rect,this,IDC_EDIT_GRID);

delete rect;

OnUpdate(NULL,NULL,NULL);

return 0;

}

在装过VC 6.0 的机子上运行,出现一个2行2列的表格;在没有装VC 6.0 的机子上,当我注册过regsvr32 命令注册过MSFLXGRD.OCX控件后(系统提示注册成功),依然什么都没有显示,是何原因?

參考答案:

未安装VC使用activeX控件- -Tag: 串口控件 注册

在使用串口控件时,在没有装VC的机器上碰到问题

regsvr32 注册成功,但仍然不能使用,经查找是LicenseKey的问题

只需在创建控件时增加下列几行即可

WCHAR pwchLicenseKey[] =

{

0x0043, 0x006F, 0x0070, 0x0079, 0x0072, 0x0069,

0x0067, 0x0068, 0x0074, 0x0020, 0x0028, 0x0063,

0x0029, 0x0020, 0x0031, 0x0039, 0x0039, 0x0034,

0x0020

};

BSTR bstrLicense = ::SysAllocStringLen(pwchLicenseKey,

sizeof(pwchLicenseKey)/sizeof(WCHAR));

if(!m_ComPort.Create(NULL,0,CRect(0,0,0,0),AfxGetMainWnd(),

IDC_MSCOMM1,NULL,FALSE,bstrLicense))

{

AfxMessageBox("Failed to create OLE Communications Control\n");

return -1; //fail to create

}

......

::SysFreeString(bstrLicense);

具体参考原文见下:

-----------------------------------------------------------------------------------------------------

This article was previously published under Q151771

SUMMARYThe LicReqst sample illustrates how to use the IClassFactory2 interface to request an object's License key.

The following file is available for download from the Microsoft Download Center:

Licreqst.exe

For additional information about how to download Microsoft Support files, click the following article number to view the article in the Microsoft Knowledge Base:

119591 How to Obtain Microsoft Support Files from Online Services

Microsoft scanned this file for viruses. Microsoft used the most current virus-detection software that was available on the date that the file was posted. The file is stored on security-enhanced servers that help to prevent any unauthorized changes to the file. NOTE: Use the -d option when running Licrqst.exe to decompress the file and recreate the proper directory structure.

MORE INFORMATIONThe LicReqst sample is a dialog-based MFC application that illustrates how to use the IClassFactory2 interface to request an object's License key. LicReqst displays the ProgID of each of the currently registered ActiveX controls in a Listbox. When one of the displayed ProgID's is selected, an instance of the corresponding control is created and then asked for it's License key. If a valid key is returned, LicReqst displays the key and enables the "Copy to Clipboard" button that allows the License key to be copied to the Clipboard. The License key can then easily be pasted into code that uses the CWnd::CreateControl method to dynamically create an instance of the Control.

LicReqst creates a textual version of the License key data in the form of a declaration of an array of WCHAR when copying the key to the Clipboard. This is done because the License key data could contain non-printable characters. A human-readable version of the License key data is also provided for reference and is included inside a Comment block in the final string that is copied to the Clipboard.

For example, if an object uses the string "Copyright (c) 1994" (without the quotes) for its License key, LicReqst would generate the following block of text that could be copied to and pasted from the Clipboard:

/*

Copyright (c) 1994

*/

WCHAR pwchLicenseKey[] =

{

0x0043, 0x006F, 0x0070, 0x0079, 0x0072, 0x0069,

0x0067, 0x0068, 0x0074, 0x0020, 0x0028, 0x0063,

0x0029, 0x0020, 0x0031, 0x0039, 0x0039, 0x0034,

0x0020

};

You can use the previous block of text in code that creates an instance of the Licensed object, and you can use the pwchLicenseKey variable to specify the object's License key.

For example, if MFC code is dynamically creating an instance of a Licensed ActiveX Control using the Create method of a Visual C++ Component Gallery generated wrapper class, the pwchLicenseKey variable can be used in the Create call like this:

BSTR bstrLicense = ::SysAllocStringLen(pwchLicenseKey,

sizeof(pwchLicenseKey)/sizeof(WCHAR));

m_MyControl.Create(NULL, WS_VISIBLE, CRect(10,10,10,10), this,

2, NULL, FALSE, bstrLicense);

::SysFreeString(bstrLicense);

Note how a BSTR is created from the pwchLicenseKey variable and how the BSTR is then used for the License key parameter in the Create call.

NOTE: The code in this sample that generates the text copied to the Clipboard makes the assumption that it is being executed on a little endian system (Intel x86-class processors). Because of this, it will not work correctly on big endian system. For these systems, it is still possible to use the Helper function used internally by the sample to request the License key from an object.

The sample uses a Helper function called RequestLicenseKey() to get the License key from an object based on its ProgID. The source code for the RequestLicenseKey() function is shown later in the Sample Code section.

To find other locations of interest in the sample source code, use the Find in Files feature of the Visual C++ Developer Studio to search for the string named SAMPLE CODE. This string has been used to tag each of the modified sections in the source code.

NOTE: Running the LicReqst sample on a licensed machine to obtain an object's License key, and then distributing that key to allow applications to be developed on other non-licensed machines, may be a violation of established copyrights. For more information and to determine if an object's License key can be legally redistributed, refer to the License Agreement provided with the object or contact the creator of the object. Sample Code// Compile options needed: none

///////////////////////////////////////////////////////////////////////

// SAMPLE CODE - Implementation of the RequestLicenseKey function

//

// The RequestLicenseKey function uses the IClassFactory2 interface

// to request a License key from an object specified by its ProgID.

//

// Parameters:

//

// [out] BSTR& bstrLicenseKey

// Upon return, this BSTR will contain either a valid

// License key or an error message. It is the caller's

// responsibility to call ::SysFreeString on this BSTR.

//

// [in] CString strProgID

// Specifies the ProgID of the object from which to request the

// License key.

//

//

// Return Value:

//

// A BOOL specifying success or failure. If TRUE is returned,

// the License key was retrieved successfully and the

// bstrLicenseKey parameter contains a valid License key. If

// FALSE is returned, the License key was not retrieved

// successfully and the bstrLicenseKey parameter contains a

// descriptive error string.

//

// Regardless of the return value, it is the responsibility of

// the caller to call ::SysFreeString on the returned bstrLicenseKey

// parameter.

//

BOOL RequestLicenseKey(BSTR& bstrLicenseKey, CString strProgID)

{

USES_CONVERSION;

LPCLASSFACTORY2 pClassFactory;

CLSID clsid;

BOOL bValidKeyReturned = FALSE;

// Get the CLSID of the specified ProgID.

if (SUCCEEDED(CLSIDFromProgID(T2OLE(strProgID), &clsid)))

{

// Create an instance of the object and query it for

// the IClassFactory2 interface.

if (SUCCEEDED(CoGetClassObject(clsid, CLSCTX_INPROC_SERVER, NULL,

IID_IClassFactory2, (LPVOID *)(&pClassFactory))))

{

LICINFO licinfo;

// Check to see if this object has a runtime License key.

if (SUCCEEDED(pClassFactory->GetLicInfo(&licinfo)))

{

if (licinfo.fRuntimeKeyAvail)

{

HRESULT hr;

// The object has a runtime License key, so request it.

hr = pClassFactory->RequestLicKey(0, &bstrLicenseKey);

if (SUCCEEDED(hr))

{

if(bstrLicenseKey == NULL)

bstrLicenseKey = ::SysAllocString(

L""); else // You have the license key. bValidKeyReturned = TRUE; } else // Requesting the License key failed. switch(hr) { case E_NOTIMPL: bstrLicenseKey = ::SysAllocString( L""); break; case E_UNEXPECTED: bstrLicenseKey = ::SysAllocString( L""); break; case E_OUTOFMEMORY: bstrLicenseKey = ::SysAllocString( L""); break; case CLASS_E_NOTLICENSED: bstrLicenseKey = ::SysAllocString( L""); break; default: bstrLicenseKey = ::SysAllocString( L""); } } else bstrLicenseKey = ::SysAllocString( L""); } else bstrLicenseKey = ::SysAllocString( L""); // Make sure you release the reference to the class factory. pClassFactory->Release(); } else bstrLicenseKey = ::SysAllocString( L""); } else bstrLicenseKey = ::SysAllocString( L""); // Return a BOOL specifying whether or not you were able to get a // valid license key. return bValidKeyReturned; }

小贴士:① 若网友所发内容与教科书相悖,请以教科书为准;② 若网友所发内容与科学常识、官方权威机构相悖,请以后者为准;③ 若网友所发内容不正确或者违背公序良俗,右下举报/纠错。
 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有