Thread: Avisynth+
View Single Post
Old 29th December 2019, 21:34   #5012  |  Link
Groucho2004
 
Join Date: Mar 2006
Location: Barcelona
Posts: 5,034
For reference, this is how I initialise (and destroy) IScriptEnvironment for AVS 2.6 (AVISYNTH_INTERFACE_VERSION 5/6):

Code:
const AVS_Linkage *AVS_linkage = 0;
typedef IScriptEnvironment * __stdcall CREATE_ENV(int);

int main()
{
  int iInterfaceVersion;
  IScriptEnvironment *AVS_env = 0;

  HINSTANCE hDLL = ::LoadLibrary("avisynth");
  if (!hDLL)
  {
    //Cannot load avisynth.dll
    return -1;
  }

  try
  {
    CREATE_ENV *CreateEnvironment = (CREATE_ENV *)GetProcAddress(hDLL, "CreateScriptEnvironment");
    if (!CreateEnvironment)
    {
      //Cannot load CreateScriptEnvironment()
      ::FreeLibrary(hDLL);
      return -1;
    }

    iInterfaceVersion = 7;
    while (!AVS_env)
    {
      iInterfaceVersion--;

      if (iInterfaceVersion < 5)
      {
        //Cannot create IScriptenvironment (AVSVersion too old)
        ::FreeLibrary(hDLL);
        return -1;
      }

      AVS_env = CreateEnvironment(iInterfaceVersion);
    }

    AVS_linkage = AVS_env->GetAVSLinkage();


    //Do your stuff



    //destroy
    AVS_env->DeleteScriptEnvironment();
    AVS_env = 0;
    AVS_linkage = 0;
  }
  catch (AvisynthError err)
  {
    printf("%s", (PCSTR)err.msg);
  }

  ::FreeLibrary(hDLL);
}
Note: This does not work for Avisynth 2.5!

There are additional checks I do, for example making sure avisynth.dll exports "AVS_linkage". If you're interested, look at the code of AVSMeter and/or avsr (link in my sig).
__________________
Groucho's Avisynth Stuff

Last edited by Groucho2004; 30th December 2019 at 20:23. Reason: updated code
Groucho2004 is offline