asp.net C # calls the difference between managed and unmanaged DLL files

Source: Internet
Author: User
Tags dotnet tagname

ASP tutorial The difference between calling a managed DLL and an unmanaged DLL file in. NET C #
managed DLL files, which can be added directly to your project by adding references in the dotnet environment. The corresponding DLL object is then invoked through the using DLL namespace.

unmanaged DLL files, which are invoked by DllImport when the dotnet environment is applied.

   C # calls unmanaged DLL files. DLL files are written in C language.
as follows:
1: Structure definition
  rditag_t  
  rditag_t structure defines the structure of the measuring point
  typedef struct _RDITAG_T
  {
char tagname[rdi_max_tagname_len];/*[in]*/
float val;/*[out]*/
int status;/*[out]*/
 } rditag_t; The
  2:rditagname_t
  rditagname_t defines the test-naming type
  typedef char Rditagname_t[rdi_max_tagname_len];
----------------------------------------------------
Function Description:
  1:void rdi_read (rditag_t tags[], int count, int timeout);
  Parameters
  tags read the data points group.
  Count input parameters.
  Timeout input parameters.
  2:void rdi_read0 (rditagname_t tagnames[], float values[], int statuses[], int count, int timeout);
Parameter
TagNames the input parameter. The
values output parameters. The
statuses output parameters. The
Count input parameter. The
Timeout timeout value (milliseconds).
return value
None.

--The following is the source code. And for reference study. cannot be used for commercial profit.
Public Const string dll_name = "Rdiapi.dll";
Public Const byte Rdi_max_tagname_len = 0x18;
public const INT rdi_sts_failed =-1;
public const INT Rdi_sts_invalid_handle =-2;
public const INT Rdi_sts_invalid_tag =-5;
public const INT RDI_STS_NET_ERROR =-3;
Public Const BYTE RDI_STS_OK = 1;
public const INT rdi_sts_timeout =-4;

[DllImport ("Rdiapi.dll")]
public static extern int rdi_close ();
[DllImport ("Rdiapi.dll")]
public static extern int Rdi_init ();
[DllImport ("Rdiapi.dll")]
public static extern int Rdi_isopen ();
[DllImport ("Rdiapi.dll")]
public static extern int Rdi_open (string server, int port);
[DllImport ("Rdiapi.dll")]
--Functions written in C # (note parameters [in, out] rditag_t[] tags instead of ref)
public static extern int Rdi_read ([in, out] rditag_t[] tags, int count, int timeout);
[DllImport ("Rdiapi.dll")]
public static extern int rdi_read0 (rditag_t1[) tags, [in, out] float[] Value_array, [in, out] int[] status_array, int coun T, int timeout);
[DllImport ("Rdiapi.dll")]
public static extern int Rdi_uninit ();
--Define structure with C #
[StructLayout (LayoutKind.Sequential)]
public struct rditag_t
{
[MarshalAs (UnmanagedType.ByValTStr, SizeConst = 0x18)]
public string tagname;
public float Val;
public int status;
}
--Define structure with C #
[StructLayout (LayoutKind.Sequential)]
public struct RDITAG_T1
{
[MarshalAs (UnmanagedType.ByValTStr, SizeConst = 0x18)]
public string tagname;

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.