在制作OCX时,为什么定义了属性却无法访问
本帖最后由 jone7319 于 2012-06-11 23:04:24 编辑
STDMETHODIMP TFetionOCXImpl::get_FetionUser(BSTR* Value)
{
try
{
*Value = WideString(m_VclCtl->FetionUser).Copy(); //这里出错
}
catch(Exception &e)
{
return Error(e.Message.c_str(), IID_IFetionOCX);
}
return S_OK;
};
// pointers for interfaces in the COM map. VCL controls exposed as OCXes
// have a minimum set of interfaces defined by the
// VCL_CONTROL_COM_INTERFACE_ENTRIES macro. Add other interfaces supported
// by your object with additional COM_INTERFACE_ENTRY[_xxx] macros.
//
BEGIN_COM_MAP(TFetionOCXImpl)
VCL_CONTROL_COM_INTERFACE_ENTRIES(IFetionOCX)
END_COM_MAP()
// The PROPERTY map stores property descriptions, property DISPIDs,
// property page CLSIDs and IDispatch IIDs. You may use use
// IPerPropertyBrowsingImpl, IPersistPropertyBagImpl, IPersistStreamInitImpl,
// and ISpecifyPropertyPageImpl to utilize the information in you property
// map.
//
// NOTE: The BCB Wizard does *NOT* maintain your PROPERTY_MAP table. You must
// add or remove entries manually.
//
BEGIN_PROPERTY_MAP(TFetionOCXImpl)
// PROP_PAGE(CLSID_FetionOCXPage)
END_PROPERTY_MAP()
/* DECLARE_VCL_CONTROL_PERSISTENCE(CppClass, VclClass) is needed for VCL
* controls to persist via the VCL streaming mechanism and not the ATL mechanism.
* The macro adds static IPersistStreamInit_Load and IPersistStreamInit_Save
* methods to your implementation class, overriding the methods in IPersistStreamImpl.
* This macro must be manually undefined or removed if you port to C++Builder 4.0. */
DECLARE_VCL_CONTROL_PERSISTENCE(TFetionOCXImpl, TFetionOCX);
// The DECLARE_ACTIVEXCONTROL_REGISTRY macro declares a static 'UpdateRegistry'
// routine which registers the basic information about your control. The
// parameters expected by the macro are the ProgId & the ToolboxBitmap ID of
// your control.
//
DECLARE_ACTIVEXCONTROL_REGISTRY("FetionOCProj1.FetionOCX", 1);
protected:
STDMETHOD(_set_Font(IFontDisp** Value));
STDMETHOD(get_Active(VARIANT_BOOL* Value));
STDMETHOD(get_AlignDisabled(VARIANT_BOOL* Value));
STDMETHOD(get_AutoScroll(VARIANT_BOOL* Value));
STDMETHOD(get_AutoSize(VARIANT_BOOL* Value));
STDMETHOD(get_AxBorderStyle(TxActiveFormBorderStyle* Value));
STDMETHOD(get_BorderWidth(long* Value));
STDMETHOD(get_Caption(BSTR* Value));
STDMETHOD(get_Color(::OLE_COLOR* Value));
STDMETHOD(get_DoubleBuffered(VARIANT_BOOL* Value));
STDMETHOD(get_DropTarget(VARIANT_BOOL* Value));
STDMETHOD(get_Enabled(VARIANT_BOOL* Value));
STDMETHOD(get_Font(IFontDisp** Value));
STDMETHOD(get_HelpFile(BSTR* Value));
STDMETHOD(get_KeyPreview(VARIANT_BOOL* Value));
STDMETHOD(get_PixelsPerInch(long* Value));
STDMETHOD(get_PrintScale(TxPrintScale* Value));
STDMETHOD(get_Scaled(VARIANT_BOOL* Value));
STDMETHOD(get_Visible(VARIANT_BOOL* Value));
STDMETHOD(get_VisibleDockClientCount(long* Value));
STDMETHOD(set_AutoScroll(VARIANT_BOOL Value));
STDMETHOD(set_AutoSize(VARIANT_BOOL Value));
STDMETHOD(set_AxBorderStyle(TxActiveFormBorderStyle Value));
STDMETHOD(set_BorderWidth(long Value));
STDMETHOD(set_Caption(BSTR Value));
STDMETHOD(set_Color(::OLE_COLOR Value));
STDMETHOD(set_DoubleBuffered(VARIANT_BOOL Value));
STDMETHOD(set_DropTarget(VARIANT_BOOL Value));
STDMETHOD(set_Enabled(VARIANT_BOOL Value));
STDMETHOD(set_Font(IFontDisp* Value));
STDMETHOD(set_HelpFile(BSTR Value));
STDMETHOD(set_KeyPreview(VARIANT_BOOL Value));
STDMETHOD(set_PixelsPerInch(long Value));
STDMETHOD(set_PrintScale(TxPrintScale Value));
STDMETHOD(set_Scaled(VARIANT_BOOL Value));
STDMETHOD(set_Visible(VARIANT_BOOL Value));
STDMETHOD(get_FetionUser(BSTR* Value));
STDMETHOD(get_Password(BSTR* Value));
STDMETHOD(set_FetionUser(BSTR Value));
STDMETHOD(set_Password(BSTR Value));
VARIANT_BOOL STDMETHODCALLTYPE Login(BSTR user, BSTR pass);
};
//---------------------------------------
#endif
[解决办法]
直接用 *Value = WideString(FetionUser).Copy();
[解决办法]
TWinControlAccess<TVCL>* m_VclCtl;
m_VclCtl 用来访问vcl标准 属性
[解决办法]
我使用 vs2010 中没有楼主说的问题
添加属性:
在Project1.ridl 的Design界面
选择IFetionOCX树节点,右键New-Property
添加属性FetionUser,修改Type值为BSTR
点Project1.ridl 工具栏上的刷新,
这样Unit1.cpp中就可以找到set_FetionUser 函数了。
STDMETHODIMP TFetionOCXImpl::get_FetionUser(BSTR* Value)
{ //mabao add
try
{
//*Value = WideString(m_VclCtl->FetionUser).Copy(); //mabao
*Value = WideString(FetionUser).Copy(); //mabao
}
catch(Exception &e)
{
return Error(e.Message.c_str(), IID_IFetionOCX);
}
return S_OK;
};
STDMETHODIMP TFetionOCXImpl::set_FetionUser(BSTR Value)
{ //mabao add
try
{
FetionUser =Value; //mabao
//m_VclCtl->FetionUser =Value; //mabao
}
catch(Exception &e)
{
return Error(e.Message.c_str(), IID_IFetionOCX);
}
return S_OK;
};
class TFetionOCX : public TActiveForm
{
__published:// IDE-managed Components
private:// User declarations
public:// User declarations
System::UnicodeString Password;
System::UnicodeString FetionUser;
....
STDMETHODIMP TFetionOCXImpl::get_FetionUser(BSTR* Value)
{
try
{ *Value = WideString(m_VclCtl->FetionUser).Copy(); //mabao
}
catch(Exception &e)
{
return Error(e.Message.c_str(), IID_IFetionOCX);
}
return S_OK;
};
STDMETHODIMP TFetionOCXImpl::set_FetionUser(BSTR Value)
{
try
{
m_VclCtl->FetionUser = AnsiString(Value);
}
catch(Exception &e)
{
return Error(e.Message.c_str(), IID_IFetionOCX);
}
return S_OK;
};
STDMETHODIMP TFetionOCXImpl::get_Password(BSTR* Value)
{
try
{
*Value = WideString(m_VclCtl->Password).Copy(); //mabao
}
catch(Exception &e)
{
return Error(e.Message.c_str(), IID_IFetionOCX);
}
return S_OK;
};
STDMETHODIMP TFetionOCXImpl::set_Password(BSTR Value)
{
try
{
m_VclCtl->Password = AnsiString(Value);
}
catch(Exception &e)
{
return Error(e.Message.c_str(), IID_IFetionOCX);
}
return S_OK;
};