473,545 Members | 2,291 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to convert SafeArray to array ?

in my script file , i need call a method of a atl com
module(implemen ted in vc++), which returan an safearray. i don't know
how to convert it into array in jscript. i have tried serveral ways to
get each item but failed at last. could anyone help me?

Jan 24 '06 #1
10 11084
VK

thinktwice wrote:
in my script file , i need call a method of a atl com
module(implemen ted in vc++), which returan an safearray. i don't know
how to convert it into array in jscript. i have tried serveral ways to
get each item but failed at last. could anyone help me?


SafeArray is Microsoft specific, so you cannot handle it by JavaScript,
only by JScript (IE).

JScript has VBArray object wrapper for safe arrays.

var arr = (new VBArray(mySafeA rray)).toArray( );

arr now contains mySefeArray converted into standard JavaScript jagged
sparse array.

Jan 24 '06 #2
this is definition of the method
[ propget...]
get_mySafeArray (VARIANT *pval);

i tried
new VBArray(mySafeA rray()) but failed

Jan 24 '06 #3
VK

thinktwice wrote:
this is definition of the method
[ propget...]
get_mySafeArray (VARIANT *pval);

i tried
new VBArray(mySafeA rray()) but failed


On what side (client or server) did you try? VBArray has sense only on
client side and only in the context of JScript.

Also it is IE-exclusive. Your server side should return instead
standard JavaScript array or JSON object (if AJAX) to easy handle it on
client side.

Jan 24 '06 #4
hi, VK. thanks for your reply.
i do use Jscript now.

try{
var arr = (new VBArray(myobj.m ySafeArray)).to Array();
}
catch(e)
{
e.errorno;//0x800A1395
}

Jan 24 '06 #5
here is the code in server side
STDMETHOD(mySaf eArray)(VARIANT *pVal)
{
CComSafeArray<l ong> arr;
i = 5;
while(i-- > 0)
{
hr = arr.Add(i);
}
CComVariant vtRet;
LPSAFEARRAY pCopy;
if (arr.m_psa != NULL)
{
HRESULT hRes = ::SafeArrayCopy (arr.m_psa, &pCopy);
if (SUCCEEDED(hRes ) && pCopy != NULL)
{
::SafeArrayGetV artype(arr.m_ps a, &(vtRet.vt)) ;
vtRet.vt |= VT_ARRAY;
vtRet.parray = pCopy;
}
else
{
vtRet.vt = VT_ERROR;
vtRet.scode = hRes;
}
}
return vtRet.Detach(pV al);
}

Jan 24 '06 #6
VK

thinktwice wrote:
here is the code in server side
STDMETHOD(mySaf eArray)(VARIANT *pVal)
{
CComSafeArray<l ong> arr;
i = 5;
while(i-- > 0)
{
hr = arr.Add(i);
}
CComVariant vtRet;
LPSAFEARRAY pCopy;
if (arr.m_psa != NULL)
{
HRESULT hRes = ::SafeArrayCopy (arr.m_psa, &pCopy);
if (SUCCEEDED(hRes ) && pCopy != NULL)
{
::SafeArrayGetV artype(arr.m_ps a, &(vtRet.vt)) ;
vtRet.vt |= VT_ARRAY;
vtRet.parray = pCopy;
}
else
{
vtRet.vt = VT_ERROR;
vtRet.scode = hRes;
}
}
return vtRet.Detach(pV al);
}


Truthfully I am not a VBArray expert as I almost never had to use it.
But in any case it's *VB*Array (Visual Basic Array)

Therefore your only options are:
1) Use VBScript on client side instead of JScript (this naturally
exclude all browsers by IE)
2) Use VBScript helper together with JScript - so safe array would come
first to VBScript which understand safe array format - and convert it
later to JavaScript array (this naturally exclude all browsers but IE)
3) Change your server-side procedure so it would return JavaScript
array. I don't see really any problems with the latter (?)

Jan 24 '06 #7
thanks VK. i just wonder why the debug window could show the array
content correctly. if it could achieve this, i guess i would get the
content out of the safearray too.
again thank you for taking time to answer my question .:)

