VB.NET Features ---- DLLIMPORT Features

zhaozj2021-02-16  52

We can use the DECLARE statement to call the process in the external DLL. But VB.NET provides us with another advanced ----- DLLIMPORT feature.

Such as:

Imports system.Runtime.InteropServices

_

Function FindWindow (Byval LpClassName As String, Byval Lpwindowname As String) AS INTEGER

END FUNCTION

_

Function movewindow (byval hwnd as string, byval x as integer, byval y as integer, byval nheight as integer, ByVal NHEPAINT AS INTEGER

END FUNCTION

SUB Test ()

DIM HWND As INTEGER = FindWindow (Nothing, "UnTID-NODEPAD")

IF HWND <> 0 THEN MOVEWINDOW (HWND, 0, 0, 600, 300, 1)

End Sub

This can call the external DLL without any code, even if we change the method named FindWindowa, you can smoothly implement the call because the DLLIMPORT feature compiler can automatically track the actual process and method!

In addition, the DLLIMPORT feature sea supports several optional parameters to accurately define how to call external processes, as well as the return value of the external process.

CHARSET parameters: The way to illustrate the string to the external process, can be charset.ansi (default), charset.unicode.charset.Auto.

Exactspelling Parameters: Used to specify whether the method name is completely consistent with the name in the DLL, the default value is true.

ENTRYPOINT parameter: Used to specify the actual function name in the DLL.

Callingconvention Parameters: Specify the invocation for the entry point, with the value of WINAPI (default), CDECL, FastCallstdCall, and thisCall.

SetLasTERROR parameter: Deconstimate whether the called function sets the last Win32 error code, if set to true, you can read these code through the Err.lastdllerror method or the Marshal.getlastwin32Error method.

PreservesIG parameter: For a boolean value, if true, the compiler will not be converted into a return HRESULT value function.

The following uses the DLLIMPORT feature to call the method named Friend (Friend is VB Reserved Name) in MyFunction.dll.DLLIMPORT feature with Unicode string and affects Win32 error code:

_

Function makefriends (Byval Sl AS String, Byval S2 AS String) AS Integer

END FUNCTION

转载请注明原文地址:https://www.9cbs.com/read-21369.html

New Post(0)