DelphiÖи߼¶DLLµÄ±àдºÍµ÷Óü¼ÇÉ
¸ù¾ÝDelphiÌṩµÄÓÐ¹Ø DLL±àдºÍµ÷ÓõİïÖúÐÅÏ¢£¬Äã¿ÉÒԺܿìÍê³ÉÒ»°ãµÄ DLL±àдºÍµ÷ÓÃµÄ Ó¦ÓóÌÐò¡£±¾ÎĽéÉܵÄÖ÷ÌâÊÇÈçºÎ±àдºÍµ÷ÓÃÄܹ»´«µÝ¸÷ÖÖ²ÎÊý£¨°üÀ¨¶ÔÏóʵÀý£©µÄ DLL¡£ÀýÈ磬 Ö÷½Ð³ÌÐò´«µÝ¸ø DLLÒ»¸öADOConnection ¶ÔÏóʾÀý×÷Ϊ²ÎÊý£¬ DLLÖеĺ¯ÊýºÍ¹ý³Ìµ÷ÓÃͨ¹ý¸Ã¶ÔÏó ʵÀý·ÃÎÊÊý¾Ý¿â¡£
ÐèÒªÃ÷ȷһЩ»ù±¾¸ÅÄî¡£¶ÔÓÚ DLL£¬ÐèÒªÔÚÖ÷³ÌÐòÖаüº¬ exports×Ӿ䣬ÓÃÓÚÏòÍâ½çÌṩµ÷Óà ½Ó¿Ú£¬×Ó¾äÖоÍÊÇһϵÁк¯Êý»ò¹ý³ÌµÄÃû×Ö¡£¶ÔÓÚÖ÷½Ð·½£¨µ÷Óà DLLµÄÓ¦ÓóÌÐò»òÆäËüµÄ DLL£©£¬ ÔòÐèÒªÔÚµ÷ÓÃ֮ǰ½øÐÐÍⲿÉùÃ÷£¬¼´external±£Áô×ÖָʾµÄÉùÃ÷¡£ÕâЩÊDZàд DLLºÍµ÷Óà DLL±ØÐë ¾ß±¸µÄÒªËØ¡£
ÁíÍâÐèÒªÁ˽âObject Pascal ÖÐÓйص÷ÓÃÐÒéµÄÄÚÈÝ¡£ÔÚObject Pascal ÖУ¬¶ÔÓÚ¹ý³ÌºÍº¯Êý ÓÐÒÔÏÂÎåÖÖµ÷ÓÃÐÒ飺
ָʾ×Ö ²ÎÊý´«µÝ˳Ðò ²ÎÊýÇå³ýÕß ²ÎÊýÊÇ·ñʹÓüĴæÆ÷
register ×Ô×óÏòÓÒ ±»µ÷Àý³Ì ÊÇ
pascal ×Ô×óÏòÓÒ ±»µ÷Àý³Ì ·ñ
cdecl ×ÔÓÒÏò×ó µ÷ÓÃÕß ·ñ
stdcall ×ÔÓÒÏò×ó ±»µ÷Àý³Ì ·ñ
safecall ×ÔÓÒÏò×ó ±»µ÷Àý³Ì ·ñ
ÕâÀïµÄָʾ×Ö¾ÍÊÇÔÚÉùÃ÷º¯Êý»ò¹ý³Ìʱ¸½¼ÓÔÚÀý³Ì±êÌâÖ®ºóµÄ±£Áô×Ö£¬Ä¬ÈÏΪregister£¬¼´ÊÇ Î¨Ò»Ê¹Óà CPU¼Ä´æÆ÷µÄ²ÎÊý´«µÝ·½Ê½£¬Ò²ÊÇ´«µÝËÙ¶È×î¿ìµÄ·½Ê½£»
pascal: µ÷ÓÃÐÒé½öÓÃÓÚÏòºó¼æÈÝ£¬¼´Ïò¾ÉµÄ°æ±¾¼æÈÝ£»
cdecl: ¶àÓÃÓÚ CºÍ C++ÓïÑÔ±àдµÄÀý³Ì£¬Ò²ÓÃÓÚÐèÒªÓɵ÷ÓÃÕßÇå³ý²ÎÊýµÄÀý³Ì£»
stdcall: ºÍsafecallÖ÷ÒªÓÃÓÚµ÷ÓÃWindows API º¯Êý£»ÆäÖÐsafecall»¹ÓÃÓÚË«Öؽӿڡ£
ÔÚ±¾ÀýÖУ¬½«Ê¹Óõ÷ÓÃÐÒécdecl £¬ÒòΪ±»µ÷ÓÃµÄ DLLÖУ¬Ê¹ÓõÄÊý¾Ý¿âÁ¬½ÓÊÇÓÉÖ÷½Ð·½´«µÝ µÃµ½µÄ£¬²¢ÇÒÐèÒªÓÉÖ÷½Ð·½´¦ÀíÁ¬½ÓµÄ¹Ø±ÕºÍÏú»Ù¡£
ÏÂÃæÊÇ DLLÍêÕûÔ´³ÌÐòºÍÖ÷½Ð³ÌÐòÍêÕûÔ´³ÌÐò¡£°üÀ¨ÒÔÏÂËĸöÎļþ£º
Project1.DPR {Ö÷½Ð³ÌÐò}
Unit1.PAS {Ö÷½Ð³ÌÐòµ¥Ôª}
Project2.DPR {DLL}
Unit2.PAS {DLLµ¥Ôª}
{---------- DLL Ö÷³ÌÐò Project2.DPR ----------}
library Project2;
uses
SysUtils,
Classes,
Unit2 in 'Unit2.pas' {Form1};
{$R *.RES}
{ ÏÂÃæµÄÓï¾äÓÃÓÚÏòµ÷Óøà DLLµÄ³ÌÐòÌṩµ÷ÓÃ½Ó¿Ú }
exports
DoTest; { ¹ý³ÌÀ´×Ôµ¥ÔªUnit2 }
begin
end.
{---------- DLLÖеĵ¥Ôª Unit2.PAS ----------}
unit Unit2;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Db, ADODB, StdCtrls, Menus;
type
TForm1 = class(TForm)
ADOConnection1: TADOConnection;{ ±¾µØÊý¾Ý¿âÁ¬½Ó }
Memo1: TMem
Ïà¹ØÎĵµ£º
²éÕÒÁíÍâÒ»¸ö´°¿ÚµÄ¾ä±ú£º handle := FindWindow(nil,PChar('´°¿ÚµÄ±êÌâ'));//²éµ½´°Ìå¾ä±ú
²éÕÒ×Ó´°Ì壺childHandle := FindWindowEx(handle,0,'×Ó´°ÌåÀà','×Ó´°Ìå±êÌâ');
ÁíÍâÓиöö¾Ù×Ó´°ÌåµÄAPI£¬EnumChildWindows(Ö÷´´Ìå¾ä±ú,@»Øµ÷º¯Êý,Óû§²ÎÊý);
ÓÃÕâ¸öº¯ÊýÐèÒª×Ô¼ºÐ´Ò»¸ö»Øµ÷µÄº¯Êý£¬±ÈÈ磺
function EnumChil ......
¼¼Êõ½»Á÷,DH½²½â. Ê×ÏÈÎÒÃÇÒªÖªµÀʲôÊÇÊý×é?Êý×éÊÇÒ»¶ÑÏàͬÌØÐÔÊý¾ÝµÄÒ»¸ö¼¯ºÏ,Ò²¾ÍÊÇÿ¸öÔªËصÄÀàÐͱØÐëÊÇÒ»ÑùµÄ,µ±È»ÔÚÆäËûһЩÈõÓï·¨µÄÓïÑÔÀïÃæ,Êý×éµÄÔªËØ¿ÉÒÔǧÆæ°Ù¹Ö.
Àý×Ó: Var
A: Array[ 0..2 ] Of Integer ;
Begin
A[ 0 ] := 1 ;
A[ 1 ] := 1.0 ; //ÕâÀïÊÇ´íµÄ,ÒòΪÿ¸öÔªËض¼±ØÐëÊÇIntegerÀàÐ ......
¼¼Êõ½»Á÷,DH½²½â. ½ñÌìÀ´ÊµÏÖÒ»¸ö¼òµ¥µÄÎå×ÓÆå,Ö±½ÓÓÃGDIÀ´»µÄÒ»¸öÓÎÏ·.
Ê×ÏÈÎÒÃÇÀ´ÏëÏÂÔõô´æ·ÅÊý¾Ý,ÄÄЩµØ·½ÊÇ°×Æå,ÄÄЩµØ·½ÊǺÚÆå,ÄÄЩµØ·½Ã»ÓÐÏÂÆå?
¶Ô,ÎÒÃÇÓÃÒ»¸ö¶þάÊý×é,Èç¹ûÊý×éÖÐijһ¸öλÖõÄֵΪ0´ú±íûÓÐÏÂÆå,Ϊ1´ú±íÊÇ°×Æå,Ϊ2´ú±íÊǺÚÆå.
ºÃ¾ÍÕâô˵¶¨ÁË,ΪÁËʹÓ÷½±ã,ÎÒÃÇ´òËã×ö³ÉÒ»¸ö¿Ø¼ ......
º¯ÊýÒ»£º
view plaincopy to clipboardprint?
uses
Windows,
SysUtils,
Classes,
ShellAPI;
function RunAndWait(FileName: string; Visibility: Integer): THandle;&nbs ......