Jan 24 '06 #8
VK

thinktwice wrote:
i just wonder why the debug window could show the array
content correctly.


I guess because any data type (known or unknown) is still internally a
sequence of characters / bytes. System may do not know how to handle
it, but still can display it as some text. (?)

Jan 24 '06 #9
thinktwice wrote:
i do use Jscript now.

try{
var arr = (new VBArray(myobj.m ySafeArray)).to Array();
}
catch(e)
{
e.errorno;//0x800A1395
}


There is no `errorno' property, the Error object property indicating the
numeric value associated with an error in JScript is `number'.[1] And
using it in this way does exactly nothing but evaluating the value of the
property. Furthermore, this will break in JScript/IE before version 5.

Think twice.
PointedEars
___________
[1]
<URL:http://msdn.microsoft. com/library/en-us/jscript7/html/jspronumber.asp >
Jan 24 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
10305
by: Roland Moschel | last post by:
Hi there ! I have some Problems to get a SafeArray out of a COM Server written in (Unmanaged) C++. From (unmanaged) Visual Basic , everything is ok , but unfortunately in C# I get an exception. Can anybody help me ?
6
17287
by: Petar Popara | last post by:
I need some help converting byte into Array: int bufferLen = Convert.ToInt32(file.Length); byte buffer = new byte; int len = sr.Read(buffer, 0, bufferLen); ArrayList a = new ArrayList(len); a.Add(buffer); Array result = a.toArray();
5
6921
by: Tronster Hartley | last post by:
I've written an ATL 7.1 component and have a C# 1.1 client that is consuming it. The ATL component has a method with a that returns a SAFEARRAY of INTs, but my C# component chokes on it. The C# code: // Display a message box with a value from the ATL control private void GoButton_Click(object sender, System.EventArgs e) {
1
6009
by: Brendan Grant | last post by:
I’ve got a C# library that I’ve built into a COM component that will be used from a VC++ 6 application and while the creation of the COM object side of things seem to be working fine, using the object fully is another matter. On the C# side of things I’ve got an object defined like so: public class PID : IPID { private string...
5
6338
by: Maxim | last post by:
Hi all, I'm calling a COM Interface method that returnes SafeArray wrapped into variant. Is it possible to convert it to managed array? Because working with SAFEARRAY directly is a bit complicated. Or maybe there is a managed wrapper class for safe array? Thanks in advance.
1
2819
by: Christian Schmidt | last post by:
Hi all, I need to implement an unmanaged function that gets a SafeArray and hands it over to a managed function having the managed array-type. Using MarshalAs I can call unmanaged functions having SafeArray from managed code. But here I need this vice-versa... I assume it is doable with MarshalAs magic, but how? Thanks Christian
2
4122
by: Simply_Red | last post by:
I'm using VC6. i have a DLL written in VC6 and used by VB6( and VBA Excel), i use SafeArray as parameter, the array is created(declared), in VB and C++ fill it. now i need VC++ to get an array of array of different sizes, and VB can't know the size of these arrays, so the arrays will be 'created' in VC. here the code that i use(and it...
4
6534
by: Steven Blair | last post by:
I have some C++ code which creates a SafeArray and passes it to my C# dll using COM: SAFEARRAY *psaOut = SafeArrayCreateVector(VT_BSTR, 0, 3); VARIANT pVarOut; VariantInit(&pVarOut); pVarOut.vt = VT_ARRAY | VT_BSTR; pVarOut.parray = psaOut;
0
3206
skeptics
by: skeptics | last post by:
Trying to pass a SafeArray that i get form Request.BinaryRead Method in classic asp to a c# com interop component. In this thread i found a solution to pass and cast a normal asp safearray in to a c# array: http://bytes.com/groups/net/114755-passing-safearray-bytes-vbscript-managed-com-object-c#goto_threadtools but no matter what i try. i cant...
0
7398
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7656
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7805
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7416
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7752
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5969
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
4944
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3449
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1878
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.