CFanatic

Go Back   CFanatic > Programming > MFC Programming

Join CFanatic Forum Now

code on passing array from MFC ActiveX to Jscript... topic posted under MFC Programming which is a part of Programming category in CFanatic Forum
Reply
 
Thread Tools Display Modes
  #1  
Old 06-27-2007, 02:34 AM
Junior Member
 
Join Date: May 2007
Location: 爱国者同盟 Chinese Patriot League
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
冯锦华 is on a distinguished road
| More
Lightbulb code on passing array from MFC ActiveX to Jscript...

Code:
alst=document.getElementById("ListBox1");

alst.addItem(alst,"yyyyyyyy",      "666");
alst.removeItem(alst,2);

asb =alst.getItems(alst);


asj = new VBArray( asb ).toArray();

window.alert(asj[0]);
window.alert(asj[1]);
window.alert(asj[2]);

window.alert(asj[3]);
window.alert(asj[4]);
window.alert(asj[5]);

window.alert(asj[6]);
window.alert(asj[7]);
window.alert(asj[8]);

http://msdn2.microsoft.com/en-us/library/xc634c13.aspx
The conversion translates the multidimensional VBArray into a single dimensional JScript array.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
^^in the idl^^
Code:
	[ uuid(CB35E5F2-...) ]
	dispinterface IMyList
	{
...
methods:
		[id(5), helpstring("方法getItem")] VARIANT getItem(IDispatch* jjj, LONG kkk);
	};

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
^^in The CPP^^
Code:
BEGIN_DISPATCH_MAP(CUFList, CListBox)
...
	DISP_FUNCTION_ID(CUFList, "getItem", dispidgetItem, getItem, VT_VARIANT, VTS_DISPATCH VTS_I4)
END_DISPATCH_MAP()


VARIANT CmYList::getItem(IDispatch* ooo, LONG iii)
{
	AFX_MANAGE_STATE(AfxGetStaticModuleState());

    USES_CONVERSION;

    HRESULT hr= S_OK;

	VARIANT * pGIV = new VARIANT;
	VariantInit(pGIV); // WARNING You must initialize *pVal before calling Detach

    // Create SafeArray of VARIANT BSTRs
    SAFEARRAY *pSA;
    SAFEARRAYBOUND aDim[1];
    aDim[0].lLbound= 0;
    aDim[0].cElements= 3;
    pSA= SafeArrayCreate(VT_VARIANT,1,aDim);

    if (pSA != NULL) {
		_variant_t vOut;
		CString strIII;
		long l =0;	

			GetText(iii,strIII);	
            vOut= A2W(strIII);
            if (hr= SafeArrayPutElement(pSA, &l, &vOut)) {
                SafeArrayDestroy(pSA); // does a deep destroy
                return * pGIV;
            }
            l++;

			strIII.Format("%d", (int)GetItemData(iii));
            vOut= A2W(strIII);
            if (hr= SafeArrayPutElement(pSA, &l, &vOut)) {
                SafeArrayDestroy(pSA); // does a deep destroy
                return * pGIV;
            }
            l++;
					
			strIII.Format("%d", (int)GetSel(iii));
            vOut= A2W(strIII);
            if (hr= SafeArrayPutElement(pSA, &l, &vOut)) {
                SafeArrayDestroy(pSA); // does a deep destroy
                return * pGIV;
            }
    }


V_VT(pGIV)= VT_ARRAY | VT_VARIANT; //pVal->vt= VT_ARRAY | VT_VARIANT; // oleauto.h
V_ARRAY(pGIV)= pSA; // (pSA may be null) //pVal->parray= pSA; // oleauto.h
return *  pGIV;
}

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
^^IN THE H^^
Code:
	enum 
	{
		dispidgetItem = 5L,	...
	};
	VARIANT getItem(IDispatch* ooo, LONG iii);

Last edited by 冯锦华; 06-29-2007 at 12:30 AM.
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
1-dimensional array type double.....and....2-dimensional array styles8687 C++ Programming 2 01-01-2009 04:30 AM
passing arrays in C# Xarzu C# Programming 3 09-29-2008 05:27 AM
Error passing a value_type as a reference a_new_beginning C++ Programming 0 08-15-2008 10:40 PM
transparent MFC activeX control praxisist MFC Programming 1 05-07-2008 03:15 AM
Gosh ! 2D int array trapeze C++ Programming 2 11-16-2007 05:47 AM

 

Advertisement

CFanatic Search
Custom Search

Advertisement

All times are GMT -5. The time now is 02:10 AM.



Powered by vBulletin® Version 3.7.4
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO ©2010, Crawlability, Inc.
Cfanatic.com is a premier member of the IDG TechNetwork. For advertising opportunities contact here
Get Paid for Working on Projects Matching Your Expertise at Go4Expert's Jobs Board