????? C++ ?? Visual Basic 6.0 ?? ??? ??? ??? VARIANT * ???? SafeArray ?????????? ?? ??? ???? ?? ??? ???? ????

???? ?????? ???? ??????
???? ID: 167668 - ?? ???????? ?? ?????? ??? ?? ?? ???? ???? ???? ??.
???:Microsoft Visual C++ .NET (2002) Microsoft .NET Framework ?????? ??? ?? ??? ?? ???????? ???? ?? ????????? ??? Microsoft Windows ??? ???? ?? ?????? ???? ??? ?? ???? ??? ?? ?? ??????? ???? ????????? ????? C++ ??? ?? ??? ???? ???? ???
??? ?? ??????? ???? | ??? ?? ??????? ????

??????

?? ???? ??? SafeArray ?? ???????? ??? ????? C++ ?? Visual Basic 6.0, ??????? ?? ??? SafeArrays passing ?? ?????? ??????? ?? ????? ?? VARIANT ?????? ?? ?????? ???? MFC, ??? ?? ?? "const VARIANT & varName" ???????? ????

???? ?????? ?? ??? ??? ?? ???? explores ???? ??? ??? VARIANT *, ?? MFC ??? declared "VARIANT FAR * varName" ???????? ?? ??? ??? ???? ??????

????? ???? ????? ?? ?? ???? ?? ????? ???? ??? ??????? ??????? ????????? ?????? ?????? ???? ?? ??? ??? SafeArray ??? ?? VARIANT, ????? ??? ???? ???? ??? ??? Excel 95 ??? ?? ?? ???? ??? ??? ??? SafeArray ?? VARIANT ??? ??? ????? C++ ???? ?? ??? ?????, ????? ??? ??? ?? ??????? ????, ??????? SafeArray ???? ????? ?? ??? ?? ???????? Excel 95 ??? ??? ?? ????? ?? ????? ???? ?? ??? ???? ???? ???? ?? ?????? ?? ??? Visual Basic 6.0 ??? ??? ????? ???????? ?? ????? ???? ???

???? ???????

?? concept demonstrate, ?? ??? "MFC AppWizard(exe)" ????????? ?? ??? ??????? ???? ?? ??? StrArray ?? ?? ??? ???? ????? ??? "??? 3 ?? 6," ?? ??? ???????????????? ????,???????? ????-????? ????, ?? ???? ???OK????????? ??????? ????? ?????

???:: ??? ????? Studio.NET ?? ????? ?? ??? ??: ?? ??? "MFC ?????????" ????? ????????? StrArray ?? ?? ??? ???? ???? ??? ????? ????????? ??????????? ?? ??? ????????????? ????-????? ????, ?? ???? ?????????????????? ??????? ????? ?????

?? ???? ??? ??????? ?????? ?? ClassWizard ?????? ??? ClassWizard, ?? ??? ???? "CStrArrayDoc" ?? ??????? "???? ?? ???:"? ????? ???????????????? ???? ?? ??????? ??????. ???? ????? ????? ????? ??? ????? ??? ???? ????:

???:: ??? ????? Studio.NET ?? ????? ?? ??? ??: "???? ?????" ?? ????? ?? ???? ??? ??????? ???? ??????? ???? ????? ???? ?? ??????? ???? ?? ????? VCCOdeIDLLibrary ?????????? ?? ??? ?? ??????? IStrArray ??????? ??????? ??????? ?? ????-????? ????, ?? ???? ??? ?? ??? ???????? ??????. ???? ????? ????? ????? ??? ????? ??? ???? ????:
   External Name : Sort
   Internal Name : Sort
   Return Type   : long
   Parameter List:

      Name       : vArray
      Type       : VARIANT*
				


????? ????,OK, ????? ?? ??????? ????.

????? ?????? ?? ??????????? ???? ?? ??? ???? ??? ?? ???????? ??? ??? ???????? MFCARRAY ????? ?? FastSort ?????? ?? ????? ????? ???? ???? ?? "const VARIANT & varName" ?? ??? ??? ???????? ??? ?? ??? ?? ?? ??? ?? ???? ?? ????? ?? ??? ?? ?? "VARIANT * varName"? ????? ?????? ?? ??????????? ??????? ????:

   ...
   #include <afxpriv.h>
   ...
   long CStrArrayDoc::Sort(VARIANT FAR* vArray)
   {

      long i, j, min;
      BSTR bstrTemp;
      SAFEARRAY FAR* psa = NULL;
      BSTR HUGEP *pbstr;
      HRESULT hr;
      DWORD dwTimeStart;
      LONG cElements, lLBound, lUBound;

      USES_CONVERSION;

      // Type check VARIANT parameter. It should contain a BSTR array
      // passed by reference. The array must be passed by reference it is
      // an in-out-parameter.
      if (V_VT(vArray) != (VT_ARRAY | VT_BSTR))
         AfxThrowOleDispatchException(1001,
           "Type Mismatch in Parameter. Pass a string array by reference");
      psa = V_ARRAY(vArray);
      // Check dimensions of the array.
      if (SafeArrayGetDim(psa) != 1)
         AfxThrowOleDispatchException(1002,
           "Type Mismatch in Parameter. Pass a one-dimensional array");

      dwTimeStart = GetTickCount();

      // Get array bounds.
      hr = SafeArrayGetLBound(psa, 1, &lLBound);
      if (FAILED(hr))
          goto error;
      hr = SafeArrayGetUBound(psa, 1, &lUBound);
      if (FAILED(hr))
          goto error;

      // Get a pointer to the elements of the array.
      hr = SafeArrayAccessData(psa, (void HUGEP* FAR*)&pbstr);
      if (FAILED(hr))
         goto error;

      // Bubble sort.
      cElements = lUBound-lLBound+1;
      for (i = 0; i < cElements-1; i++)
      {
         min = i;
         for (j = i+1; j < cElements; j++)
         {
            // NULL is a valid value for a BSTR. This code treats a NULL
            // BSTR as less than other string values.
            if (pbstr[min] == NULL)
               continue;
            else if (pbstr[j] == NULL
               || wcscmp(pbstr[j], pbstr[min]) < 0)
               min = j;
         }

         //Swap array[min] and array[i].
         bstrTemp = pbstr[min];
         pbstr[min] = pbstr[i];
         pbstr[i] = bstrTemp;
      }

      hr = SafeArrayUnaccessData(psa);
      if (FAILED(hr))
         goto error;

      return GetTickCount()-dwTimeStart;

   error:

      AfxThrowOleDispatchException(1003,
        "Unexpected Failure in FastSort method");
      return 0;

   }
				


