Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
WwDotNetBridge
Message
 
À
09/04/2015 03:53:50
Information générale
Forum:
Visual FoxPro
Catégorie:
Visual FoxPro et .NET
Titre:
Versions des environnements
Visual FoxPro:
VFP 9 SP2
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01617874
Message ID:
01618060
Vues:
494
This message has been marked as a message which has helped to the initial question of the thread.
Usually I would agree brevity, but in this case there are about 10 (and there will probably more) of these things and they are already handled and special cased on the ComValue object. The reasoning here is that you have the specialized behavior on the object that handles it.

Additionally you only need to assign the casts if you're using types that require them. If you're assigning a string or boolean or date there's no cast.

However, I suppose CreateComValue could accept the value (and I think it might actually be there already and I just forgot).
LOCAL loNet as Westwind.WebConnection.TypePassingTests
loNet = loBridge.Createinstance("Westwind.WebConnection.TypePassingTests")

*** Pass parameters by Reference
*** Create ComValue objects for each parameter
loInt = loBridge.CreateComValue(INT(10))
loString = loBridge.CreateComValue("Hello World.")
loDecimal = loBridge.CreateComValue(CAST( 5.22 as Currency))

? "Original:"
? loInt.Value, loString.Value, loDecimal.Value

lobridge.InvokeStaticMethod("Westwind.WebConnection.TypePassingTests",;
                            "PassByReferenceStatic",;
                            loInt,loString,loDecimal)

*** Look at the result values
? "Updated:"
? loInt.Value, loString.Value, loDecimal.Value
There are a also explicit methods that cast to types that FoxPro doesn't support:
loLong = loValue.SetLong(10)
loSingle = loValue.SetSingle(1.231)
loDbNull = loValue.SetDbNull()
which is why I tend to be explicit in the examples to make it clear that there's an object that has a number of operations you can perform on it to get around FoxPro's type limitations.

+++ Rick ---

>Rick,
>
>For my eyes that setup code is much lower than your usual well-balanced mix of brevity, clarity and functionality. Adding a few 3-liner methods (or 1-liner methods if loBridge.CreateComValue() accepts an optional tuValue Parameter) would enable you and later your users to write shorter and to my eyes more readable code and forcing a Cast in each method adds a liiiittle type security at least to the creation stage.
>
>>
>loNet = loBridge.Createinstance("Westwind.WebConnection.TypePassingTests")
>
>*** Create ComValue objects for each parameter
>loInt = loBridge.CreateComValueInt(10)
>loString = loBridge.CreateComValueString("Hello World.")
>loDecimal = loBridge.CreateComValueCurrency(5.22)
>
>
>my 0.002 €
>
>thomas
>
>>This is currently not supported. You can only use ByRef parameters if you're calling .NET directly.
>>
>>I'm adding this functionality as we speak and it'll look like this:
>>
>>
>>loNet = loBridge.Createinstance("Westwind.WebConnection.TypePassingTests")
>>
>>*** Create ComValue objects for each parameter
>>loInt = loBridge.CreateComValue()
>>loInt.Value = INT(10)
>>loString = loBridge.CreateComValue()
>>loString.Value = "Hello World."
>>loDecimal = loBridge.CreateComValue()
>>loDecimal.Value = CAST( 5.22 as Currency)
>>
>>lobridge.InvokeStaticMethod("Westwind.WebConnection.TypePassingTests",;
>>                            "PassByReferenceStatic",;
>>                            loInt,loString,loDecimal)
>>
>>*** Look at the result values
>>? loInt.Value, loString.Value, loDecimal.Value
>>
>>
>>
>>+++ Rick ---
>>
>>
>>>UPDATE. I checked your code and you're passing parameters as is, not by reference. I am wondering if I change it to pass by reference, my problem will be resolved.
>>>
>>>UPDATE 2. Just changing them in the wwDotNetBridge program to be passed by reference didn't help.
>>>
>>>Hi Rick,
>>>
>>>I have another question. The signature for the method is this
>>>
>>>
>>>static public string VerifyAddress( ref string AddressLine1, ref string AddressLine2, ref string City, ref string State, ref string ZipCode, ref string Country)
>>>
>>>So, although it may be not a good practice, my colleague (who wrote this method) returns new values using parameters passed by references. When I debug that DLL, I can see the new values, however, my call
>>>
>>>
>>>lcResult = loBridge.Invokestaticmethod("Siriusware.Library.Cass", "VerifyAddress", @Address1, @Address2, @City, @State, @Zipcode, @Country)
>>>		?Address1
>>>		?ZipCode
>>>		
>>>		?lcResult
>>>
>>>
>>>does not return the new values for the address components.
>>>
>>>Do you know what needs to be done to be able to get the changed values in VFP or how the method should be changed in C# if this is not possible?
>>>
>>>Thanks in advance.
>>>
>>>
>>>>>UPDATE. I got it to work using InvokeStaticMethod, e.g. I'm getting the result. The only problem is that this dll reads one setting from the ini file and it's not finding that ini file and therefore the result is not what I want to get.
>>>>
>>>>Do you mean the YourExe.config file? If so that file needs to be with the executing EXE. So if you're running in Fox IDE it'll be vfp.exe.config. If you're running your actual exe it'll be YourExe.exe.config.
>>>>
>>>>+++ Rick ---
>>>>
>>>>>
>>>>>Hi everybody,
>>>>>
>>>>>I am trying to use wwDotNetBridge to access static class from our custom dll. I am trying this code:
>>>>>
>>>>>
>>>>>do wwDotNetBridge
>>>>>local loBridge as wwDotNetBridge
>>>>>loBridge = createobject("wwDotNetBridge", 'V4')
>>>>>if vartype(loBridge) = 'O'
>>>>>	if loBridge.LoadAssembly("Siriusware.Library.dll")
>>>>>
>>>>>		Address1 = "2170 S Josephine St Unit 1"
>>>>>		Address2 = ""
>>>>>		City = "Denver"
>>>>>		State = "CO"
>>>>>		Zipcode  = "80210"
>>>>>		Country = "USA"
>>>>>
>>>>>		*            string sResult = Cass.VerifyAddress( ref Address1, ref Address2, ref City, ref State, ref Zipcode, ref Country);
>>>>>
>>>>>		loCass = loBridge.CreateInstance("Cass")
>>>>>		if isnull(loCass)
>>>>>			? loBridge.cErrorMsg
>>>>>			return
>>>>>		endif
>>>>>
>>>>>		*loPop.Connect("mail.gorge.net",587,.f.)
>>>>>
>>>>>
>>>>>		* loPop.Connect("mail.gorge.net",587,.f.)
>>>>>		*? loBridge.InvokeMethod(loPop,"Connect","pop3.gorge.net",110,.f.)
>>>>>
>>>>>		? loCass.VerifyAddress(@Address1, @Address2, @City, @State, @Zipcode, @Country)
>>>>>	endif
>>>>>endif
>>>>>
>>>>>
>>>>>but I am getting this strange error
>>>>>
>>>>>Type not loaded. Please load call LoadAssembly first.
>>>>>
>>>>>What do I need to do in order to use the class and why do I get this weird error message if I did use LoadAssembly already?
+++ Rick ---

West Wind Technologies
Maui, Hawaii

west-wind.com/
West Wind Message Board
Rick's Web Log
Markdown Monster
---
Making waves on the Web

Where do you want to surf today?
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform