Get data by SAFEARRAY** from COM(VB Code) in My VC COM Project (Code Part)

博客展示了在COM(VC)项目中,从VB编写的COM里通过SAFEARRAY**获得数据的代码。给出了COM中VB代码原型,介绍了函数QuickCreate的用途、参数、调用函数及返回值等信息。

以下是我在一个COM(VC)项目中从 VB 编写的另一个 COM 里通过 SAFEARRAY** 获得数据的代码

 USES_CONVERSION;
 
 HRESULT ret = m_iAWChange.CoCreateInstance(__uuidof(Application));
 m_iAWChange->Server = m_iAgileServer;
 AgileObjectsConstants aocChange = otChange;
 SAFEARRAY* sReturnValues;
 SAFEARRAYBOUND rgsabound[1];
 rgsabound[0].cElements = 2;
 rgsabound[0].lLbound = 0;

 BSTR ObjNumber = ::SysAllocString(L"");
 BSTR xSubClass = ::SysAllocString(L"");
 long onlyClassID = 0;
 long lArg6 = 0;

 sReturnValues = SafeArrayCreate(VT_NULL,2,rgsabound);;
 VARTYPE vt;
 try
 {
  long lTmp = m_iAWChange->QuickCreate(&aocChange, &sReturnValues, &ObjNumber, &xSubClass, &onlyClassID);
  SafeArrayGetVartype(sReturnValues, &vt);
  if (vt != VT_BSTR)
     return S_FALSE;

  long Dims = SafeArrayGetDim(sReturnValues);
  long UpperBounds;
  long LowerBounds;
  char strTemp[100];
  /*
  for(int i=1; i<=4; i++)
  {
   for(int j=1; j<=4; j++)
   {*/
    BSTR tmp;
    
    long indices[] = {2, 1};
    SafeArrayGetElement(sReturnValues, indices, (void *)&tmp);
    wcstombs(strTemp, tmp, 100);
    memset(strTemp, 0, 100);
 /*  
 }
  }
  */
 }
 catch(_com_error &err)
 {
  std::string strError = "Fail to load the MenuFile, ";
  strError += (const char*)err.Description();
  return FALSE;
 }

 return S_OK;

COM 中的 VB 代码原型

'****************************************************************************************************
'Function QuickCreate
'Purpose: Used by the calling app to display the quick create dialog to create an object.
'Parameters:  lCreateType - Determines the type of object to be created.
'                    sReturnValues() - Used to get the newly created object's data. Will be a three columns, 1 based,
'                                               one row array containing the created object's subclass, number and description.
'                    sObjectNumber - Optional. Used to propose an object number.
'                    sSubClass - Optional. Used to propose subclass.
'                    lOnlyClassId - Optional value specifying that only subclasses of the given ClassID should be
'                                   displayed.
'Calls: GetSubClasses() - To get the possible subclasses to fill the combo box control.
'         GetClassID() - To get a subclass' ID based on its description.
'         CreateObject() - To actually create the object based on the user selected values.
'Returns: 1 if an item was created with all attributes set, 2 if the item was created but not all of the attributes could be set,
'             0 if the user cancelled and -1 if an error occurred and the object couldn't be created.
'****************************************************************************************************
Public Function QuickCreate(lCreateType As AgileObjectsConstants, sReturnValues() As String, Optional sObjectNumber As String, Optional sSubClass As String, Optional lOnlyClassId As Long = 0) As Long
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值