Due to project needs, I wrote a connection database to the DLL of the SQL file with Delphi, where the TadoQuery component is used. Only one export method: Function DataExport (PATH, INI_PATH: PCHAR): INTEGER; After writing, write a test.exe with Delphi and found it normally. Then handed this DLL to the colleague and let him call in Powerbuilder. After the colleague took the past, it was found that once the DataExportPb was called, the target DLL could not be opened. I think it may be because the environment on both sides is different, then copy Test.exe to try. The strange thing is that Test.exe runs normally. In order to determine where the problem occurs, I use Python and C # to test, C # There is no problem below, but Python report error: Nothing to call Coinitialize () Review the information, found that if the ADO component is used in DLPHI, then The Coinitialize method that needs to call ActiveX before use. After knowing the problem, you will do more, call Coinitialize () before you create TadoQuery in the source code, and Python calls success.
I thought PowerBuilder should also be no problem, who knows or the same problem. I don't think this is. The calling method of the CTypes module in Python, the parameter transmission mode should be the same as PowerBuilder, but why is it still in the PB? Colleagues let me write more about the output method in the DLL, I have written the following way again:
Function test: pchar; begin result: = 'test string from test';
The Test method is called success in PB, followed by colleagues trying to call DataExport, success! ! ? ? why? This Test method is just the output of a fixed string, why is DataExport successfully called? I really can't understand.
But at this time there is a problem, once a memory operation error occurs once an exit PB application.
I carefully check the Delphi code, find out which object is not released, my code is as follows:
Function DataExport (PATH, INI_PATH: PCHAR): Integer; var query: tadoquery; begin ......... Coinitialize (); query: = tadoquery.create (nil); ......... Query.close; query.free; coundialize (); .........
No problem! In desperation, I divide Coinitialize () and CounInitialize () into two independent methods. Function init: integer; responsient: = 1; Except on Exception: Result: = 0; end;
Function uninit: integer; begin try couninitialize (); result: = 1; Except on Exception: Result: = 0; end;
Then let the colleagues call init in the form initialization event, and then turn off the event to call uninit. problem solved. What is normal. Although the problem is resolved, I still don't understand why I have to do this.