logo search
CSharp_Prog_Guide

Рекомендации по безопасности, касающиеся языка c# в отдельности

Этот список не является исчерпывающим перечнем возможных проблем с безопасностью. В нем отмечены только некоторые наиболее распространенные проблемы, с которыми сталкиваются разработчики C#.

Consuming Unmanaged DLL Functions

Platform invoke is a service that enables managed code to call unmanaged functions implemented in dynamic link libraries (DLLs), such as those in the Win32 API. It locates and invokes an exported function and marshals its arguments (integers, strings, arrays, structures, and so on) across the interoperation boundary as needed.

This section introduces several tasks associated with consuming unmanaged DLL functions. In addition to the following tasks, there are general considerations and a link providing additional information and examples.

To consume exported DLL functions

  1. Identify functions in DLLs.

Minimally, you must specify the name of the function and name of the DLL that contains it.

  1. Create a class to hold DLL functions.

You can use an existing class, create an individual class for each unmanaged function, or create one class that contains a set of related unmanaged functions.

  1. Create prototypes in managed code.

[C#] Use the DllImportAttribute to identify the DLL and function. Mark the method with the static and extern modifiers.

  1. Call a DLL function.

Call the method on your managed class as you would any other managed method. Passing structures and implementing callback functions are special cases.