Click here to Skip to main content
15,908,166 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: run an executable located in a memory buffer Pin
Terry O'Nolley21-Jul-03 1:56
Terry O'Nolley21-Jul-03 1:56 
GeneralWindows Common Dialog controls Pin
madErnie19-Jul-03 4:07
madErnie19-Jul-03 4:07 
GeneralRe: Windows Common Dialog controls Pin
Anthony_Yio20-Jul-03 16:52
Anthony_Yio20-Jul-03 16:52 
GeneralEdonkey2000 Help Pin
betengan19-Jul-03 3:51
betengan19-Jul-03 3:51 
GeneralI need an overloaded operator for VARIANT data type Pin
BabakZallaghi19-Jul-03 3:46
BabakZallaghi19-Jul-03 3:46 
GeneralRe: I need an overloaded operator for VARIANT data type Pin
Anthony_Yio20-Jul-03 16:54
Anthony_Yio20-Jul-03 16:54 
GeneralRe: I need an overloaded operator for VARIANT data type Pin
BabakZallaghi23-Jul-03 23:55
BabakZallaghi23-Jul-03 23:55 
GeneralRe: I need an overloaded operator for VARIANT data type Pin
Anthony_Yio24-Jul-03 0:37
Anthony_Yio24-Jul-03 0:37 
Hope this helps.

I guess _variant_t is not suitable for your case.
You are doing VBA right. I did Office Automation which automate Ms Excel before.

You should stick back to COleSafeArray.

The codes is in the MSDN but anyway. I paste it here so that you could refer it.

//Sort is an automation method by the CCmdTarget-derived class <br />
// CSAProjDlgAutoProxy<br />
void CSAProjDlgAutoProxy::Sort(VARIANT FAR* vArray) <br />
{<br />
   COleSafeArray sa;<br />
   BSTR *pbstr;<br />
   TCHAR buf[1024];<br />
   LONG cElements, lLBound, lUBound;<br />
  <br />
   //needed for OLE2T macro below, include afxpriv.h<br />
   USES_CONVERSION;<br />
<br />
   // Type check VARIANT parameter. It should contain a BSTR array<br />
   // passed by reference. The array must be passed by reference it is<br />
   // an in-out-parameter.<br />
   if (V_VT(vArray) != (VT_ARRAY | VT_BSTR))<br />
      AfxThrowOleDispatchException(1001, <br />
         "Type Mismatch in Parameter. Pass a string array by reference");<br />
<br />
   // clears data in sa and copies the variant data into sa<br />
   sa.Attach(*vArray);<br />
<br />
   // Check that array is 1 dimensional<br />
   if (sa.GetDim() != 1)<br />
      AfxThrowOleDispatchException(1002, <br />
         "Type Mismatch in Parameter. Pass a one-dimensional array");<br />
<br />
   try <br />
   {<br />
      // Get array bounds.<br />
      sa.GetLBound(1, &lLBound);<br />
      sa.GetUBound(1, &lUBound);<br />
<br />
      // Get a pointer to the elements of the array<br />
      // and increments the lock count on the array<br />
      sa.AccessData((LPVOID*)&pbstr);<br />
<br />
      //get no. of elements in array<br />
      cElements = lUBound-lLBound+1;<br />
      for (int i = 0; i < cElements-1; i++)<br />
      {<br />
         //output the elements of the array<br />
         wsprintf(buf, "%s", OLE2T(pbstr[i]));<br />
         OutputDebugString(buf);<br />
      }<br />
      <br />
      //decrement lock count<br />
      sa.UnaccessData();<br />
   }<br />
   catch (COleException *pEx)<br />
   {<br />
      AfxThrowOleDispatchException(1003, <br />
         "Unexpected Failure in FastSort method");<br />
      pEx->Delete();<br />
   }<br />
}


Code above shows how to retrieve the VARIANT with array type and access via sa.AccessData((LPVOID*)&pbstr). The pbstr the void* pointer.

I guess there is no easy way out. If you still like the operator[] overload. Try to write your own class by inherit this COleSafeArray;)
GeneralRe: I need an overloaded operator for VARIANT data type Pin
BabakZallaghi24-Jul-03 3:44
BabakZallaghi24-Jul-03 3:44 
Generalwho can help me?about SHAppBarMessage Pin
Hendy_So19-Jul-03 2:12
Hendy_So19-Jul-03 2:12 
Questionwhat is MakeFile? Pin
Anonymous19-Jul-03 2:04
Anonymous19-Jul-03 2:04 
AnswerRe: what is MakeFile? Pin
Nick Parker19-Jul-03 2:11
protectorNick Parker19-Jul-03 2:11 
GeneralRe: what is MakeFile? Pin
Anonymous19-Jul-03 2:19
Anonymous19-Jul-03 2:19 
GeneralRe: what is MakeFile? Pin
Mike Nordell19-Jul-03 3:58
Mike Nordell19-Jul-03 3:58 
GeneralRe: what is MakeFile? Pin
Anonymous19-Jul-03 20:18
Anonymous19-Jul-03 20:18 
GeneralRe: what is MakeFile? Pin
Anthony_Yio20-Jul-03 17:18
Anthony_Yio20-Jul-03 17:18 
GeneralRe: what is MakeFile? Pin
Anonymous20-Jul-03 22:11
Anonymous20-Jul-03 22:11 
Generaldeleting an object from a list of objects Pin
aqualite19-Jul-03 1:59
aqualite19-Jul-03 1:59 
GeneralRe: deleting an object from a list of objects Pin
Mike Nordell19-Jul-03 4:03
Mike Nordell19-Jul-03 4:03 
GeneralCDocument::OnFileSendMail, how to attach default file other than one given.. Pin
IrishSonic18-Jul-03 23:18
IrishSonic18-Jul-03 23:18 
GeneralRe: CDocument::OnFileSendMail, how to attach default file other than one given.. Pin
IrishSonic19-Jul-03 23:26
IrishSonic19-Jul-03 23:26 
Generalc++ graphics Pin
virtualspy18-Jul-03 23:15
virtualspy18-Jul-03 23:15 
GeneralRe: c++ graphics Pin
Ryan Binns19-Jul-03 0:21
Ryan Binns19-Jul-03 0:21 
GeneralRe: c++ graphics Pin
John M. Drescher19-Jul-03 18:55
John M. Drescher19-Jul-03 18:55 
GeneralRe: c++ graphics Pin
dog_spawn19-Jul-03 2:48
dog_spawn19-Jul-03 2:48 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.