Thread: Avisynth+
View Single Post
Old 2nd June 2019, 00:39   #4694  |  Link
Groucho2004
 
Join Date: Mar 2006
Location: Barcelona
Posts: 5,034
Quote:
Originally Posted by wonkey_monkey View Post
I'm writing a C++ program that creates its own Avisynth environment. When I compile it, I get:

Code:
error LNK2001: unresolved external symbol "struct AVS_Linkage const * const AVS_linkage" (?AVS_linkage@@3PEBUAVS_Linkage@@EB)
That goes away if I add:

Code:
#define AVS_LINKAGE_DLLIMPORT
which is what I used to do in my old plugins. Nowadays, in my plugins, I do:

Code:
const AVS_Linkage *AVS_linkage = 0;

extern "C" __declspec(dllexport) const char* __stdcall AvisynthPluginInit3(IScriptEnvironment* env, const AVS_Linkage* const vectors) {
	AVS_linkage = vectors;
	...
but I don't know how to, or if I should, translate this to my standalone C++ program. So - since I have no idea what this vectors thing is about - what's the right thing to do?
Have a look at my avsr code, "avsr.cpp" in particular.
It basically boils down to this:
Code:
//global defs
const AVS_Linkage *AVS_linkage = 0;
typedef IScriptEnvironment * __stdcall CREATE_ENV(int);

HINSTANCE hDLL;
hDLL = ::LoadLibrary("avisynth");

if (!hDLL)
{
  //Error handling
  return;
}

int iInterfaceVersion;
IScriptEnvironment *AVS_env = 0;

try
{
 CREATE_ENV *CreateEnvironment = (CREATE_ENV *)GetProcAddress(hDLL, "CreateScriptEnvironment");
 if (!CreateEnvironment)
 {
  ::FreeLibrary(hDLL);
  //Error handling
  return;
 }

 iInterfaceVersion = 6;
 while (!AVS_env)
 {
  if (iInterfaceVersion < 5)
  {
   ::FreeLibrary(hDLL);
  //Error handling
   return;
  }

  AVS_env = CreateEnvironment(iInterfaceVersion);
  iInterfaceVersion--;
 }

 AVS_linkage = AVS_env->GetAVSLinkage();

 //do your stuff
 ...


 //important!
 AVS_env->DeleteScriptEnvironment();
 AVS_env = 0;
 AVS_linkage = 0;
}
catch (AvisynthError err)
{
  //Error handling
}
catch (other error handling mechanisms)
{
 //Error handling
}

::FreeLibrary(hDLL);
__________________
Groucho's Avisynth Stuff

Last edited by Groucho2004; 2nd June 2019 at 00:57.
Groucho2004 is offline