资源描述:
《c 中如何调用动态链接库dll(how to call dynamic link library dll in c )》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、c#中如何调用动态链接库dll(HowtocalldynamiclinklibraryDLLinc#)EachprogramminglanguagecallsDLLmethodsarenotthesame,inthisonlyfortheuseofC#callDLLmethodisintroduced.Firstofall,youneedtoknowwhatescrowisandwhatunmanagedis.Itcanbegenerallyconsidered:unmanagedcodeismainlybasedonwin32platformdevelopedDLL,activeXcom
2、ponents,managedcodeisdevelopedbasedonthe.Netplatform.Ifyouwanttothoroughlyunderstandtherelationshipanddifferencebetweentrusteeshipandunmanaged,andtheiroperatingmechanism,pleasefindthedatayourself,thisdocumentisnotdiscussedhere.(1)thegeneralmethodofcallingunmanagedfunctionsinDLLFirst,theexternalmet
3、hodshouldbedeclaredintheC#languagesourceprogram.Thebasicformis:[DLLImport("DLLfile")]Themodifierexternreturnsthevariabletypemethodname(parameterlist)Amongthem:DLLfile:alibraryfilethatcontainsanexternalmethod.Modifiers:accessmodifiers,modifiersotherthanabstract,thatcanbeusedtodeclaremethods.Returnv
4、ariabletype:intheDLLfile,youneedtocallthereturnvariabletypeofthemethod.Methodname:intheDLLfile,youneedtocallthenameofthemethod.Parameterlist:intheDLLfile,youneedtocallthelistofmethods.Note:youneedtousetheSystem.Runtime.InteropServicesnamespaceintheprogramdeclaration.DllImportcanonlybeplacedontheme
5、thodstatement.TheDLLfilemustbelocatedinthecurrentdirectoryoftheprogramorinthequerypathdefinedbythesystem(i.e.,thepathsetbyPathinthesystemenvironmentvariable).Thereturnvariabletype,methodname,andparameterlistmustbeconsistentwiththedefinitionintheDLLfile.Touseotherfunctionnames,youcanusetheEntryPoin
6、tpropertysettings,suchas:[DllImport("user32.dll","EntryPoint=","MessageBoxA")StaticexternintMsgBox(inthWnd,stringMSG,stringcaption,inttype);OtheroptionalDllImportAttributeattributes:CharSetindicatesthesetofcharactersusedattheentrypoint,suchas:CharSet=CharSet.Ansi;SetLastErrorindicateswhethertheWin
7、32"lastmistake"isretained,suchas:SetLastError=true;ExactSpellingindicateswhetherEntryPointmustmatchthespellingoftheentrypointoftheinstruction,suchas:ExactSpelling=false;ShouldthesignatureofthePreserveSiginstructi