Beispiel #1
0
// Read from stream
void CShader::Read_t(CTStream *istrFile)
{
  // read the dll filename and class name from the stream
  CTFileName fnmDLL;
  CTString strShaderFunc;
  CTString strShaderInfo;

  fnmDLL.ReadFromText_t(*istrFile, "Package: ");
  strShaderFunc.ReadFromText_t(*istrFile, "Name: ");
  strShaderInfo.ReadFromText_t(*istrFile, "Info: ");

  // create name of dll
  #ifndef NDEBUG
    fnmDLL = _fnmApplicationExe.FileDir()+fnmDLL.FileName()+/*_strModExt+*/"D"+fnmDLL.FileExt();
  #else
    fnmDLL = _fnmApplicationExe.FileDir()+fnmDLL.FileName()+/*_strModExt+*/fnmDLL.FileExt();
  #endif

  CTFileName fnmExpanded;
  ExpandFilePath(EFP_READ | EFP_NOZIPS,fnmDLL,fnmExpanded);
  // set new error mode
  UINT iOldErrorMode = SetErrorMode(SEM_NOOPENFILEERRORBOX|SEM_FAILCRITICALERRORS);
  // load dll
  hLibrary = LoadLibraryA((const char*)fnmExpanded);
  // return last error mode
  SetErrorMode(iOldErrorMode);
  // check if library has loaded
  if(hLibrary==NULL)
  {
    // report error
    istrFile->Throw_t("Error loading '%s' library",(const char*)fnmExpanded);
    return;
  }
  // get pointer to shader render function
  ShaderFunc = (void(*)(void))GetProcAddress(hLibrary,(const char*)strShaderFunc);
  // if error accured
  if(ShaderFunc==NULL)
  {
    // report error
    istrFile->Throw_t("GetProcAddress 'ShaderFunc' Error");
  }
  // get pointer to shader info function
  GetShaderDesc = (void(*)(ShaderDesc&))GetProcAddress(hLibrary,(const char*)strShaderInfo);
  // if error accured
  if(GetShaderDesc==NULL) {
    // report error
    istrFile->Throw_t("GetProcAddress 'ShaderDesc' Error");
  }
}