Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Passing arguments to/from VFP COM server
Message
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:
01498412
Message ID:
01499396
Views:
45
I have made progress on having VFP create a type library for the VFP COM (EXE) server that specifies arguments that are ByRef. The answer: include the '@' symbol at the end of the AS clause in the procedure specification: Like so:

PROCEDURE ReadDatFiles(nPatientID AS Integer @, nVisitID AS integer @, nFileID AS integer @, sFilename AS String @) AS Variant

The C++ wrapper that gets generated in VS2005 by importing that type library is:
   VARIANT ReadDatFiles(long * nPatientID, long * nVisitID, long * nFileID, BSTR * sFilename)
   {
	VARIANT result;
	static BYTE parms[] = VTS_PI4 VTS_PI4 VTS_PI4 VTS_PBSTR ;
	InvokeHelper(0x0, DISPATCH_METHOD, VT_VARIANT, (void*)&result, parms, nPatientID, nVisitID, nFileID, sFilename);
	return result;
   }
I still haven't worked out the details of passing back the full file path in sFilename.

Again, thanks for your help.

Jim

>Thank you all for your suggestions.
>
>I have advanced my problem a bit. I have given up the idea of passing a structrue through the COM interface, and I have changed the calling sequence to the method in my COM server. Now, I pass the parameters all separately: a string, three integers, and another string.
>
>My intention is that the arguments to the method are passed "by reference", so that the COM server can pass return values back to the client through them.
>
>This works like a charm with my VFP client. As I understand it, arguments passed to procedures are automatically passed by reference in VFP. And the VFP COM server is able to return values through those arguments.
>
>But, this doesn't work with my C++ client. I am using the Visual Studio 2005 "Add a class from TypeLib" wizard. This creates a wrapper for my COM method. The wrapper shows the arguments as string, long, long, long, and string, and apparently automatically encases each into its own VARIANT in the call to the COM server.
>
>The arguments are all getting to the COM server OK, but new values are not being returned back.
>
>The problem is that the arguments in the wrapper are all "by value".
>
>If I look at the typelib of my COM server in object browser, I can see that, sure enough, the arguments to the method are all shown as ByVal.
>
>The VFP COM server seems to be treating the arguments as "by reference". However, the typelib created by building the VFP COM server shows them as "by value".
>
>My question now: is there some way to coerce VFP to output a type library that specifieds the arguments to the COM method as "By reference"?
>
>Thanks,
>Jim
>
>
>
>
>
>>I am developing EXE COM server in VFP.
>>
>>I have created a method in my server that takes two arguments. The first argument is a string, the second is an object derived from custom class. The name of the 2nd parameter in the method is "oInOut". oInOut has 4 properties: 3 integers, and a string. The intended role of oInOut is to pass values into the COM server, and to return new values back to the client.
>>
>>I have a VFP client, that calls that method in the server, passing in the two arguments as I just described. The COM server updates the values in the object, and returns them to the client successfully.
>>
>>So, this works fine with a VFP client.
>>
>>However, it does not work with a C++ client. The type library generated by VFP (as views in VFP Object Browser) specifies the second argument as "oInOut AS Variant". In the C++ client, if I create a C++ structure with the same members as the VFP custom object, and pass this to the method in the COM server (casting it as VARIANT&), I get an error when the client calls that method. The error is a System.AccessViolation exception - attempt to read or write protected memory.
>>
>>So, this strategy doesn't seem to work with C++.
>>
>>Is there a way to get this strategy to work with a C++ client?
>>I guess an alternative that should work would be to separately pass each of the 4 parameters.
>>
>>Thanks in advance for your help.
>>
>>Jim
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform