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

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

??????

??? ????? ??? ??????? ?????? ??? ????? SafeArrays ??? Visual C++ ? Visual Basic 6.0 ???? ????? SafeArray ?? ????? ???? VARIANT. ?? MFC ? ??? ????? ??? ????? "VARIANT const & ??? ???????".

?????? ????? ??????? ??? ??????? ????? ????? VARIANT * ? ???? ?? MFC ??? ???? ?? ?? ????? ?????? "FAR VARIANT * varname".

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

??????? ????

??? ??? ??? ??????? ? ???? ????? "MFC AppWizard(exe)" ???? ???? StrArray. ?? "?????? 3 ?? 6" ? ??? ??????? ???? ??? ????? ?? ???? ??? ????? ?????? ????? ???????.

??????: ??????? 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*
				


???? ??? "?????" ? "????? ????????? ????????.

?????? ????? ??? ??????? ??????? FastSort ???? MFCARRAY ???????? ?? ??? "???????" ?????. ????? ?? ??? ??????? ?????????? ??? ????? ??????? ?????? "VARIANT const & ??? ???????" ? "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 ??? Dim ????? ????? ?????? ?????? ???? ReDim ???? ???? ????? ????? ??? ???? ?????. ??? ???? ???? ??????? ??????. ????? ???? ???? ?? ????????? ???????? Visual Basic 6.0 ??? ???? ??????? ???. ????? ????? Visual Basic 6.0 ???? ??? Command1 ?? ??????? ???? ???????? ??? ???? ?? ??? v.

?????

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

(?) ???? ???? Microsoft ? ???? ???? ?????. ????????? ??? Shawn ??? Karr ? Microsoft Corporation.

???????

???? ???????: 167668 - ????? ??? ??????: 30/????/1427 - ??????: 3.1
????? ???
  • Microsoft Foundation Class Library 4.2, ????? ?????? ??:
    • Microsoft Visual C++ 2.0 Professional Edition
    • Microsoft Visual C++ 2.1
    • Microsoft Visual C++ 2.2
    • Microsoft Visual C++ 4.0 Standard Edition
    • Microsoft Visual C++ 4.0 Standard Edition
    • Microsoft Visual C++ 4.1 Subscription
    • Microsoft Visual C++ 4.2 Professional Edition
    • Microsoft Visual C++ 4.2 Enterprise Edition
    • Microsoft Visual C++ 5.0 Enterprise Edition
    • Microsoft Visual C++ 6.0 Enterprise Edition
    • Microsoft Visual C++ 4.2 Professional Edition
    • Microsoft Visual C++ 5.0 Professional Edition
    • Microsoft Visual C++ 6.0 Professional Edition
    • Microsoft Visual C++, 32-bit Learning Edition 6.0
    • Microsoft Visual C++ .NET 2002 Standard Edition
  • Microsoft Visual C++ .NET 2003 Standard Edition
????? ??????: 
kbmt kbautomation kbfaq kbhowto KB167668 KbMtar
????? ????
???: ??? ????? ??? ?????? ???????? ?????? ????? ???? ????? ?????????? ????? ?? ????????? ?????? ????. ???? ???? ?????????? ???? ?? ???????? ???????? ?????? ????????? ????? ????????? ???????? ????? ???????? ?????? ?? ?????? ??? ?? ???????? ???????? ?? ????? ??????? ?????? ??? ??????? ?????? ??. ?????? ?? ???? ??? ??????? ???????? ????? ?? ???? ????? ?????? ??? ????? ??? ????? ??????? ?? ????? ?? ?????? ??? ??? ??????? ??????? ?? ????? ????? ????? ????? ?????. ?? ????? ???? ?????????? ??????? ??? ????? ?? ??????? ?? ????? ?????? ?? ??? ????? ?? ????? ??????? ?? ???????? ?? ??? ???????. ???? ???? ?????????? ???????? ??? ????? ?????? ??????? ??????
???? ??? ????? ??????? ?????? ??????????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