Unicode Support


Unicode Support

Previous pageReturn to chapter overviewNext page

CAD DLL uses Unicode standard to encode characters in text strings. So, if you have used a previous version of DLL, you need to make changes in your project (depending on the IDE and language you are using for applications development).


This tutorial shows what you need to do in order to provide the correct interaction between your application and DLL.





You need to use Embarcadero Delphi 2009/2010/XE/XE2/XE3/XE4/XE5/XE6/XE7/XE8/XE10 in order to provide a complete support for the Unicode characters set in Delphi applications. No changes are required in your project.



C#/Visual Basic .NET:


You need to override the default marshaling for string parameters to unmanaged methods using the LPWStr type . The following sample shows how to implement it:


public class DLLWin32Import
   const string CADImage = "CADImage.dll";
   const UnmanagedType sgStrType = UnmanagedType.LPWStr;
   public static extern IntPtr CreateCAD(IntPtr hWindow, [MarshalAs(sgStrType)] string lpFileName);



[Visual Basic]
Class CADImageLib
   Private Const CADImageLibName As String = "CADImage.dll"
   Private Const sgStrType As UnmanagedType = UnmanagedType.LPWStr
   <DllImport(CADImageLibName, _
       SetLastError:=True, _
       CharSet:=CharSet.Ansi, ExactSpelling:=True, _
       CallingConvention:=CallingConvention.)> _
       Public Shared Function CreateCAD(ByVal hWindow As IntPtr, <MarshalAs(sgStrType)> ByVal lpFileName As StringAs IntPtr
       End Function
End Class


You also need to use the Marshal.PtrToStringUni method in order to get a managed string from an unmanaged Unicode string (for instance, if you get text data from the DXFDATA structure):



DXFData EData = new DXFData();

string name = Marshal.PtrToStringUni(EData.Text);



[Visual Basic]

Dim CADData As Data = New Data

Dim str As String = Marshal.PtrToStringUni(CADData.Text)





You need to declare pointer to the WCHAR type using typedef keyword and then use this pointer type for string parameters that are passed to the DLL functions. The following sample shows how to implement it:









Visual Basic:


If you use Visual Basic, please, refer to the DemoVB project. Check the sgStringToVBString and VBStringTosgString functions (Module1.bas) that implement string conversion.



See Also

64-bit support  | CAD DLL structures  | CAD DLL Functions

© 2003-2021 CADSoftTools