<Vi@discussions.microsoft.com> wrote in
message
news:581e6584-adef-4824-8694-b14ac4f8b5f7@discussions.microsoft.com
> I have a c++ method that accepts variant array as a parameter.
> when I pass the variant array from c# client , the value is assigned
> to Variant.parray in c++ method but when pass the variant from vb
> client the value is assigned to Variant.pparray. I want vb to assign
> value to Variant.parray and not pparray,what do I do, any ideas
> please.
news:581e6584-adef-4824-8694-b14ac4f8b5f7@discussions.microsoft.com
> I have a c++ method that accepts variant array as a parameter.
> when I pass the variant array from c# client , the value is assigned
> to Variant.parray in c++ method but when pass the variant from vb
> client the value is assigned to Variant.pparray. I want vb to assign
> value to Variant.parray and not pparray,what do I do, any ideas
> please.
I believe you enclose the parameter in parentheses on VB side, like
this:
yourObj.yourMethod (array)
This indicates pass-by-value. VB passes by reference by default.
The correct way to deal with this problem however is to modify your C++
code so that it accepts the parameter either way, depending on whether variant
type contains VT_BYREF flag.
--
With best wishes,
Igor Tandetnik
--
With best wishes,
Igor Tandetnik

VARIANT PARRAY
Edwin Jongsma
I think it doesn't matter how you get the data. You can see it in the variant type, what you get. BTW: Can you tell us the type flags given in the type field of the VARIANT.
AFAIK it depends also how you call the method from VB.
method(array) ' passes the array by value
method array ' passes the array by reference
Just read the KB article
Q142223 http://support.microsoft.com/kb/142223/en-us
HTH
GaltSalt
Many thanks for your replies.
Here is what i do,
vbmethod
Public Declare Function PassArraySample Lib "C:\MyWork\APPLICATIONS\TestSamples\Test1\Debug\Test1.dll" (ByVal Ser As String, ByVal Sym As String, ByRef varArray As Variant) As Integer
lReturn = PassArraySample("a", "b", varray)
c# ofcoure works fine.
anyideas. Thanks vi
softwarejaeger
Many thanks Martin,
I tried the last parameter in the vb func as byvalue and I get the following error:
"Unhandled exception in exe(Test1.dll):0xC0000005: Access Violation"
Any ideas please
fyi, when I pass the last parameter Byref I dont get any error but Array is assigned to pparray of the variant , but I want that to be assigned to parray of the variant.
c++ method signature
---------------------
long __declspec(dllexport) __stdcall PassArraySample( const char* szSer, const *szSym, VARIANT &pVariantArray)
SAFEARRAY * pArrayVal = pVariantArray.parray;
VARIANT *pArray = NULL;
HRESULT hr = S_OK;
long lRet = -1;
hr = SafeArrayAccessData(pArrayVal, (void HUGEP * FAR *) &pArray);
........
_______________________________________
vb method
Public Declare Function PassArraySample Lib "C:\MyWork\APPLICATIONS\TestSamples\Test1\Debug\Test1.dll" (ByVal Ser As String, ByVal Sym As String, ByVal varArray As Variant) As Integer
best reg. Vi
derek73
Hi,
I have a c++ method that accepts variant array as a parameter.
when I pass the variant array from c# client , the value is assigned to Variant.parray in c++ method but when pass the variant from vb client the value is assigned to Variant.pparray. I want vb to assign value to Variant.parray and not pparray,what do I do, any ideas please.
Many thanks in advance.
vi
integrators