C # access to pointer parameters when calling the C interface

Source: Internet
Author: User

There are two ways to access pointers,

Reference Type in 1. C #

2. pointer implementation in C #

Using system; using system. collections. generic; using system. LINQ; using system. text; using system. runtime. interopservices; // <summary> // offline UK operation class /// </Summary> Public unsafe class UK {// reference type variable implementation [dllimport ("UK")] extern static int unikey_find (ref uint handle, ref uint S1, ref uint S2); [dllimport ("UK")] extern static int unikey_logoff (ref uint handle ); // [dllimport ("UK")] // extern static int unikey_log_on_secu (ref uint handle, ref char [] password); [dllimport ("UK")] extern static int unikey_log_on_secu (ref uint handle, char [] password); [dllimport ("UK")] extern static int unikey_log_out_secu (ref uint handle ); [dllimport ("UK")] extern static int unikey_get_com_panfu (ref uint handdle, ref char pdrivename); // pointer address implementation (however, you must set program properties to allow Insecure code) [dllimport ("UK")] extern static int unikey_find (uint * handle, uint * S1, uint * S2); [dllimport ("UK")] extern static int unikey_logoff (uint * handle); [dllimport ("UK")] extern static int unikey_log_on_secu (uint * handle, uint * password); [dllimport ("UK")] extern static int unikey_log_out_secu (uint * handle); [dllimport ("UK")] extern static int unikey_get_com_panfu (uint * handdle, char * pdrivename ); /// <summary> /// search for ukey /// </Summary> /// <returns> </returns> protected static int ukeyfind () {uint handle = 0; uint S1 = 0; uint S2 = 0; int result = unikey_find (ref handle, ref S1, ref S2); return result ;} /// <summary> /// exit ukey /// </Summary> /// <Param name = "handle"> </param> /// <returns> </returns> protected static int ukeylogoff () {uint handle = 0; return unikey_logoff (ref handle );} /// <summary> /// log on to ukey /// </Summary> /// <returns> </returns> protected static int ukeylogonsecu () {uint handle = 0; char [] Password = new char [6] {'1', '2', '3', '4', '5', '6 '}; int result = unikey_log_on_secu (ref handle, password); return result ;} /// <summary> /// exit ukey /// </Summary> /// <returns> </returns> protected static int ukeylogoutsecu () {uint handle = 0; return unikey_log_out_secu (ref handle );}}

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.