时间: 2021-07-31 作者:daque
extren重要用来证明在外部实行的本领,什么叫外部实行的本领呢,普遍说来即是用system.runtime.interopservices效劳的dllimport本领引入非托管代码步调集。比方挪用步调api,c谈话写的本领之类。在这种情景下,证明必需为static
同声,extren要害字还不妨设置外部步调集别号,使得不妨从单个步调会合援用同一组件的各别本子。
底下是一个改写自msdn上的大略的例子,挪用体例winmm.dll播放wav文献:
//体例api的挪用的证明
[system.runtime.interopservices.dllimport("winmm.dll", entrypoint = "playsound", setlasterror = true)]
public static extern void playsound(string path,system.intptr hmod,playsoundflags flags);
//挪用该本领
string path = @“c:\22.wav”;
try
{
playsound(path, new system.intptr(), playsoundflags.snd_sync);
}
catch (exception ex)
{
throw (ex);
}