MohdAsalah
asked on
How can I define two dimentional SAFEARRAY?
How can I define two dimentional SAFEARRAY of type integer?
I assume you're talking COM. Well, you use SafeAffayCreate (look in MSDN library). There's an example here
http://support.microsoft.com/support/kb/articles/Q182/8/31.ASP
(using VT_VARIANT - you'll have to use VT_UI1 for ints).
Have a look here, too:
http://community.borland.com/article/0,1410,22016,00.html
you should have something like this.
<altered version of that MSDN link>
SAFEARRAY FAR* psa;
SAFEARRAYBOUND rgsabound[2];
rgsabound[0].lLbound = 0;
rgsabound[0].cElements = 3;
rgsabound[1].lLbound = 0;
rgsabound[1].cElements = 3;
psa = SafeArrayCreate(VT_UI1, 2, rgsabound);
http://support.microsoft.com/support/kb/articles/Q182/8/31.ASP
(using VT_VARIANT - you'll have to use VT_UI1 for ints).
Have a look here, too:
http://community.borland.com/article/0,1410,22016,00.html
you should have something like this.
<altered version of that MSDN link>
SAFEARRAY FAR* psa;
SAFEARRAYBOUND rgsabound[2];
rgsabound[0].lLbound = 0;
rgsabound[0].cElements = 3;
rgsabound[1].lLbound = 0;
rgsabound[1].cElements = 3;
psa = SafeArrayCreate(VT_UI1, 2, rgsabound);
//like int arr[8][4];
HRESULT hres;
SAFEARRAY * psaiNew;
SAFEARRAYBOUND aDim[2];
aDim[0].lLbound = 0;
aDim[0].cElements = 7;
aDim[1].lLbound = 0;
aDim[1].cElements = 3;
psaiNew = SafeArrayCreate(VT_I2, 2, aDim);
if (psaiNew == NULL) throw ERROR_NOT_ENOUGH_MEMORY;
//use array ....
//.....
//destroy!
if (hres = SafeArrayDestroy(psaiNew)) throw hres;
HRESULT hres;
SAFEARRAY * psaiNew;
SAFEARRAYBOUND aDim[2];
aDim[0].lLbound = 0;
aDim[0].cElements = 7;
aDim[1].lLbound = 0;
aDim[1].cElements = 3;
psaiNew = SafeArrayCreate(VT_I2, 2, aDim);
if (psaiNew == NULL) throw ERROR_NOT_ENOUGH_MEMORY;
//use array ....
//.....
//destroy!
if (hres = SafeArrayDestroy(psaiNew))
ASKER
That's fine but how can I fill this array ,I mean how can I use SafeArrayPutElement API function in this two dimentional array.
ASKER
That's fine but how can I fill this array ,I mean how can I use SafeArrayPutElement API function in this two dimentional array.
//like int arr[8][4];
HRESULT hres;
SAFEARRAY * psaiNew;
SAFEARRAYBOUND aDim[2];
aDim[0].lLbound = 0;
aDim[0].cElements = 7;
aDim[1].lLbound = 0;
aDim[1].cElements = 3;
psaiNew = SafeArrayCreate(VT_I2, 2, aDim);
if (psaiNew == NULL) throw ERROR_NOT_ENOUGH_MEMORY;
//use array ....
//.....
//destroy!
if (hres = SafeArrayDestroy(psaiNew)) throw hres;
HRESULT hres;
SAFEARRAY * psaiNew;
SAFEARRAYBOUND aDim[2];
aDim[0].lLbound = 0;
aDim[0].cElements = 7;
aDim[1].lLbound = 0;
aDim[1].cElements = 3;
psaiNew = SafeArrayCreate(VT_I2, 2, aDim);
if (psaiNew == NULL) throw ERROR_NOT_ENOUGH_MEMORY;
//use array ....
//.....
//destroy!
if (hres = SafeArrayDestroy(psaiNew))
for(long i =0; i < 4; i++)
{
for(long j=0; j < 8; j++)
{
int someVal = 4; //some value
//j means dimension
::SafeArrayPutElement(psai New,&j, &someVal);
}
}
{
for(long j=0; j < 8; j++)
{
int someVal = 4; //some value
//j means dimension
::SafeArrayPutElement(psai
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
>>How can I define two dimentional SAFEARRAY of type integer?
... solution ...
>> That's fine but how can I fill this array?
Normally this would be a different question, especially if the original question is 5 times easier than an easy question. Please don't take this the wrong way - I'm just giving my opinion.
... solution ...
>> That's fine but how can I fill this array?
Normally this would be a different question, especially if the original question is 5 times easier than an easy question. Please don't take this the wrong way - I'm just giving my opinion.
ASKER
This Comment to lainHere:
If the first question is 5 times easier than an easy question why u do not complete ur answer.
and please keep your opinion to yourself.
If the first question is 5 times easier than an easy question why u do not complete ur answer.
and please keep your opinion to yourself.
Interesting. As you will have been advised when you asked the question, 50 points = easy question; 100 points = moderate question; 200 points = difficult question.
>> If the first question is 5 times easier than an easy question
I was referring to the number of points you put up. 10 points = 1/5 of easy question.
>> why u do not complete ur answer.
I did. You will notice that the SafeArrayCreate function call I made did what you asked in your original question.
>>keep your opinion to yourself.
>>Please don't take this the wrong way
:-)
>> If the first question is 5 times easier than an easy question
I was referring to the number of points you put up. 10 points = 1/5 of easy question.
>> why u do not complete ur answer.
I did. You will notice that the SafeArrayCreate function call I made did what you asked in your original question.
>>keep your opinion to yourself.
>>Please don't take this the wrong way
:-)
ASKER
That is very silly,I do not put 10 points because this <comment edited by Community Support> question is very easy but because I just have 10 points.
<comment edited by Community Support> .
<comment edited by Community Support> .
where is "the" hell?
MohdAsalah We do not allow profanity or flaming here at EE. Please keep your comments professional.
Thank you
Lab1
CS Moderator
Thank you
Lab1
CS Moderator
Normally you define it as
int a[10][10];
a[5][6] = 14;
You can also typedef it for convenience:
typedef int safearray[10][10];
safearray a;
a[5][6] = 14;
If the dimensions are not known at compile time, it's more difficult.