help me !调用dll出现了问题,思考了多日不能决解,各位大哥多多指点小弟?(200分)

  • 主题发起人 主题发起人 txzhf
  • 开始时间 开始时间
T

txzhf

Unregistered / Unconfirmed
GUEST, unregistred user!
我dll主程<br>ibrary khxx_dll;<br><br>{ Important note about DLL memory management: ShareMem must be the<br> &nbsp;first unit in your library's USES clause AND your project's (select<br> &nbsp;Project-View Source) USES clause if your DLL exports any procedures or<br> &nbsp;functions that pass strings as parameters or function results. This<br> &nbsp;applies to all strings passed to and from your DLL--even those that<br> &nbsp;are nested in records and classes. ShareMem is the interface unit to<br> &nbsp;the BORLNDMM.DLL shared memory manager, which must be deployed along<br> &nbsp;with your DLL. To avoid using BORLNDMM.DLL, pass string information<br> &nbsp;using PChar or ShortString parameters. }<br><br>uses<br> &nbsp;Windows,<br> &nbsp;SysUtils,<br> &nbsp;Classes,<br> &nbsp;Forms,<br> &nbsp;Dialogs,<br> &nbsp;DbTables,<br> &nbsp;u_khxx in 'u_khxx.pas' {frmkhxx};<br><br>var<br> &nbsp; DLLApp:TApplication;<br> &nbsp; DLLScr:TScreen;<br> &nbsp; DLLAppHandle:THandle;<br>{$R *.res}<br><br>procedure DLLEntryPoint(dwReason: DWORD); stdcall; //register; //stdcall;<br>begin<br> &nbsp; case dwReason of<br> &nbsp; &nbsp; &nbsp;DLL_PROCESS_ATTACH: //1<br> &nbsp; &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp; &nbsp; DLLAppHandle := Application.Handle;<br> &nbsp; &nbsp; &nbsp; &nbsp; DLLApp := Application;<br> &nbsp; &nbsp; &nbsp; &nbsp; DLLScr := Screen;<br> &nbsp; &nbsp; &nbsp; <br> &nbsp; &nbsp; &nbsp;end;<br> &nbsp; &nbsp; &nbsp;DLL_PROCESS_DETACH: //3<br> &nbsp; &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Application := DllApp;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Screen := DllScr;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Application.Handle := DLLAppHandle;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; try<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; session.Free<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; except<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;raise &nbsp;exception.Create('error')<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end;<br> &nbsp; &nbsp; &nbsp;end;<br> &nbsp; &nbsp; &nbsp;DLL_THREAD_ATTACH : {ShowMessage('Thread Attach')}; &nbsp;//2<br> &nbsp; &nbsp; &nbsp;DLL_THREAD_DETACH : {ShowMessage('Thread Detach')}; &nbsp;//0<br> &nbsp; end;<br>end;<br><br>exports<br> &nbsp; &nbsp;showkhxx;<br>begin<br> DLLProc := @DLLEntryPoint; &nbsp; &nbsp; &nbsp; &nbsp; //Assign the address of DLLEntryPoint to DLLProc<br> DLLEntryPoint(DLL_PROCESS_ATTACH);<br>end.<br>待调用dllfrom<br>unit u_khxx;<br><br>interface<br><br>uses<br> &nbsp;Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br> &nbsp;Dialogs, StdCtrls, DB, Grids, DBGrids, ADODB, DBTables;<br><br>type<br> &nbsp;Tfrmkhxx = class(TForm)<br> &nbsp; &nbsp;Button1: TButton;<br> &nbsp; &nbsp;Edit1: TEdit;<br> &nbsp; &nbsp;DBGrid1: TDBGrid;<br> &nbsp; &nbsp;ADOQuery1: TADOQuery;<br> &nbsp; &nbsp;DataSource1: TDataSource;<br> &nbsp; &nbsp;procedure Button1Click(Sender: TObject);<br> &nbsp;private<br> &nbsp; &nbsp;{ Private declarations }<br> &nbsp;public<br> &nbsp; &nbsp;{ Public declarations }<br> &nbsp;end;<br><br>var<br> &nbsp;frmkhxx: Tfrmkhxx;<br>procedure &nbsp;showkhxx(aHandle:THandle);stdcall;<br>implementation<br><br>{$R *.dfm}<br>procedure &nbsp;showkhxx(aHandle:THandle);<br>begin<br> &nbsp; Application.Handle:=aHandle;<br> &nbsp; with &nbsp;Tfrmkhxx.Create(Application) &nbsp;do<br> &nbsp; begin<br> &nbsp; &nbsp; try<br> &nbsp; &nbsp; &nbsp; showmodal;<br> &nbsp; &nbsp; finally<br> &nbsp; &nbsp; &nbsp; free;<br> &nbsp; &nbsp; end;<br> &nbsp; end;<br>end;<br>procedure Tfrmkhxx.Button1Click(Sender: TObject);<br>begin<br> &nbsp;self.Edit1.Text:='khxx';<br> &nbsp;<br>end;<br><br>end.<br>调用的主程<br>unit u_main;<br><br>interface<br><br>uses<br> &nbsp;Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br> &nbsp;Dialogs, StdCtrls;<br><br>type<br> &nbsp; &nbsp;Tfrmmain = class(TForm)<br> &nbsp; &nbsp;Button1: TButton;<br> &nbsp; &nbsp;procedure Button1Click(Sender: TObject);<br> &nbsp; &nbsp;procedure FormCreate(Sender: TObject);<br> &nbsp;private<br> &nbsp; &nbsp;{ Private declarations }<br> &nbsp;// &nbsp;DLLHandle:THandle;<br> &nbsp;public<br> &nbsp; &nbsp;{ Public declarations }<br> &nbsp;end;<br>procedure &nbsp;showkhxx(aHandle:THandle);stdcall &nbsp; external &nbsp;'khxx_dll.dll'<br>var<br> &nbsp;frmmain: Tfrmmain;<br><br>implementation<br><br>{$R *.dfm}<br><br>procedure Tfrmmain.Button1Click(Sender: TObject);<br>begin<br> &nbsp; &nbsp;showkhxx(application.Handle);<br>end;<br><br>procedure Tfrmmain.FormCreate(Sender: TObject);<br>begin<br><br>end;<br><br>end.<br>出现的问题<br>project p_main.exe raised &nbsp;exception &nbsp;class &nbsp;EOleSysErro &nbsp;with message '尚未调用coinitialze.' process &nbsp;stopped.use step or run to cotinue
 
