Click here to Skip to main content
16,012,223 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
Questionsave complete web page(html,gif et al) Pin
shuchigo_jane15-Jun-06 18:49
shuchigo_jane15-Jun-06 18:49 
AnswerRe: save complete web page(html,gif et al) Pin
Ganesh_T15-Jun-06 19:00
Ganesh_T15-Jun-06 19:00 
QuestionDatabase Connection Pin
velayudhan_raj15-Jun-06 18:41
velayudhan_raj15-Jun-06 18:41 
AnswerRe: Database Connection Pin
_AnsHUMAN_ 15-Jun-06 18:44
_AnsHUMAN_ 15-Jun-06 18:44 
GeneralRe: Database Connection Pin
velayudhan_raj15-Jun-06 18:48
velayudhan_raj15-Jun-06 18:48 
QuestionSafe Array Pin
satsumatable15-Jun-06 18:21
satsumatable15-Jun-06 18:21 
AnswerRe: Safe Array Pin
alan top15-Jun-06 18:50
alan top15-Jun-06 18:50 
AnswerRe: Safe Array Pin
Laxman Auti15-Jun-06 22:44
Laxman Auti15-Jun-06 22:44 
sivaprakashshanmugam wrote:
I have the following prototype in ActiveX to send the Array from my client program. The variable VarArray contains array of values, Can you please provide me an example to get the values of each index by using SafeArray.

Here m_vecIcecreamFlavors and m_vecIcecreamPrices are vecters of BSTR and float resp.

//Initialize the bounds for the array<br />
	//Ours is a 2 dimensional array<br />
	SAFEARRAYBOUND safeBound[2]; <br />
	<br />
	//Set up the bounds for the first index<br />
	//That's the number of flavors that we have<br />
	safeBound[0].cElements = m_vecIcecreamFlavors.size();    <br />
	safeBound[0].lLbound = 0;<br />
<br />
	//Set up the bounds for the second index<br />
	safeBound[1].cElements = m_vecIcecreamPrices.size();<br />
	safeBound[1].lLbound = 0 ;<br />
<br />
	<br />
	///Initialize the VARIANT<br />
	VariantInit(VarArray);<br />
	//The array type is VARIANT<br />
	//Storage will accomodate a BSTR and a float<br />
	pVariant->vt = VT_VARIANT | VT_ARRAY; <br />
	pVariant->parray = SafeArrayCreate(VT_VARIANT,2,safeBound);<br />
	<br />
	<br />
	//Initialize the vector iterators<br />
	std::vector<CComBSTR>::iterator iterFlavor;<br />
	std::vector<float>::iterator iterPrices;<br />
<br />
<br />
	<br />
	//Used for indicating indexes in the Multidimensional array<br />
	long lDimension[2];<br />
	int iFlavorIndex = 0;<br />
<br />
	<br />
	//Start iteration<br />
	iterPrices = m_vecIcecreamPrices.begin();<br />
	iterFlavor = m_vecIcecreamFlavors.begin(); <br />
<br />
<br />
	//Iterate thru the list of flavors and prices<br />
	while(iterFlavor != m_vecIcecreamFlavors.end()) <br />
	{<br />
<br />
		<br />
		//Put the Element at (0,0), (0,1)  , (0,2) ,.............(0,n)<br />
		lDimension[1] = iFlavorIndex;<br />
		lDimension[0] = 0;<br />
		CComVariant variantFlavor(SysAllocString((*iterFlavor).m_str));<br />
		SafeArrayPutElement(pVariant->parray,lDimension,&variantFlavor);<br />
<br />
	<br />
		<br />
		//Put the Element at (1,0), (1,1)  , (1,2) ,.............(1,n)<br />
		lDimension[1] = iFlavorIndex;<br />
		lDimension[0] = 1;<br />
		CComVariant variantPrices(*iterPrices);<br />
		SafeArrayPutElement(pVariant->parray,lDimension,&variantPrices);<br />
	<br />
		<br />
		iFlavorIndex++;<br />
		iterPrices++;<br />
		iterFlavor++;<br />
		<br />
<br />
	}


