DLL.new Method [AX 2012]
Creates an instance of the class.
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 . Ensure that the user has development privileges by setting the security key to SysDevelopment on the control that calls this method.
This example uses the DLL and the DLLFunction classes to interoperate with the GetVersion API in Kernel32.dll. The example asserts the use of the InteropPermission class. It loads the DLL, and, if it is successful, it 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();
}
}