DLL.newmethod(String) Method

Definition

Creates an instance of the DLL class.

public:
 void newmethod(System::String ^ _filename);
public void newmethod (string _filename);
override this.newmethod : string -> unit
Public Sub newmethod (_filename As String)

Parameters

_filename
String

The file name of the DLL to use to create the instance of the DLL class.

Remarks

To access a DLL function, use a created instance of the DLL class in a call to the DLLFunction::new method. If an attacker can control input to the new method, a security risk exists. Therefore, this method runs under Code Access Security. Calls to this method on the server require permission from the InteropPermission class. Make sure that the user has development privileges by setting the security key to SysDevelopment on the control that calls this method.

The following example uses the DLL and DLLFunction classes to interoperate with the GetVersion API in Kernel32.dll. This example asserts the use of the InteropPermission class. It loads the DLL and, if it is successful, sets the return type from the call in the DLLFunction class.

void DLLExample() 
{ 
    Dll               dll; 
    DllFunction       dllFunc; 
    anytype           retVal; 
    InteropPermission perm; 
    perm = new InteropPermission(InteropKind::DllInterop); 
    // Grants permission to execute the DLL.new method. 
    // DLL.new runs under code access security. 
    perm.assert(); 
    dll = new Dll("Kernel32.dll"); 
    // Closes the code access permission scope. 
       CodeAccessPermission::revertAssert(); 
    if (dll != null) 
    { 
        perm = new InteropPermission(InteropKind::DllInterop); 
       // Grants permission to execute the DLLFunction.new method. 
       // DLLFunction.new runs under code access security. 
        perm.assert(); 
        dllFunc = new DllFunction(dll, "GetVersion"); 
        if (dllFunc != null) 
        { 
             dllFunc.returns(ExtTypes::DWord); 
            retVal = dllFunc.call(); 
        } 
        // Close the code access permission scope. 
       CodeAccessPermission::revertAssert(); 
    } 
}

Applies to