资源描述:
《c 如何动态调用dll中的函数(how does c dynamically call functions in dll)》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、c#如何动态调用dll中的函数(Howdoesc#dynamicallycallfunctionsinDLL)Topic:howtodynamicallycallfunctionsinDLL(urgent)!Onlinewaiting)Author:wltj(WulinTianjiao)Grade:Reputationvalue:100Forum:.NETtechnologyC#Problempoints:20Numberofreplies:12Publicationtime:2004-3-1910:27:51Imean,Idon'tknowthenameofDLL
2、inadvance,thatis,Idon'tknowwhichDLLtocall.ButthefunctionnamesareunifiedReplyperson:Ninputer(assemblyhead)(reputation):852004-3-1910:40:37score:0Yes,isit.NET'sDLL?TopReplytopeople:mfc2003(programmingprodigalson)(reputation):1002004-3-1910:46:51score:0MaybenotIftwoDLLhavethesamefunction,
3、andthenumberofparametersisthesamequantityandtypeTopReplyperson:fq_ln(winter)()reputation:1002004-3-1910:55:13score:0Dynamiclinklibrariesareessentiallydifferent1,ifyoucalladynamiclinklibrarywritteninVC,youdon'tknowifthefunctionnameisunavailable,ifyoucanprovidetheheaderfile.2ifyoucallAct
4、iveDLL,thenyoushouldregisterfirst,andthenyoucanusecom.3ifyoucallDLLwrittenin.Net,thendirectreferenceisOKTopReplytopeople:wltj(martialartsTianjiao)(credit):1002004-3-1911:17:34score:0I'mcalling.Net'sDLL,andit'snotasifit'sadirectquote.Becauseyoudon'tknowthefilenameofDLLinadvance.TopReply
5、topeople:wltj(martialartsTianjiao)(credit):1002004-3-1912:06:16score:0Theproblemnowisthatyoudon'tknowthenameoftheDLLinadvance(butyoucangetthenameintheprogram,butstoredinthevariable).HowdoyougenerateaninstanceofaclassintheDLL?TopReplyperson:Ninputer(assemblyhead)(reputation):852004-3-19
6、13:23:44score:15Itturnedouttobe.NET'sDLL,anditcouldbedone!Youneedreflection.YoucanreadthecollectionprogramwithAssembly(yourDLL)information,andthenturninto,readtype,method(ifyouknowhowtocallthemethodbetter),attributeinformation,andthendynamicallycreatedobjects,theexecutionmethodwithrefl
7、ection,OKIt'smoreconvenienttouseVBbecauseVBencapsulatesapartofthereflectedcode,especiallywhendealingwithlatebindingproblems,mucheasierthanC#.TopReplytopeople:wltj(martialartsTianjiao)(credit):1002004-3-1913:46:15score:0DoyoumeantousetheCreateInstancefunctionupstairs?Itseemsthattheret