Suppose Variant result is parameter passed for fillup then we can retrive the elements from the array as follows.

long lUDimension,lLDimension;<br />
    <br />
    SafeArrayGetUBound(result->parray,2,&lUDimension);<br />
    SafeArrayGetLBound(result->parray,2,&lLDimension);<br />
    VARIANT val[2];<br />
    long Dimension[2];<br />
    <br />
    for(LONG i=lLDimension;i<=lUDimension;i++)<br />
    {<br />
        m_Data.InsertItem(i," ");<br />
        Dimension[0]=0;<br />
        Dimension[1]=i;    <br />
        HRESULT hr=SafeArrayGetElement(result->parray,Dimension,(void*)&val[0]);<br />
        if(FAILED(hr))<br />
            AfxMessageBox("Unable to read 1 element");<br />
               m_Data.SetItemText(i,0,_com_util::ConvertBSTRToString(val[0].bstrVal));<br />
        Dimension[0]=1;<br />
        Dimension[1]=i;    <br />
        hr=SafeArrayGetElement(result->parray,Dimension,(void*)&val[1]);<br />
        if(FAILED(hr))<br />
            AfxMessageBox("Unable to read 2 element");<br />
        m_Data.SetItemText(i,1,_com_util::ConvertBSTRToString(val[1].bstrVal));<br />
}


Knock out 't' from can't,
You can if you think you can
Cool | :cool:
Questionlistboxctrl update Pin
locoone15-Jun-06 17:41
locoone15-Jun-06 17:41 
AnswerRe: listboxctrl update Pin
Naveen15-Jun-06 18:24
Naveen15-Jun-06 18:24 
GeneralRe: listboxctrl update Pin
locoone16-Jun-06 11:36
locoone16-Jun-06 11:36 
AnswerRe: listboxctrl update Pin
Ganesh_T15-Jun-06 18:39
Ganesh_T15-Jun-06 18:39 
GeneralRe: listboxctrl update Pin
locoone16-Jun-06 12:16
locoone16-Jun-06 12:16 
AnswerRe: listboxctrl update Pin
Laxman Auti15-Jun-06 22:53
Laxman Auti15-Jun-06 22:53 
GeneralRe: listboxctrl update Pin
locoone16-Jun-06 12:21
locoone16-Jun-06 12:21 
GeneralRe: listboxctrl update Pin
Naveen16-Jun-06 18:17
Naveen16-Jun-06 18:17 
GeneralRe: listboxctrl update Pin
locoone16-Jun-06 21:44
locoone16-Jun-06 21:44 
GeneralRe: listboxctrl update Pin
Naveen16-Jun-06 22:17
Naveen16-Jun-06 22:17 
GeneralRe: listboxctrl update [modified] Pin
locoone16-Jun-06 22:27
locoone16-Jun-06 22:27 
QuestionI need gSpan source code ( C or Linux without graphic)! Pin
abiisalwayshappy15-Jun-06 17:40
abiisalwayshappy15-Jun-06 17:40 
AnswerRe: I need gSpan source code ( C or Linux without graphic)! Pin
NiceNaidu15-Jun-06 19:51
NiceNaidu15-Jun-06 19:51 
GeneralRe: I need gSpan source code ( C or Linux without graphic)! [modified] Pin
abiisalwayshappy19-Jun-06 18:24
abiisalwayshappy19-Jun-06 18:24 
GeneralRe: I need gSpan source code ( C or Linux without graphic)! Pin
linnumberone12-Feb-12 20:29
linnumberone12-Feb-12 20:29 
QuestionWIN32 API to find out color monitor v/s monochrome monitor Pin
rajandpayal15-Jun-06 16:00
rajandpayal15-Jun-06 16:00 
AnswerRe: WIN32 API to find out color monitor v/s monochrome monitor Pin
NiceNaidu15-Jun-06 19:56
NiceNaidu15-Jun-06 19:56 

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.