Unit1 summary
-
Upload
eleksdev -
Category
Technology
-
view
1.167 -
download
0
Transcript of Unit1 summary
eleks.com eleks.com
Unit 1 Summary
P/Invoke, Marshalling
C++ .h fileextern "C"{
struct EndpointData{
char* userName1;char* userName2;
};
struct ResultData{
char* userName;int userId;
};
__declspec(dllexport) int __stdcall findPath(EndpointData* pStructs, int nItems, const char* userName1, const char* userName2);
__declspec(dllexport) int __stdcall returnNumber();__declspec(dllexport) ResultData* __stdcall findPathWithResultData(EndpointData* pStructs, int nItems,
const char* userName1, const char* userName2, int& resultArraySize);}
C# methods definition[DllImport("ExternalNativeLibrary.dll")]public static extern int returnNumber();
[DllImport("ExternalNativeLibrary.dll")]public static extern int findPath(MyStruct[] pStructs, int nItems, string userNamr1, string userName2);
[DllImport("ExternalNativeLibrary.dll", EntryPoint = "findPathWithResultData")]public static extern IntPtr findPathWithResultData(MyStruct[] pStructs, int nItems, string userNamr1, string userName2, out int resultArrSize);
C# structures definition [StructLayout(LayoutKind.Sequential)] public struct MyStruct { public string userName1; public string userName2; }
[StructLayout(LayoutKind.Sequential)] public struct Results { public string userName; public int userId; }
C# Call methodsConsole.WriteLine("Return number:");Console.WriteLine(returnNumber());
int count;var pointer = findPathWithResultData(structArray, structArray.Length, "user1", "user3", out count);
var firstResult = Marshal.PtrToStructure<Results>(pointer);
var pointer2 = pointer + Marshal.SizeOf<Results>();var secondResult = Marshal.PtrToStructure<Results>(pointer2);
SerializationSerialization is the process of converting an object into a stream of bytes in order to store or transmit it.Deserialization is the opposite process to serialization – converting data to object.
The most used serialization types in .NET Framework:
• Binary serialization (is the serialization process with binary data as a result)• Xml serialization (is the serialization process with XML data as a result)
Serialization example public static class XmlSerializationService<T> where T : class{ private static XmlSerializer _serializer = new XmlSerializer(typeof(T));
public static T Deserialize(string serializedObject) { using (var sr = new StringReader(serializedObject)) { return (T)_serializer.Deserialize(sr); } }
public static string Serialize(T objectToSerialize) { using (var sw = new StringWriter()) { _serializer.Serialize(sw, objectToSerialize); return sw.ToString(); } } }
Trello
Project architecture
Project requirementsІдея: месенджер, де дружба = надіслане повідомлення.
C++- Пошук спільних друзів.- Пошук спільних речей між людьми.- Пошук відстані між двома людьми.C#- Консольна аплікація.- Додавання користувача.- Збереження, завантаження даних з файлу.- Видалення користувача.- Інтеграція С++ методів.- Збереження ‘метадати’ користувача.- Імпорт\експорт файлу з користувачами. Вхідний файл – csv- Технічні вимоги: exception handling, logs, application menu.
eleks.com
Inspired by Technology.Driven by Value.
What to readP/Invoke:https://msdn.microsoft.com/en-us/library/aa288468(v=vs.71).aspxhttps://blogs.msdn.microsoft.com/jonathanswift/2006/10/02/calling-an-unmanaged-dll-from-net-c/https://msdn.microsoft.com/en-us/library/26thfadc(v=vs.110).aspx
Serialization:http://ryaremchuk.blogspot.com/2012/10/xml-serialization.html