IToolS Blog

lupok
My Blog
RssIcon

Using DOTNET_STARTUP_HOOKS in an NET Core Application

by host on giovedì 3 ottobre 2024 10:55
DOTNET_STARTUP_HOOKS is a powerful yet lesser-known feature of the .NET runtime that allows you to execute custom code before the main application starts. In this article, we'll explore how to use this feature in an ASP.NET Core application to perform advanced initialization or configuration operations.

WinForms Filtered PropertyGrid

by host on mercoledì 17 marzo 2021 22:07

This example shows how to create a PropertyGrid in which there is a property search system, useful when the object managed by the PropertyGrid is made up of a large number of properties.

There are two paths that can be followed to implement this system:

  • Implement an object wrapper assigned to the PropertyGrid that implements the ICustomTypeDescriptor interface. This solution, besides being complex and having several side effects, has the disadvantage of having to rewrite part of the editors necessary to modify the properties using PropertyGrid .
  • Implement a TypeConverter to apply to the objects managed by the PropertyGrid , the only disadvantage of this solution is the fact of having to apply the TypeConverter to the classes that you want to manage using the PropertyGrid . Apart from this it is the ideal solution and it is the way implemented in this example.

PropertyGrid
FilteredPropertyGrid
Filtered

Configuring Properties with Fluent API (Code First)

by host on giovedì 26 marzo 2015 11:49
https://msdn.microsoft.com/en-us/library/hh295844(v=vs.103).aspx

Caricare oggetti COM non registrati

by host on martedì 16 settembre 2014 16:03

Ho creato un semplice oggetto COM con il seguente IDL:

// ComObject.idl : IDL source for ComObject
//
 
// This file will be processed by the MIDL tool to
// produce the type library (ComObject.tlb) and marshalling code.
 
import "oaidl.idl";
import "ocidl.idl";
 
[
	object,
	uuid(1C0C9AB2-4388-4E1A-A897-D63DD16910AC),
	dual,
	nonextensible,
	pointer_default(unique)
]
interface IComClass : IDispatch{
   [id(1)] HRESULT CalculateArea(FLOAT a, FLOAT b, [out] FLOAT* area);
};
[
	uuid(F687E8E6-C714-404B-B946-57DFD49D1D1A),
	version(1.0),
]
library ComObjectLib
{
	importlib("stdole2.tlb");
	[
		uuid(916BBACF-990F-44DC-80B2-AD2FF5368E57)		
	]
	coclass ComClass
	{
		[defaultinterface IComClass;
	};
};
 

Condividere dati tra applicazioni mediante DLL

by host on domenica 14 settembre 2014 09:00

In questo esempio vi mostro come sia possibile condividere dati tra applicazioni mediante una DLL, detto in altre parole, come sia possibile condividere dati di una DLL tra applicazioni differenti, Maggiori informazioni si possono trovare al seguente link: How do I share data in my DLL with an application or with other DLLs?

 

 

#pragma data_seg (".SHARED")
 
int var = 0; // per la condivisione tra processi la variabile delle
             //essere allocata staticamente ed essere inizializzata
#pragma data_seg()
 
extern "C"
{
   bool __declspec(dllexport__cdecl ReadValue(int* value);
   bool __declspec(dllexport__cdecl WriteValue(const int& value);
}

Marshal native struct array to managed struct array

by host on lunedì 28 luglio 2014 07:25
// MarshalArrayOfStructures.cpp : main project file.
 
#include "stdafx.h"
#include "MyNativeStruct.h"
#include "MyManagedStruct.h"
#include <stdlib.h>
#include <string.h>
 
using namespace System;
using namespace System::Runtime::InteropServices;
 
struct MyNativeStruct
{
public:
   int myInt;
   double myDouble;
   float myFloat;
}; 
 
[StructLayout(LayoutKind::Sequential)]
public value struct MyManagedStruct
{
public:
   int myInt;
   double myDouble;
   float myFloat;
};
 
array<MyManagedStruct>^ marshalNativeArrayOfMyStruct(const MyNativeStructvectorint size)
{
   array<MyManagedStruct>^ result = gcnew array<MyManagedStruct>(static_cast<int>(size));
 
   if (size) {
      pin_ptr<MyManagedStruct> dest = &result[0];
      memcpy(dest, &vector[0], size * sizeof(MyNativeStruct));
   }
 
   return result;
}
 
 
int main(array<System::String ^> ^args)
{
   MyNativeStruct myNativeStructArray[5] = 
   { 
      { 100, 34.5, 56.4f }, { 200, 66.7, 78.2f }, 
      { 300, 88.9, 8.566f }, { 400, 7438.3, 937589.487f }, 
      { 500, 0.64567, 84677.4887f } 
   };
 
   array<MyManagedStruct>^ myManagedStructArray = 
      gcnew array<MyManagedStruct>(_countof(myNativeStructArray));
 
   myManagedStructArray = marshalNativeArrayOfMyStruct(myNativeStructArray, 
      _countof(myNativeStructArray));
 
   Console::WriteLine(L"Hello World");
   return 0;
}

How to: Wrap Native Class for Use by C#

by host on giovedì 12 giugno 2014 15:39

Esempio tratto da MSDN How to: Wrap Native Class for Use by C#

 

// wrap_native_class_for_mgd_consumption.cpp
// compile with: /clr /LD
#include <windows.h>
#include <vcclr.h>
#using <System.dll>

using namespace System;

class UnmanagedClass {
public:
   LPCWSTR GetPropertyA() { return 0; }
   void MethodB( LPCWSTR ) {}
};

public ref class ManagedClass {
public:
   // Allocate the native object on the C++ Heap via a constructor
   ManagedClass() : m_Impl( new UnmanagedClass ) {}
   
   // Deallocate the native object on a destructor
   ~ManagedClass() {
      delete m_Impl;
   }

protected:
   // Deallocate the native object on the finalizer just in case no destructor is called
   !ManagedClass() {
      delete m_Impl;
   }

public:
   property String ^  get_PropertyA {
      String ^ get() {
         return gcnew String( m_Impl->GetPropertyA());
      }
   }

   void MethodB( String ^ theString ) {
      pin_ptr<const WCHAR> str = PtrToStringChars(theString);
      m_Impl->MethodB(str);
   }

private:
   UnmanagedClass * m_Impl;
};

ThreeJS QuoteHelper

by host on lunedì 9 giugno 2014 00:13
ThreeJS QuoteHelper is a utility for displaying the size of an 3d object in technical drawing style

 

 

ThreeJS Collada loader

by host on lunedì 21 aprile 2014 07:14

Tags