ÓÃDelphiÖÆ×÷DLL
Ò» DllµÄÖÆ×÷Ò»°ã²½Öè
¶þ ²ÎÊý´«µÝ
Èý DLLµÄ³õʼ»¯ºÍÍ˳öÇåÀí[Èç¹ûÐèÒª³õʼ»¯ºÍÍ˳öÇåÀí]
ËÄ È«¾Ö±äÁ¿µÄʹÓÃ
Îå µ÷Óþ²Ì¬ÔØÈë
Áù µ÷Óö¯Ì¬ÔØÈë
Æß ÔÚDLL½¨Á¢Ò»¸öTForM
°Ë ÔÚDLLÖн¨Á¢Ò»¸öTMDIChildForM
¾Å ʾÀý£º
Ê® DelphiÖÆ×÷µÄDllÓëÆäËûÓïÑԵĻìºÏ±à³ÌÖг£ÓöÎÊÌ⣺
ʮһ Ïà¹Ø×ÊÁÏ
Ò» DllµÄÖÆ×÷Ò»°ã·ÖΪÒÔϼ¸²½£º
1 ÔÚÒ»¸öDLL¹¤³ÌÀïдһ¸ö¹ý³Ì»òº¯Êý
2 дһ¸öExports¹Ø¼ü×Ö£¬ÔÚÆäÏÂд¹ý³ÌµÄÃû³Æ¡£²»ÓÃд²ÎÊýºÍµ÷Óúó׺¡£
¶þ ²ÎÊý´«µÝ
1 ²ÎÊýÀàÐÍ×îºÃÓëwindow C++µÄ²ÎÊýÀàÐÍÒ»Ö¡£²»ÒªÓÃDELPHIµÄÊý¾ÝÀàÐÍ¡£
2 ×îºÃÓзµ»ØÖµ[¼´Ê¹ÊÇÒ»¸ö¹ý³Ì]£¬À´±¨³öµ÷Óóɹ¦»òʧ°Ü£¬»ò״̬¡£³É¹¦»òʧ°ÜµÄ·µ»ØÖµ×îºÃΪ1[³É¹¦]»ò0[ʧ°Ü].Ò»¾ä»°£¬Óëwindows c++¼æÈÝ¡£
3 ÓÃstdcallÉùÃ÷ºó׺¡£
4 ×îºÃ´óСдÃô¸Ð¡£
5 ÎÞÐëÓÃfarµ÷Óúó׺£¬ÄÇÖ»ÊÇΪÁËÓëwindows 16λ³ÌÐò¼æÈÝ¡£
Èý DLLµÄ³õʼ»¯ºÍÍ˳öÇåÀí[Èç¹ûÐèÒª³õʼ»¯ºÍÍ˳öÇåÀí]
1 DLLProc[SysUtilsµ¥ÔªµÄÒ»¸öPointer]ÊÇDLLµÄÈë¿Ú¡£ÔÚ´ËÄã¿ÉÓÃÄãµÄº¯ÊýÌæ»»ÁËËüµÄÈë¿Ú¡£µ«ÄãµÄº¯Êý±ØÐë·ûºÏÒÔÏÂÒªÇó[Æäʵ¾ÍÊÇÒ»¸ö»Øµ÷º¯Êý]¡£ÈçÏ£º
procedure DllEnterPoint(dwReason: DWORD);far;stdcall;
dwReason²ÎÊýÓÐËÄÖÖÀàÐÍ£º
DLL_PROCESS_ATTACH:½ø³Ì½øÈëʱ
DLL_PROCESS_DETACH½ø³ÌÍ˳öʱ
DLL_THREAD_ATTACH Ï߳̽øÈëʱ
DLL_THREAD_DETACH Ïß³ÌÍ˳öʱ
ÔÚ³õʼ»¯²¿·Öд:
DLLProc := @DLLEnterPoint;
DllEnterPoint(DLL_PROCESS_ATTACH);
2 ÈçFormÉÏÓÐTdcomConnection×é¼þ,¾ÍUses Activex,ÔÚ³õʼ»¯Ê±Ð´Ò»¾äCoInitialize (nil);
3 ÔÚÍ˳öʱһ¶¨±£Ö¤DcomConnection.Connected := False,²¢ÇÒÊý¾Ý¼¯Òѹرա£·ñÔò±¨µØÖ·´í¡£
ËÄ È«¾Ö±äÁ¿µÄʹÓÃ
ÔÚwidnows 32λ³ÌÐòÖУ¬Á½¸öÓ¦ÓóÌÐòµÄµØÖ·¿Õ¼äÊÇÏ໥ûÓÐÁªÏµµÄ¡£ËäÈ»DLLÔÚÄÚ´æÖÐÊÇÒ»·Ý£¬µ«±äÁ¿ÊÇÔÚ¸÷½ø³ÌµÄµØÖ·¿Õ¼äÖУ¬Òò´ËÄã²»ÄܽèÖúdllµÄÈ«¾Ö±äÁ¿À´´ïµ½Á½¸öÓ¦ÓóÌÐò¼äµÄÊý¾Ý´«µÝ£¬³ý·ÇÄãÓÃÄÚ´æÓ³ÏñÎļþ¡£
Îå µ÷Óþ²Ì¬ÔØÈë
1 ¿Í»§¶Ëº¯ÊýÉùÃû:
1)´óСдÃô¸Ð¡£
2)ÓëDLLÖеÄÉùÃ÷Ò»Ñù¡£
È磺 showform(form:Tform);Far;external'yproject_dll.dll';
3)µ÷ÓÃʱ´«¹ýÈ¥µÄ²ÎÊýÀàÐÍ×îºÃÒ²Óë
Ïà¹ØÎĵµ£º
Ò») ʹÓö¯Ì¬´´½¨µÄ·½·¨
Ê×ÏÈ´´½¨ Excel ¶ÔÏó£¬Ê¹ÓÃComObj:
var ExcelApp: Variant;
ExcelApp := CreateOleObject( 'Excel.Application'  ......
ADO¶àÏß³ÌÊý¾Ý¿â²éѯͨ³£»á³öÏÖ3¸öÎÊÌ⣺
1¡¢CoInitialize ûÓе÷ÓÃ
£¨CoInitialize was not
called£©£»ËùÒÔ£¬ÔÚʹÓÃÈκÎdbGo¶ÔÏóÇ°£¬±ØÐëÊÖ
µ÷ÓÃCoInitializeºÍCoUninitialize¡£µ÷ÓÃCoInitializeʧ°Ü»á²úÉú"CoInitialize was not
called"ÀýÍâ¡£
2¡¢»²¼²»ÔÊÐí»æ»
£¨Canvas does not allow
drawing£ ......
3.2 Óû§µÇ¼·½°¸
ÔÚ½øÈëÒ»¸öϵͳʱ£¬±ØÐëÏÈÔڵǼ´°ÌåÖÐÊäÈëÕýÈ·µÄÓû§ÃûºÍÃÜÂë²ÅÄܽøÈë¡£ÕâÑù¿ÉÒÔÈ·±£ÏµÍ³µÄ°²È«ÐԺͱ£ÃÜÐÔ£¬µÇ¼´°ÌåµÄÖÆ×÷°´ÕÕϵͳµÄ´óС¼°Óô¦£¬¿ÉÒÔ·ÖΪ²»Í¬µÄµÇ¼´°ÌåÑùʽ£¬ÔÚϵͳµÚÒ»´ÎµÇ¼ǰ£¬Ê×ÏÈÒª¶Ô²Ù×÷Ô±ÐÅÏ¢½øÐÐÏàÓ¦µÄÉèÖᣱ¾½Ú½«¶ÔµÇ¼´°Ìå¼°²Ù×÷Ô±¹ÜÀí´°ÌåµÄÖÆ×÷¹ý³Ì½øÐÐÏêϸµÄ˵Ã÷ ......
ÎÒÃÇÄÜ¿´µ½ÒÔÏ´úÂë
var pSource,pDest:PChar;
len: integer;
.......................//һЩ´úÂë
Move(pSource,pDest,len); //´íÎó
Move(pSource^,pDest^,len); //ÕýÈ·
¿´ÆðÀ´È·ÊµºÃÏñÊÇ´«Öµ£¬¶ø²»ÊÇ´«µØÖ·£¬µ«ÊǸ÷λ±ðÍüÁË£¬Õâ²»ÊÇC£¬C++£¬¶øÊÇDelphi
Object Pascal,ËùÒÔ£¬¾ø²»ÄÜ´Óº¯Êýµ ......
¶¯Ì¬Á´½Ó¿âÊÇÒ»¸öÄܹ»±»Ó¦ÓóÌÐòºÍÆäËüµÄDLLµ÷ÓõĹý³ÌºÍº¯ÊýµÄ¼¯ºÏÌå,ËüÀïÃæ°üº¬µÄÊǹ«¹²´úÂë»ò×ÊÔ´¡£ÓÉÓÚDLL´úÂëʹÓÃÁËÄÚ´æ¹²Ïí¼¼Êõ,ÔÚijЩµØ·½windowsÒ²¸øÁËDLLһЩ¸ü¸ßµÄȨÏÞ,Òò¶øDLLÖпÉÒÔʵÏÖһЩһ°ã³ÌÐòËù²»ÄÜʵÏֵŦÄÜ,ÈçʵÏÖwindowsµÄHOOK¡¢ISAPIµÈ¡£Í¬Ê±,DLL»¹Îª²»Í¬ÓïÑÔ¼ä´úÂë¹²ÏíÌṩÁËÒ»Ìõ·½±ãµÄ;¾¶¡£Òò¶øD ......