{"id":758,"date":"2008-05-26T01:03:11","date_gmt":"2008-05-26T01:03:11","guid":{"rendered":"http:\/\/6teen.ru\/?p=313"},"modified":"2008-05-26T01:03:11","modified_gmt":"2008-05-26T01:03:11","slug":"3925","status":"publish","type":"post","link":"http:\/\/pblog.ru\/lab\/?p=758","title":{"rendered":"\u041a\u0430\u043a \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0444\u043e\u0440\u043c\u044b, \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u043d\u044b\u0435 \u0432 DLL"},"content":{"rendered":"<p>\u041a\u0430\u043a \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0444\u043e\u0440\u043c\u044b, \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u043d\u044b\u0435 \u0432 DLL<br \/>\n<!--more--><\/p>\n<pre class=\"alt2\" style=\"margin:0px; padding:6px; border:1px inset; width:580px; height:320px; overflow:auto\"><div>\u041a\u0430\u043a \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0444\u043e\u0440\u043c\u044b, \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u043d\u044b\u0435 \u0432 DLL\n\nin the example that follows the exe only sees a totally \"virtual\nabstract\" interface to the object as is being exported from the dll\nbut it still can create the object and use it.\nof course the exe can not see or execute any methods declared in the\nexe but that is the whole purpose of implementing them in a custom dll\nto begin with.\n\nim folgenden beispiel sieht die exe-datei nur ein total \"virtuelles, abstraktes\"\ninterface zum objekt, welches aus der dll importiert wird aber es\nkann doch dieses objekt erzeugen und es gebrauchen.\n}\n\n\n\/\/ example code:\n\nprogram dlloader;\n\nuses\nsharemem,\nforms,\nexeunit1 in 'exeunit1.pas' {form1},\ndllintfu in 'dllintfu.pas';\n\n{$r *.res}\n\nbegin\napplication.initialize;\napplication.createform(tform1, form1);\napplication.run;\nend.\n\n\/\/--------------------------\n\nunit dllintfu;\n\ninterface\n\ntype\ntdllobject = class\nprotected\nfunction get_username: string; virtual; abstract;\nprocedure set_username(value: string); virtual; abstract;\npublic\nproperty username: string read get_username write set_username;\nend;\ntdllobjectclass = class of tdllobject;\n\nimplementation\n\nend.\n\n\/\/---------------------------\n\nunit exeunit1;\n\ninterface\n\nuses\nwindows, messages, sysutils, classes, graphics,\ncontrols, forms, dialogs, dllintfu, stdctrls;\n\ntype\ntform1 = class(tform)\nbutton1: tbutton;\nprocedure button1click(sender: tobject);\nprivate\n{ private declarations }\npublic\n{ public declarations }\nend;\n\nvar\nform1: tform1;\n\nimplementation\n\n{$r *.dfm}\n\ntype\ntdllfunc = function: tdllobjectclass;\nstdcall;\n\nprocedure tform1.button1click(sender: tobject);\nvar\ni: dword;\nfhandle: thandle;\nfdllfunc: tdllfunc;\nfdllobject: tdllobject;\nfusername: string;\nbegin\nfhandle := loadlibrary('username.dll');\nif (fhandle <> 0) then\nbegin @fdllfunc := getprocaddress(fhandle, 'dllfunc');\nif assigned(@fdllfunc) then\nbegin\ni := 255;\nsetlength(fusername, i);\ngetusername(pchar(fusername), i);\nfusername := strpas(pchar(fusername));\nfdllobject := fdllfunc.create;\nfdllobject.username := fusername;\nshowmessage(fdllobject.username);\nfdllobject.free;\nend;\nfreelibrary(fhandle);\nend;\nend;\n\nend.\n\n\/\/-------------------------------\n\nlibrary username;\n\nuses\nsharemem,\nsysutils,\ndllintfu;\n\ntype\ntcustomdllobject = class(tdllobject)\nprivate\nfusername: string;\nfunction getfilecount: integer;\nprotected\nfunction get_username: string; override;\nprocedure set_username(value: string); override;\nend;\n\ntcustomdllobjectclass = class of tcustomdllobject;\n\nfunction tcustomdllobject.getfilecount: integer;\nvar\ndoserr: integer;\nfsrch: tsearchrec;\nbegin\nresult := 0;\ndoserr := findfirst('*.*', faanyfile, fsrch);\nif (doserr = 0) then\nbegin\nwhile (doserr = 0) do\nbegin\nif (fsrch.attr and fadirectory) = 0 then\ninc(result);\ndoserr := findnext(fsrch);\nend;\nfindclose(fsrch);\nend;\nend;\n\nfunction tcustomdllobject.get_username: string;\nbegin\nresult := 'you signed on as ''' + fusername + '''' +\n' and there ' + inttostr(getfilecount) +\n' files in this directory.';\nend;\n\nprocedure tcustomdllobject.set_username(value: string);\nbegin\nfusername := value;\nend;\n\nfunction dllfunc: tcustomdllobjectclass; stdcall;\nbegin\nresult := tcustomdllobject; \/\/ class type only\nend;\n\nexports\ndllfunc name 'dllfunc';\n\nbegin\nend.\n<\/div><\/pre>\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u041a\u0430\u043a \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0444\u043e\u0440\u043c\u044b, \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u043d\u044b\u0435 \u0432 DLL<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[16,402],"tags":[1907,867,1034],"_links":{"self":[{"href":"http:\/\/pblog.ru\/lab\/index.php?rest_route=\/wp\/v2\/posts\/758"}],"collection":[{"href":"http:\/\/pblog.ru\/lab\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/pblog.ru\/lab\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/pblog.ru\/lab\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"http:\/\/pblog.ru\/lab\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=758"}],"version-history":[{"count":0,"href":"http:\/\/pblog.ru\/lab\/index.php?rest_route=\/wp\/v2\/posts\/758\/revisions"}],"wp:attachment":[{"href":"http:\/\/pblog.ru\/lab\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=758"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/pblog.ru\/lab\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=758"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/pblog.ru\/lab\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=758"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}