Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use DLL in C # Delphi Development

2025-03-13 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces how to use DLL in the development of C # Delphi. It is very detailed and has a certain reference value. Friends who are interested must finish it!

In the previous C # Delphi development projects, will often use TChart this drawing control, it itself is very powerful, support all kinds of maps, such as dots and lines, Plato, histogram, etc., plus can be output to BMP,JPEG,JPG,SVG,GIF and other formats of pictures, easy to use, at that time also packaged into a more independent C # DLL file. The development of .NET programs comes in handy this time.

Several key technical points in the development of C # Delphi:

1.C# will call DLL in an unmanaged manner

2.C# generates a pre-defined format XML file from the sorted drawing data, which is passed to DLL.

3.C# DLL parses XML files and draws pictures according to the corresponding format and requirements

4.C# DLL output GIF file (after comparison, GIF image distortion rate is small, and file size is the smallest)

5.C# loads GIF files and sends them to the front desk for display

C # Delphi development key code:

The following is a reference clip:

# region defines the drawing DLL written by calling Delphi

/ / /

/ define the drawing DLL written by calling Delphi

/ / /

Private class DrawChartFromDll

{

/ / define the DLL file name, which is to be added to the system Path

Private const string _ fileDll = @ "Chart.dll"

/ / calling unmanaged Dll,GetChartFromXMLByNet is the name of the function exposed by ChartAccess.dll

[DllImport (_ fileDll, EntryPoint = "GetChartFromXMLByNet"

CharSetCharSet = CharSet.Ansi, CallingConventionCallingConvention =

CallingConvention.StdCall)]

/ / statement in C#

Public static extern int GetChartFromXMLByNet

(int piChartType, string psXMLFileName, string psPriChartFileName

String psSecChartFileName, string psPriHotFileName, string psSecHotFileName)

}

# endregion

Public ChartResultData GetCharts

(ChartData _ ChartData, Hashtable _ HotPriAdditionSeqNo, Hashtable _ HotSecAdditionSeqNo)

{

/ / generate XML files based on data

String _ xmlFileName = ""

ChartResultData _ ChartResultData = new ChartResultData ()

Try

{

_ xmlFileName = this.ConvertDataToXml (_ ChartData)

}

Catch (Exception err)

{

_ ChartResultData.ErrMessage = err.Message

}

...

/ / call DELPHI to get the returned parameters

Int _ return =-1

Try

{

_ return = DrawChartFromDll.GetChartFromXMLByNet

(m_chartType, _ xmlFileName, _ priChartFileName

_ secChartFileName, _ priHotFileName, _ secHotFileName)

}

Catch (Exception err)

{

If (_ return > 0)

{

/ / Delete temporarily generated XML files

This.DeleteTempFile (_ xmlFileName)

This.DeleteTempFile (_ priChartFileName)

This.DeleteTempFile (_ secChartFileName)

This.DeleteTempFile (_ priHotFileName)

This.DeleteTempFile (_ secHotFileName)

_ ChartResultData.ErrMessage = err.Message

Return _ ChartResultData

}

Else

{

/ / possibly due to security problems, memory protection error messages may occur when the DLL method is called frequently and successively.

Although there is an error, the method has been called correctly and can return the correct value, which can be ignored at this time

_ return = 0

}

}

/ / Delete temporarily generated XML files

This.DeleteTempFile (_ xmlFileName)

...

}

The above is all the contents of the article "how to use DLL in C # Delphi Development". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report