Differences between hosted DLL and non-hosted DLL files by calling C #

Source: Internet
Author: User

First, Let's explain the differences between hosted DLL and non-hosted DLL. In a narrow sense, hosted DLL files are generated in the DOTNET environment. Unmanaged DLL files are not generated in the DOTNET environment.

To host DLL files, you can add the hosted DLL files to the project directly by adding references in the DOTNET environment. Then, use the Using DLL namespace to call the corresponding DLL object.

A non-hosted DLL file that is called by dllimport when used in the DOTNET environment.

C # Call an unmanaged DLL file. DLL files are written in C language.
as follows:
1: structure Definition
rditag_t structure defines the measurement point structure
typedef struct _ rditag_t
{< br> char tagname [rdi_max_tagname_len]; /* [in] */
float val;/* [out] */
int status;/* [out] */
} rditag_t;
2: rditagname_t
rditagname_t defines the name test type
typedef char rditagname_t [rdi_max_tagname_len];
Functions
Description:
1: void rdi_read (rditag_t tags [], I NT count, int timeout);
parameter
tags reads the data point array.
count parameter.
timeout input parameter.
2: void rdi_read0 (rditagname_t tagnames [], float values [], int statuses [], int count, int timeout );
parameter
tagnames input parameter.
values output parameters.
statuses output parameters.
count parameter.
timeout value (MS ).
return value
none.

-- The following is the source code. And for reference. It 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 that the parameter [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 count, int timeout );
[Dllimport ("rdiapi. dll")]
Public static extern int rdi_uninit ();
-- Use C # to define the structure
[Structlayout (layoutkind. Sequential)]
Public struct rditag_t
{
[Financialas (unmanagedtype. byvaltstr, sizeconst = 0x18)]
Public String tagname;
Public float val;
Public int status;
}
-- Use C # to define the structure
[Structlayout (layoutkind. Sequential)]
Public struct rditag_t1
{
[Financialas (unmanagedtype. byvaltstr, sizeconst = 0x18)]
Public String tagname;

-------------------------------------

This document can be retained. For more information, see. If you have any shortcomings, please point out your reply. Thank you.

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.