?? ?? ?? ???? ??? ????? ?? ??????? ????? ?? ??????? ????? ?? ?? ????? ????? ???, ?? ??? ???? ?????????? ??? ??????? ???? ?? ??? ?? ??? ??? ?????? Visual Basic 6.0 ?????, ?? Visual Basic 6.0 ?? ??? ??? ????????? ?????? ??????? ?? ?? ??? ?? ????, ?? ????? ??? ?? ??? ???? ?? ??? ?????? ??????? ????:

   Private Sub Command1_Click()
      Dim o As Object
      Dim v As Variant
      ReDim v(50) As String
      Dim SortTime As Long

      Set o = CreateObject("StrArray.Document")

      upperbound = 1
      lowerbound = 100
      For n = 0 To 50
          v(n) = "Entry " & Int((upperbound-lowerbound+1)*Rnd+lowerbound)
      Next n

      SortTime = o.Sort(v)
      MsgBox ("Done")
   End Sub
				


Visual Basic 6.0 ??? ??? ???? ?? ??? ?? ???????? ??????? ???? ?? ??? ????? ?? ??? ??? ?? variant ???? ?? ???? Dim ???? ?? ??? ??, ?? ?? ReDim ?? ?? ?? ?? variant ?????????? ?? ??? ???? ???? ?? ???? ??? ?? ?? ????? ?? ???? ???? ?? ??? ????? ???? Visual Basic 6.0 ??? ??? ????? ????? ??? ???? ?? ???? ?? ??? ??? ?? ????? ???? ?? ???? Visual Basic 6.0 ????????? ?????, Command1 ????? ????, ?? ????? ?? v ?? ??? ???? ???? ?? ??? ??? ????? ?? ????? ?????

??????

???? ??????? ?? ???, Microsoft ?????? ??? ??? ???? ????? ?? ??? ????? ???? ???????? ????? ????::
122287Visual Basic 3.0 ?? ?????? ?? ??????? ???????? ?? ??? ??? Disptest
131046Binary.exe OLE ??????? ?? ????? ???? ??? ??????? ???? ??????????? ???? ??
131086??????? ??? ???????? ???????? ?? ????? ????
140202MFCArray MFC ??????? ??? ???????? ???????? ?? ????? ????
122289OLE ??????? ??? ???????? ??? ?? ??? ??
154172??? ActiveX ???????? ?? VB ?? ??? ??????? ???? ?? ??? ???? ?? ??? ???? ????
Microsoft ???????? ???????? 1996 ??, Don ?????? "Q&A OLE" ??????

(?) Microsoft Corporation 1997, ??? ?????? ????????? ???????? Shawn W. Karr, Microsoft Corporation ?????? ???

???

???? ID: 167668 - ????? ???????: 02 ?????? 2010 - ??????: 4.0
???? ???? ???? ??:
  • Microsoft Foundation Class Library 4.2, ?? ???? ??? ?????? ???? ???:
    • Microsoft Visual C++ 2.1
    • Microsoft Visual C++ 2.2
    • Microsoft Visual C++ 4.0 Standard Edition
    • Microsoft Visual C++ 4.2 Enterprise Edition
    • Microsoft Visual C++ 5.0 Enterprise Edition
    • Microsoft Visual C++ 5.0 Professional Edition
    • Microsoft Visual C++ .NET 2002 Standard Edition
  • Microsoft Visual C++ .NET 2003 Standard Edition
??????: 
kbautomation kbFAQ kbhowto kbmt KB167668 KbMthi
???? ?????? ????????
??????????: ?? ???? ?? ???? ??????? ?? ????? ?? Microsoft ????-?????? ?????????? ?????? ?????? ???? ??? ??. Microsoft ???? ??? ????-???????? ?? ????-???????? ????? ?????? ?? ???? ???????? ???? ?? ???? ????? ????? ??? ?? ??? ?????? ?? ???? ???? ???? ??? ????? ??. ???????, ????-???????? ???? ????? ???? ???? ???? ???. ?????, ????????, ?????-???? ?? ??????? ?? ???????? ?? ???? ???, ???? ?? ??? ?????? ???? ???? ??? ????? ??? ?? ???? ??. Microsoft ??????? ??? ???? ?? ?????? ?? ??????????, ????????? ?? ??? ?????? ?? ???? ????? ?? ???? ???????? ?? ??? ???? ????? ?? ??? ????????? ???? ??. Microsoft ????-?????? ?????????? ?? ????? ?????? ?? ?? ??? ??.
?????????? ?? ??????? ????????? ??????? ??:167668

??????????? ???

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com