|Navigation: Clarion.Net (Clarion#) > Clarion# Language Extensions > Platform Invoke Service Support >====== Platform Invocation Service Support (PInvoke) ======|
Platform Invocation Services (PInvoke) allows managed code (code executed by the Common Language Runtime) to call unmanaged functions (i.e., COM components, ActiveX components, Win32 API, etc.) that are implemented in a DLL.
Calling external functions that reside in a DLL uses the Platform Invoke service. It locates and invokes an exported function and marshals (e.g., arranges in a methodical order) its arguments (integers, strings, arrays, structures, and so on) across the interoperation boundary as needed.
To call external procedure you should specify the DLL name and entry point with .NET's DllImport attribute in the MAP. It uses the default PInvoke marshaling mechanisms, as result, you can only use .Net data types as parameters. There is no specific marshaling behavior support for Clarion-specific types (i.e. CLADECIMAL, CLASTRING, CSTRING, PSTRING, ASTRING).
To customize the default marshaling behavior you can use MarshalAs attribute (see .Net Framework documentation for details).
Calling external functions in a DLL with Platform Invoke service can be done in two ways:
1.Clarion# includes support for the .NET's DllImportAttribute attribute:
[DllImport(“user32.dll”, EntryPoint = “MessageBoxW”)] MessageBox PROCEDURE(UNSIGNED hWnd, STRING Text, STRING Caption, UNSIGNED Type),SIGNED
To use the DLLImport attribute, you must include the following namespace in your program as follows:
2.Or using Clarion syntax:
MessageBox PROCEDURE(SIGNED h,ClaString msg,String cpt,SIGNED tp),SIGNED