在你的外壳函数里要加上uese上一个单元好象是关于com接口的一个单元<br>你在网上查查!
 
是不是ShareMem的问题?
 
uses<br> activex<br><br>在出现问题地方之前加入 ActiveX.coinitialze<br>调完后加Activex.Uninitialze
 
uses<br> activex;<br>加入一句CoInitialize(nil);
 
调用了数据库在调用前应用CoInitialze,调用完后再次调用UnCoInitialze就可以了
 
我加入 activex<br>主程如下:<br>library khxx_dll;<br><br>{ Important note about DLL memory management: ShareMem must be the<br> &nbsp;first unit in your library's USES clause AND your project's (select<br> &nbsp;Project-View Source) USES clause if your DLL exports any procedures or<br> &nbsp;functions that pass strings as parameters or function results. This<br> &nbsp;applies to all strings passed to and from your DLL--even those that<br> &nbsp;are nested in records and classes. ShareMem is the interface unit to<br> &nbsp;the BORLNDMM.DLL shared memory manager, which must be deployed along<br> &nbsp;with your DLL. To avoid using BORLNDMM.DLL, pass string information<br> &nbsp;using PChar or ShortString parameters. }<br><br>uses<br> &nbsp;Windows,<br> &nbsp;SysUtils,<br> &nbsp;Classes,<br> &nbsp;Forms,<br> &nbsp;Dialogs,<br> &nbsp;DbTables,<br> &nbsp;activex,<br> &nbsp;u_khxx in 'u_khxx.pas' {frmkhxx},<br> &nbsp;u_ado in '../try2/u_ado.pas' {Form1};<br><br>var<br> &nbsp; DLLApp:TApplication;<br> &nbsp; DLLScr:TScreen;<br> &nbsp; DLLAppHandle:THandle;<br>{$R *.res}<br><br>procedure DLLEntryPoint(dwReason: DWORD); stdcall; //register; //stdcall;<br>begin<br> &nbsp; case dwReason of<br> &nbsp; &nbsp; &nbsp;DLL_PROCESS_ATTACH: //1<br> &nbsp; &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp; &nbsp; DLLAppHandle := Application.Handle;<br> &nbsp; &nbsp; &nbsp; &nbsp; DLLApp := Application;<br> &nbsp; &nbsp; &nbsp; &nbsp; DLLScr := Screen;<br> &nbsp; &nbsp; &nbsp; &nbsp; ActiveX.coinitialze;<br> &nbsp; &nbsp; &nbsp;end;<br> &nbsp; &nbsp; &nbsp;DLL_PROCESS_DETACH: //3<br> &nbsp; &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Application := DllApp;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Screen := DllScr;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Activex.Uninitialze &nbsp;;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Application.Handle := DLLAppHandle;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; try<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; session.Free<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; except<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;raise &nbsp;exception.Create('error')<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end;<br> &nbsp; &nbsp; &nbsp;end;<br> &nbsp; &nbsp; &nbsp;DLL_THREAD_ATTACH : {ShowMessage('Thread Attach')}; &nbsp;//2<br> &nbsp; &nbsp; &nbsp;DLL_THREAD_DETACH : {ShowMessage('Thread Detach')}; &nbsp;//0<br> &nbsp; end;<br>end;<br><br>exports<br> &nbsp; &nbsp;showkhxx;<br>begin<br> DLLProc := @DLLEntryPoint; &nbsp; &nbsp; &nbsp; &nbsp; //Assign the address of DLLEntryPoint to DLLProc<br> DLLEntryPoint(DLL_PROCESS_ATTACH);<br>end.<br>但仍出现如现错误提示<br>[Error] khxx_dll.dpr(38): Undeclared identifier: 'coinitialze'<br>[Error] khxx_dll.dpr(44): Undeclared identifier: 'Uninitialze'<br>首先送分感谢各位大哥的指点
 
多人接受答案了。
 
后退
顶部