Access objects in Visual C ++ DLL using interfaces in Object Pascal

xiaoxiao2021-03-06  46

Separating the software interface is a common method of developing a normal desktop application, which can bring a variety of benefits, such as convenient software automatic update and maintenance (we rarely see all all things of the software to an exe) . The usual approach is to encapsulate business logic or core in a separate component, such as COM or even standard DLL libraries. We discuss ordinary DLL here. Only only normal functions or processes in the DLL must not work, object-oriented design and development, good model applications are essential, this requires us to provide an external access to the object in DLL. For example, Delphi can use the BPL package, or Interface to access objects in the DLL, Visual C is simpler, and the MFC extension DLL even allows you to export this class. However, Delphi and VC have advantages in the development, and Delphi quickly develops a very suitable interface, and there is a large number of 3rd round library available, which can develop a very beautiful interface. This point I personally think that it is more than VC. A lot (of course. Net hosting C exceptions, because it can directly use the library provided by .NET); and the advantage of VC is the flexibility and efficiency of the C language itself, which is ideal for the core part of the software (for example, you can also use Intel) C compiler to recompile the code, greatly enhance the performance in the Intel platform). If we can use Delphi to develop the software interface, use VC to develop core business logic not very good? Delphi Accessing the normal export function in the C DLL is of course no problem, but how can I access the object by interface? I studied for a two day, carefully analyzed the object model of C and Object Pascal, finally got, shared my experience: Object Pascal Interfaces and C interfaces are very different, for example, we can like Next, a C interface structure ifoo: public iunknown {Virtual INT _STDCALL ADD (int X, int y) = 0; // Because the virtual function in the class needs to be exported, the interface and the virtual function in the class should be used _stdcall formula Virtual INT _STDCALL Divd (int X, int y) = 0;}; then we use an export function to export C objects through this interface: Extern "C" _Declspec (DLLEXPORT) iFoo * getMaininterface () {return dynamic_cast

转载请注明原文地址:https://www.9cbs.com/read-50951.html

New Post(0)