以下是我在一个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
博客展示了在COM(VC)项目中,从VB编写的COM里通过SAFEARRAY**获得数据的代码。给出了COM中VB代码原型,介绍了函数QuickCreate的用途、参数、调用函数及返回值等信息。

被折叠的 条评论
为什么被折叠?



