Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to use Variant to pass array from C++ client to VFP
Message
From
31/03/2011 08:01:55
 
General information
Forum:
Visual FoxPro
Category:
COM/DCOM and OLE Automation
Environment versions
Visual FoxPro:
VFP 9 SP1
OS:
Windows 7
Network:
Windows 2003 Server
Database:
Visual FoxPro
Application:
Desktop
Miscellaneous
Thread ID:
01505541
Message ID:
01505664
Views:
45
>I have created an EXE COM server in VFP that contains a function that accepts an array from the client, and fills that array with data. The array should be an array of byte, but for now, I would be happy if I could get an array of any data type to work.
>
>I have gotten this to work with a VFP client, but not with a C++ client.
>
>When I use a function statement that defines the incoming array as char @, C++ generates a wrapper from the TypeLib of the COM server that says the calling sequence is a VARIANT*. But, this doesn't work.
>
>Today, I thought that since C++ was sending a Variant, I would try declaring the function as follows:
>
>   FUNCTION GetFBDBlob(nFileID AS Integer, aBlobData AS Variant ) AS Integer
>
>This works with the VFP client when I call with a reference to a char array, like so:
>
>   DIMENSION aBlobData[nFileSize] AS char
>   nResult = oFBD.GetFBDBlob(nFileID, @aBlobData)
>
>
>In C++ I use the following code to set up a Variant and pass it to GetFBDBlob
>
>	SAFEARRAY* pSA = SafeArrayCreateVectorEx(VT_UI1, 0, nFileSize, NULL);
>	VARIANT vaBlobData;
>	VariantInit(&vaBlobData);
>	vaBlobData.vt = VT_ARRAY | VT_BYREF | VT_UI1;
>	vaBlobData.pparray = &pSA;
>	lResult = pFBDDBA->GetFBDBlob(nFileID, vaBlobData);
>
>
>I have also tried a variation of this:
>
>	SAFEARRAY* pSA = SafeArrayCreateVectorEx(VT_UI1, 0, nFileSize, NULL);
>	VARIANT vaBlobData;
>	VariantInit(&vaBlobData);
>	vaBlobData.vt = VT_ARRAY | VT_UI1;
>	vaBlobData.parray = pSA;
>	lResult = pFBDDBA->GetFBDBlob(nFileID, vaBlobData);
>
>
>GetFBDBlob() contains a call to ALEN right at the beginning: ALEN(aBlobData)
>
>While this works in VFP, either of my two formulations in the C++ client gets an error saying "ABLOBDATA is not an array"
>
>I have also modified this so that the VFP COM server is expecting a reference to a Variant. That also works with the VFP client, but not with the C++ client passing a pointer to the Variant.
>
>Surely there must be some syntax that allows me to pass an array by reference into a VFP COM server. Does anyone know what it is?
>
>Or, does anyone know of a strategy that will let me see where this is failing in VFP?
>
>Thanks,
>Jim

Can you pass a comma delimited string and have VFP put it into an array using ALINES() ? Just curious...

I do receive an array in VFP (and also in other places a variant which is seen in VFP as a collection and I have to reference it first and then step through it so it comes in as an 'object' that I process like a collection in VFP) from a C# com interop dll in some code, but that doesn't seem to be your situation....
.·*´¨)
.·`TCH
(..·*

010000110101001101101000011000010111001001110000010011110111001001000010011101010111001101110100
"When the debate is lost, slander becomes the tool of the loser." - Socrates
Vita contingit, Vive cum eo. (Life Happens, Live With it.)
"Life is not measured by the number of breaths we take, but by the moments that take our breath away." -- author unknown
"De omnibus dubitandum"
Previous
Reply
Map
View

Click here to load this message in the networking platform