| **Navigation:**  [[clarion.htm|Clarion.Net (Clarion#)]] > [[clarion net language reference.htm|Clarion# Language Extensions]] > Platform Invoke Service Support >====== Platform Invocation Service Support (PInvoke) ====== | [[prop printdocument.htm|{{btn_prev_n.gif|Previous page}}]][[clarion net language reference.htm|{{btn_home_n.gif|Return to chapter overview}}]][[handling unmanaged code with clarion .htm|{{btn_next_n.gif|Next page}}]] | | || {{newcnet.jpg|NewCNet.jpg}} 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** {{notebox.jpg|NoteBox.jpg}} To use the DLLImport attribute, you must include the following namespace in your program as follows: **USING(System.Runtime.InteropServices)** 2.Or using Clarion syntax: **MODULE('user32.dll')** ** MessageBox PROCEDURE(SIGNED h,ClaString msg,String cpt,SIGNED tp),SIGNED** **END** **See Also:** [[custom attributes.htm|Custom Attributes]] [[handling unmanaged code with clarion .htm|Handling Unmanaged Code with Clarion#]]