Getting two value from my dll - c#

puplic class Example;
{
public static int Test(int[] Array, int value1, int value2)
{
// here I calculate my value1 and value2 by using my Array
}
}
It is my dll above. Then I want to cal my dll in my windows application below.
private void buttonStart_click(object sender, EventArgs e)
{
int value1=0, value2=0;
Example.Test(Array,value1,value2);
}
My Array is defined global. In my windows application,I want to call my dll and calculate my new value1 and value2 in dll then change my value1 and value2 which are in windows application with new value1 and value2.
I am new in using dll. I can return one value from my dll by using 'return value1;' but I do not know how I can get two value from my dll.
Is there anybody who knows the way?

Try out
public static int Test(int[] Array, out int value1, out int value2)
or
public static int Test(int[] Array, ref int value1, ref int value2)
See Passing Parameters (C# Programming Guide).

Related

Converting mixed type return data from an unmanaged C DLL?

I am writing a wrapper C# DLL to interface with a supplier provided unmanaged DLL written in C. For the most part everything is smooth, however there are some functions that in the provided documentation look like this:
int get_value(int unit, int id, int* value)
My issue is that int* value is an array with a mixture of int's and float's... The documentation states which is which, i.e. that the first value is an int, the second and third are float, etc.. I have some success if i specifically call out the DLL value as int or float. That returns some of the data i'm looking for, but only for the one type. For example, this kinda works:
[DllImport("supplier.dll")]
public static extern int get_value(int unit, int id, float* value)
public static int GetValue(int unit, int id, out float[] value)
{
float[] value = new float[3];
int ret = get_value(unit, id, value);
return ret;
}
value is returned with [NaN, value1, value2] because the 0 index is actually an integer and it's not interpreted correctly. I have attempted to use an IntPtr[] as the return value in the unmanaged DLL and then use Marshal.Copy() to get the data from the memory locations, but this hasn't gone well. Is that a promising approach? If so, I'm not sure which overload to use, an example would be very helpful!
int* value is an array with a mixture of int's and float's...
That's a serious violation of the strict aliasing rule and will invoke undefined behavior. In C you'll have to use a union instead. The documentation should be like this
union Value
{
int i;
float f;
};
int get_value(int unit, int id, union Value* value);
Disregarding the original UB in supplier.dll C# you can simulate the similar feature with FieldOffset
[StructLayout(LayoutKind.Explicit)]
public struct Value
{
[FieldOffset(0)] public int i;
[FieldOffset(0)] public float f;
}
[DllImport("supplier.dll")]
public static extern int get_value(int unit, int id, out Value[] value);
public static int GetValue(int unit, int id, out Value[] value)
{
float[] value = new float[3];
int ret = get_value(unit, id, value);
return ret;
}
After obtaining the array, just use the correct field to get the expected value
var ret = GetValue(unit, id, out Value[] value);
var f0 = value[0].f;
var i1 = value[1].i;
If you really want to do that without a union then you must get the float's binary representation like this
float f0 = value[0];
int i1 = BitConverter.SingleToInt32Bits(value[1]);
int i2 = BitConverter.SingleToInt32Bits(value[2]);
value[1] = BitConverter.Int32BitsToSingle(f0 + 0.123f);
But if the array always has 3 items like that then why return an array instead of a struct?
public struct Values
{
public float f0;
public int i1;
public int i2;
}
[DllImport("supplier.dll")]
public static extern int get_value(int unit, int id, out Values values);
public static int GetValue(int unit, int id, out Values values) {...}

How to convert a ref [enum type] to a ref int?

I want to use Interlocked.CompareExchange with an enum type that inherits from int, like so:
public enum MyEnum : int { A, B }
public class MyClass
{
private static readonly MyEnum s_field = MyEnum.A;
public void Foo()
{
if (Interlocked.CompareExchange(ref s_field, MyEnum.B, MyEnum.A) == MyEnum.A)
{
Console.WriteLine("Changed from A to B");
}
}
}
However, CompareExchange only works with reference types and select value types (see here). Since a MyEnum is really an int underneath the skin, I thought I should be able to pass it as a ref int:
// should call CompareExchange(ref int, int, int) overload
Interlocked.CompareExchange(ref s_field, (int)MyEnum.B, (int)MyEnum.A);
However, this doesn't seem to work either. I get the following error:
Error CS1503: Argument 1: cannot convert from 'ref MyEnum' to 'ref int'
Casting before passing it in, e.g. ref (int)s_field, doesn't help either.
How can I fix this? Is there any way to use CompareExchange with enums, or must I use ints instead?
Would you want to use union?
public enum MyEnum : int { A, B }
[StructLayout(LayoutKind.Explicit)]
struct IntEnumUnion
{
[FieldOffset(0)]
public MyEnum Enum;
[FieldOffset(0)]
public int Int;
}
private static IntEnumUnion s_field;
s_field.Enum = MyEnum.A;
if (Interlocked.CompareExchange(ref s_field.Int, (int)MyEnum.B, (int)MyEnum.A)
== (int)MyEnum.A)
{
Console.WriteLine("Changed from A to B");
}
Of course, it is little cumbersome...
What about converting the value after the evaluation?
int value = (int)MyEnum.A;
var result = Interlocked.CompareExchange(ref value, (int)MyEnum.A, (int)MyEnum.B);
if((MyEnum)result == MyEnum.A)
System.Console.WriteLine("Changed from A to B");
Maybe you can just use:
static readonly object lockInstance = new object();
public static TSimple CompareExchange<TSimple>(ref TSimple location1, TSimple value, TSimple comparand)
{
lock (lockInstance)
{
var location1Read = location1;
if (EqualityComparer<TSimple>.Default.Equals(location1Read, comparand))
{
// location1 write
location1 = value;
}
return location1Read;
}
}
Caution: The lock thing only prevents changes to location1 occurring through this particular method. It cannot prevent other threads from manipulating location1 by other means while my method runs. If this is a problem, maybe use int and have public static class MyEnum { public const int A = 0; public const int B = 1; }.
I believe this is now possible with the Unsafe class which was introduced in .NET Core. Run this to install the package containing the class into your app:
Install-Package System.Runtime.CompilerServices.Unsafe
Then you can do Interlocked.CE(ref Unsafe.As<MyEnum, int>(ref s_field), (int)MyEnum.B, (int)MyEnum.A). Note that this requires C# 7 language support for ref returns, so you need to have VS2017 or later.

Delegate partial function in C#?

I've written some calculate delegates which are passed as parameters.
private delegate int CalculateDelegator(int value1, int value2);
CalculateDelegator addWith = add;
CalculateDelegator divWith = div;
private static int add(int value1, int value2) {
return value1 + value2;
}
private static int div(int value1, int value2) {
return value1 / value2;
}
The method link(CalculateDelegator method, int value2) which receives addWith as parameter holds value1 and the method which calls link holds value2. So I call link() always with passing value2 as seperate paremeter.
Is there a way of passing the calculating method including the first parameter: link(addWith(value2))?
(e.g. as a partial function like in Scala)
No, something like that isn't directly possible in C#.
What you can do is something like the following:
int link(Func<int, int> addWithValue2)
{
return addWithValue2(value1);
}
You would call it like this:
link(v1 => addWith(v1, value2));
BTW: I think the concept you are describing is called currying and there is a project that tries to bring it to C#: https://github.com/ekonbenefits/impromptu-interface/wiki/UsageCurry. It basically uses the approach shown in this answer.
You can do the following:
Func<int, int> partialMethod =
value1 => addWith(value1, 5);
This way the partialMethod will take in one argument and passes it with the internal 'holded' value.
As far as I understand your question, you would need to create an extension method for int:
public static LinkExtension
{
public static void Link(this int value, CalculateDelegator method)
{
// Link action here
}
}
So you just call value2.Link(addWith).

Passing C# function pointers into C++/CLI interop dll

I'm trying to pass a function pointer from C# into C++/CLI and getting a windows compiler error stating that the ManagedTakeCallback function is not supported by this language (C#)--I define the ManagedTakeCallback in the C++/CLI interop. My code looks like
C# application:
namespace ManagedConsoleApplication
{
class Callback
{
public delegate double DelegateAdd(double value1, double value2);
public static double CallbackAdd(double value1, double value2)
{
return value1 + value2;
}
public static DelegateAdd delegateCallback = new DelegateAdd(Callback.CallbackAdd); //declare as static to prevent GC
}
class Program
{
// [DllImport("InteropDLL.dll", CallingConvention = CallingConvention.StdCall)]
// public static extern void ManagedCallback(IntPtr pCallback);
static void Main(string[] args)
{
InteropDLL io = new InteropDLL();
Console.WriteLine("The Add return = {0}", io.ManagedAdd(3, 2));
Console.WriteLine("Pass CallBack to Unmanaged code");
Callback cb = new Callback();
IntPtr intptr_delegate = Marshal.GetFunctionPointerForDelegate(Callback.delegateCallback); //convert delegate to function pointer which can be used by unmanaged code
Console.WriteLine("The callback return is {0}", io.ManagedTakeCallback(intptr_delegate));
Console.WriteLine("Please hit Enter to exit");
String value = Console.In.ReadLine();
//Console.WriteLine("End of program ", value);
}
}
}
and,
C++/CLI interop dll h and cpp file:
//HEADER
namespace Interop
{
typedef double (__stdcall *PCallback)(double value1, double value2);
public ref class InteropDLL
{
public:
double ManagedAdd(double value1, double value2);
public:
double ManagedTakeCallback(PCallback pCallback);
};
}
//CPP
double Interop::InteropDLL::ManagedAdd(double value1, double value2)
{
return NativeAdd(value1, value2);
}
double Interop::InteropDLL::ManagedTakeCallback(PCallback pCallback)
{
return NativeTakeCallback();
}
The C++/CLI interop layer then calls a C DLL. I'm able to call ManagedAdd interop function; however, if ManagedTakeCallback is added, there is a windows compiler error. I suspect that the C# application is not marshaling in the function pointer correctly via ManagedTakeCallback function or that the signature is not correct on the C++/CLI side? I would greatly appreciate any insight.
Here is comment from on site:
"But C# doesn’t suport C++ function pointer, so we cannot invoke a C++ function pointer here. C# only has Delegate objects and we have to convert the function pointer to Delegate by Marshal.GetDelegateForFunctionPointer. It is declared in System.Runtime.InteropServices as follows:
public static Delegate GetDelegateForFunctionPointer (
IntPtr ptr,
Type t)
for full answer look at link:
http://www.codeproject.com/Articles/27298/Dynamic-Invoke-C-DLL-function-in-C

Return multiple values to a method caller

I read the C++ version of this question but didn't really understand it.
Can someone please explain clearly if it can be done in C#, and how?
In C# 7 and above, see this answer.
In previous versions, you can use .NET 4.0+'s Tuple:
For Example:
public Tuple<int, int> GetMultipleValue()
{
return Tuple.Create(1,2);
}
Tuples with two values have Item1 and Item2 as properties.
Now that C# 7 has been released, you can use the new included Tuples syntax
(string, string, string) LookupName(long id) // tuple return type
{
... // retrieve first, middle and last from data storage
return (first, middle, last); // tuple literal
}
which could then be used like this:
var names = LookupName(id);
WriteLine($"found {names.Item1} {names.Item3}.");
You can also provide names to your elements (so they are not "Item1", "Item2" etc). You can do it by adding a name to the signature or the return methods:
(string first, string middle, string last) LookupName(long id) // tuple elements have names
or
return (first: first, middle: middle, last: last); // named tuple elements in a literal
They can also be deconstructed, which is a pretty nice new feature:
(string first, string middle, string last) = LookupName(id1); // deconstructing declaration
Check out this link to see more examples on what can be done :)
You can use three different ways
1. ref / out parameters
using ref:
static void Main(string[] args)
{
int a = 10;
int b = 20;
int add = 0;
int multiply = 0;
Add_Multiply(a, b, ref add, ref multiply);
Console.WriteLine(add);
Console.WriteLine(multiply);
}
private static void Add_Multiply(int a, int b, ref int add, ref int multiply)
{
add = a + b;
multiply = a * b;
}
using out:
static void Main(string[] args)
{
int a = 10;
int b = 20;
int add;
int multiply;
Add_Multiply(a, b, out add, out multiply);
Console.WriteLine(add);
Console.WriteLine(multiply);
}
private static void Add_Multiply(int a, int b, out int add, out int multiply)
{
add = a + b;
multiply = a * b;
}
2. struct / class
using struct:
struct Result
{
public int add;
public int multiply;
}
static void Main(string[] args)
{
int a = 10;
int b = 20;
var result = Add_Multiply(a, b);
Console.WriteLine(result.add);
Console.WriteLine(result.multiply);
}
private static Result Add_Multiply(int a, int b)
{
var result = new Result
{
add = a * b,
multiply = a + b
};
return result;
}
using class:
class Result
{
public int add;
public int multiply;
}
static void Main(string[] args)
{
int a = 10;
int b = 20;
var result = Add_Multiply(a, b);
Console.WriteLine(result.add);
Console.WriteLine(result.multiply);
}
private static Result Add_Multiply(int a, int b)
{
var result = new Result
{
add = a * b,
multiply = a + b
};
return result;
}
3. Tuple
Tuple class
static void Main(string[] args)
{
int a = 10;
int b = 20;
var result = Add_Multiply(a, b);
Console.WriteLine(result.Item1);
Console.WriteLine(result.Item2);
}
private static Tuple<int, int> Add_Multiply(int a, int b)
{
var tuple = new Tuple<int, int>(a + b, a * b);
return tuple;
}
C# 7 Tuples
static void Main(string[] args)
{
int a = 10;
int b = 20;
(int a_plus_b, int a_mult_b) = Add_Multiply(a, b);
Console.WriteLine(a_plus_b);
Console.WriteLine(a_mult_b);
}
private static (int a_plus_b, int a_mult_b) Add_Multiply(int a, int b)
{
return(a + b, a * b);
}
You cannot do this in C#. What you can do is have a out parameter or return your own class (or struct if you want it to be immutable).
Using out parameter
public int GetDay(DateTime date, out string name)
{
// ...
}
Using custom class (or struct)
public DayOfWeek GetDay(DateTime date)
{
// ...
}
public class DayOfWeek
{
public int Day { get; set; }
public string Name { get; set; }
}
In C#7 There is a new Tuple syntax:
static (string foo, int bar) GetTuple()
{
return ("hello", 5);
}
You can return this as a record:
var result = GetTuple();
var foo = result.foo
// foo == "hello"
You can also use the new deconstructor syntax:
(string foo) = GetTuple();
// foo == "hello"
Be careful with serialisation however, all this is syntactic sugar - in the actual compiled code this will be a Tuple<string, int> (as per the accepted answer) with Item1 and Item2 instead of foo and bar. That means that serialisation (or deserialisation) will use those property names instead.
So, for serialisation declare a record class and return that instead.
Also new in C#7 is an improved syntax for out parameters. You can now declare the out inline, which is better suited in some contexts:
if(int.TryParse("123", out int result)) {
// Do something with result
}
However, mostly you'll use this in .NET's own libraries, rather than in you own functions.
If you mean returning multiple values, you can either return a class/struct containing the values you want to return, or use the "out" keyword on your parameters, like so:
public void Foo(int input, out int output1, out string output2, out string errors) {
// set out parameters inside function
}
There is many way; but if you don't want to create a new Object or structure or something like this you can do like below after C# 7.0 :
(string firstName, string lastName) GetName(string myParameter)
{
var firstName = myParameter;
var lastName = myParameter + " something";
return (firstName, lastName);
}
void DoSomethingWithNames()
{
var (firstName, lastName) = GetName("myname");
}
Previous poster is right. You cannot return multiple values from a C# method. However, you do have a couple of options:
Return a structure that contains multiple members
Return an instance of a class
Use output parameters (using the out or ref keywords)
Use a dictionary or key-value pair as output
The pros and cons here are often hard to figure out. If you return a structure, make sure it's small because structs are value type and passed on the stack. If you return an instance of a class, there are some design patterns here that you might want to use to avoid causing problems - members of classes can be modified because C# passes objects by reference (you don't have ByVal like you did in VB).
Finally you can use output parameters but I would limit the use of this to scenarios when you only have a couple (like 3 or less) of parameters - otherwise things get ugly and hard to maintain. Also, the use of output parameters can be an inhibitor to agility because your method signature will have to change every time you need to add something to the return value whereas returning a struct or class instance you can add members without modifying the method signature.
From an architectural standpoint I would recommend against using key-value pairs or dictionaries. I find this style of coding requires "secret knowledge" in code that consumes the method. It must know ahead of time what the keys are going to be and what the values mean and if the developer working on the internal implementation changes the way the dictionary or KVP is created, it could easily create a failure cascade throughout the entire application.
You either return a class instance or use out parameters. Here's an example of out parameters:
void mymethod(out int param1, out int param2)
{
param1 = 10;
param2 = 20;
}
Call it like this:
int i, j;
mymethod(out i, out j);
// i will be 20 and j will be 10
Some answers suggest using out parameters but I recommend
not using this due to they don’t work with async methods. See
this for more information.
Other answers stated using Tuple, which I would recommend too but using the new feature introduced in C# 7.0.
(string, string, string) LookupName(long id) // tuple return type
{
... // retrieve first, middle and last from data storage
return (first, middle, last); // tuple literal
}
var names = LookupName(id);
WriteLine($"found {names.Item1} {names.Item3}.");
Further information can be found here.
<--Return more statements like this you can -->
public (int,string,etc) Sample( int a, int b)
{
//your code;
return (a,b);
}
You can receive code like
(c,d,etc) = Sample( 1,2);
I hope it works.
No, you can't return multiple values from a function in C# (for versions lower than C# 7), at least not in the way you can do it in Python.
However, there are a couple alternatives:
You can return an array of type object with the multiple values you want in it.
private object[] DoSomething()
{
return new [] { 'value1', 'value2', 3 };
}
You can use out parameters.
private string DoSomething(out string outparam1, out int outparam2)
{
outparam1 = 'value2';
outparam2 = 3;
return 'value1';
}
There are several ways to do this. You can use ref parameters:
int Foo(ref Bar bar) { }
This passes a reference to the function thereby allowing the function to modify the object in the calling code's stack. While this is not technically a "returned" value it is a way to have a function do something similar. In the code above the function would return an int and (potentially) modify bar.
Another similar approach is to use an out parameter. An out parameter is identical to a ref parameter with an additional, compiler enforced rule. This rule is that if you pass an out parameter into a function, that function is required to set its value prior to returning. Besides that rule, an out parameter works just like a ref parameter.
The final approach (and the best in most cases) is to create a type that encapsulates both values and allow the function to return that:
class FooBar
{
public int i { get; set; }
public Bar b { get; set; }
}
FooBar Foo(Bar bar) { }
This final approach is simpler and easier to read and understand.
In C# 4, you will be able to use built-in support for tuples to handle this easily.
In the meantime, there are two options.
First, you can use ref or out parameters to assign values to your parameters, which get passed back to the calling routine.
This looks like:
void myFunction(ref int setMe, out int youMustSetMe);
Second, you can wrap up your return values into a structure or class, and pass them back as members of that structure. KeyValuePair works well for 2 - for more than 2 you would need a custom class or struct.
you can try this "KeyValuePair"
private KeyValuePair<int, int> GetNumbers()
{
return new KeyValuePair<int, int>(1, 2);
}
var numbers = GetNumbers();
Console.WriteLine("Output : {0}, {1}",numbers.Key, numbers.Value);
Output :
Output : 1, 2
Classes, Structures, Collections and Arrays can contain multiple values. Output and reference parameters can also be set in a function. Return multiple values is possible in dynamic and functional languages by means of tuples, but not in C#.
When your method is async and you want to return multiple properties. You must do like this:
public async Task<(int, int)> GetMultipleValues(){
return (1,2);
}
Mainly two methods are there.
1. Use out/ref parameters
2. Return an Array of objects
Here are basic Two methods:
1) Use of 'out' as parameter
You can use 'out' for both 4.0 and minor versions too.
Example of 'out':
using System;
namespace out_parameter
{
class Program
{
//Accept two input parameter and returns two out value
public static void rect(int len, int width, out int area, out int perimeter)
{
area = len * width;
perimeter = 2 * (len + width);
}
static void Main(string[] args)
{
int area, perimeter;
// passing two parameter and getting two returning value
Program.rect(5, 4, out area, out perimeter);
Console.WriteLine("Area of Rectangle is {0}\t",area);
Console.WriteLine("Perimeter of Rectangle is {0}\t", perimeter);
Console.ReadLine();
}
}
}
Output:
Area of Rectangle is 20
Perimeter of Rectangle is 18
*Note:*The out-keyword describes parameters whose actual variable locations are copied onto the stack of the called method, where those same locations can be rewritten. This means that the calling method will access the changed parameter.
2) Tuple<T>
Example of Tuple:
Returning Multiple DataType values using Tuple<T>
using System;
class Program
{
static void Main()
{
// Create four-item tuple; use var implicit type.
var tuple = new Tuple<string, string[], int, int[]>("perl",
new string[] { "java", "c#" },
1,
new int[] { 2, 3 });
// Pass tuple as argument.
M(tuple);
}
static void M(Tuple<string, string[], int, int[]> tuple)
{
// Evaluate the tuple's items.
Console.WriteLine(tuple.Item1);
foreach (string value in tuple.Item2)
{
Console.WriteLine(value);
}
Console.WriteLine(tuple.Item3);
foreach (int value in tuple.Item4)
{
Console.WriteLine(value);
}
}
}
Output
perl
java
c#
1
2
3
NOTE: Use of Tuple is valid from Framework 4.0 and above.Tuple type is a class. It will be allocated in a separate location on the managed heap in memory. Once you create the Tuple, you cannot change the values of its fields. This makes the Tuple more like a struct.
A method taking a delegate can provide multiple values to the caller. This borrows from my answer here and uses a little bit from Hadas's accepted answer.
delegate void ValuesDelegate(int upVotes, int comments);
void GetMultipleValues(ValuesDelegate callback)
{
callback(1, 2);
}
Callers provide a lambda (or a named function) and intellisense helps by copying the variable names from the delegate.
GetMultipleValues((upVotes, comments) =>
{
Console.WriteLine($"This post has {upVotes} Up Votes and {comments} Comments.");
});
From this article, you can use three options as posts above said.
KeyValuePair is quickest way.
out is at the second.
Tuple is the slowest.
Anyway, this is depend on what is the best for your scenario.
Future version of C# is going to include named tuples.
Have a look at this channel9 session for the demo
https://channel9.msdn.com/Events/Build/2016/B889
Skip to 13:00 for the tuple stuff. This will allow stuff like:
(int sum, int count) Tally(IEnumerable<int> list)
{
// calculate stuff here
return (0,0)
}
int resultsum = Tally(numbers).sum
(incomplete example from video)
Just use in OOP manner a class like this:
class div
{
public int remainder;
public int quotient(int dividend, int divisor)
{
remainder = ...;
return ...;
}
}
The function member returns the quotient which most callers are primarily interested in. Additionally it stores the remainder as a data member, which is easily accessible by the caller afterwards.
This way you can have many additional "return values", very useful if you implement database or networking calls, where lots of error messages may be needed but only in case an error occurs.
I entered this solution also in the C++ question that OP is referring to.
You could use a dynamic object. I think it has better readability than Tuple.
static void Main(string[] args){
var obj = GetMultipleValues();
Console.WriteLine(obj.Id);
Console.WriteLine(obj.Name);
}
private static dynamic GetMultipleValues() {
dynamic temp = new System.Dynamic.ExpandoObject();
temp.Id = 123;
temp.Name = "Lorem Ipsum";
return temp;
}
Ways to do it:
1) KeyValuePair (Best Performance - 0.32 ns):
KeyValuePair<int, int> Location(int p_1, int p_2, int p_3, int p_4)
{
return new KeyValuePair<int,int>(p_2 - p_1, p_4-p_3);
}
2) Tuple - 5.40 ns:
Tuple<int, int> Location(int p_1, int p_2, int p_3, int p_4)
{
return new Tuple<int, int>(p_2 - p_1, p_4-p_3);
}
3) out (1.64 ns) or ref
4) Create your own custom class/struct
ns -> nanoseconds
Reference: multiple-return-values.
You can also use an OperationResult
public OperationResult DoesSomething(int number1, int number2)
{
// Your Code
var returnValue1 = "return Value 1";
var returnValue2 = "return Value 2";
var operationResult = new OperationResult(returnValue1, returnValue2);
return operationResult;
}
As an alternative you could set your method to void and not return anything. Instead create a public class with parameters and set them inside your method.
public class FooBar()
{
public string foo { get; set; }
public int bar { get; set; }
}
Then for your method try this
public void MyMethod(Foo foo, Bar bar)
{
FooBar fooBar = new FooBar();
fooBar.foo = "some string";
fooBar.bar = 1;
}
you can try this
public IEnumerable<string> Get()
{
return new string[] { "value1", "value2" };
}

Categories