当前位置: 首页>>代码示例>>C++>>正文


C++ ACE_DLL::open方法代码示例

本文整理汇总了C++中ACE_DLL::open方法的典型用法代码示例。如果您正苦于以下问题:C++ ACE_DLL::open方法的具体用法?C++ ACE_DLL::open怎么用?C++ ACE_DLL::open使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ACE_DLL的用法示例。


在下文中一共展示了ACE_DLL::open方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: basic_test

int basic_test (ACE_DLL &dll)
{

  ACE_TString dll_file;
  const char *subdir_env = ACE_OS::getenv ("ACE_EXE_SUB_DIR");
  if (subdir_env)
    {
      dll_file = ACE_TEXT_CHAR_TO_TCHAR (subdir_env);
      dll_file += ACE_DIRECTORY_SEPARATOR_STR;
    }

  dll_file += OBJ_PREFIX ACE_TEXT ("DLL_Test_Lib") OBJ_SUFFIX;

  int retval = dll.open (dll_file.c_str());

  if (retval != 0)
    {
      ACE_TCHAR *dll_error = dll.error ();
      ACE_ERROR_RETURN ((LM_ERROR,
                         ACE_TEXT ("Error in DLL Open of <%s>: %s\n"),
                         OBJ_PREFIX ACE_TEXT ("DLL_Test_Lib") OBJ_SUFFIX,
                         dll_error ? dll_error : ACE_TEXT ("unknown error")),
                        -1);
    }

  // Just because the ANSI C++ spec says you can no longer cast a
  // void* to a function pointer. Doesn't allow:
  // TC f = (Hello_Factory) dll.symbol ("get_hello");
  void *foo = dll.symbol (ACE_TEXT ("get_hello"));

  // Cast the void* to long first.
  ptrdiff_t tmp = reinterpret_cast<ptrdiff_t> (foo);
  Hello_Factory factory = reinterpret_cast<Hello_Factory> (tmp);
  if (factory == 0)
    ACE_ERROR_RETURN ((LM_ERROR,
                       ACE_TEXT ("%p\n"),
                       dll.error ()),
                      -1);

  auto_ptr<Hello> my_hello (factory ());

  // Make the method calls, as the object pointer is available.
  my_hello->say_hello ();
  my_hello->say_next ();

  // Allocate and delete a string allocated via new in a different dll.
  ACE_TCHAR *new_str = my_hello->new_info ();
  ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Result for new_info(): %s\n"), new_str));
  ACE::strdelete (new_str);

  // Allocate and free a string allocated via malloc in a different dll.
  ACE_TCHAR *malloc_str = my_hello->malloc_info ();
  ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Result for malloc_info(): %s\n"), malloc_str));
  ACE_OS::free (malloc_str);

  return 0;
}
开发者ID:CCJY,项目名称:ACE,代码行数:57,代码来源:DLL_Test.cpp

示例2: funcptr

//
// load_software_probe
//
int Standard_EINode::
load_software_probe (const Einode_Configuration::Software_Probe & probe)
{
  ACE_DLL module;

  if (0 != module.open (probe.location_.c_str (), ACE_DEFAULT_SHLIB_MODE, 0))
    ACE_ERROR_RETURN ((LM_ERROR,
                       ACE_TEXT ("%T (%t) - %M - failed to open %s; %s"),
                       probe.location_.c_str (),
                       module.error ()),
                       -1);

  // Extract the entry point from the module.
  void * symbol = module.symbol (probe.entrypoint_.c_str ());

  if (symbol == 0)
    ACE_ERROR_RETURN ((LM_ERROR,
                       ACE_TEXT ("%T (%t) - %M - symbol '%s' does not exist\n"),
                       probe.entrypoint_.c_str ()),
                       -1);

  // Convert to function pointer that returns to correct type.
  typedef ::OASIS::Software_Probe_Factory * (* ENTRYPOINT) (void);
  ENTRYPOINT funcptr = (ENTRYPOINT) symbol;

  // Create the software probe factory.
  Software_Probe_Factory * factory = funcptr ();

  if (0 == factory)
    return -1;

  // Now, create the software probe using the factory.
  Software_Probe_Impl * probe_impl = factory->create ();

  // Initialize the software probe and register it.
  if (0 != probe_impl->init (probe.params_.c_str (), probe.name_.c_str ()))
    ACE_ERROR_RETURN ((LM_ERROR,
                       ACE_TEXT ("%T (%t) - %M - failed to initialize probe %s\n"),
                       probe.name_.c_str ()),
                       -1);

  if (0 != this->register_probe (probe_impl))
    ACE_ERROR_RETURN ((LM_ERROR,
                       ACE_TEXT ("%T (%t) - %M - failed to register probe %s\n"),
                       probe.name_.c_str ()),
                       -1);

  return 0;
}
开发者ID:EnasAlikhashashashneh,项目名称:OASIS,代码行数:52,代码来源:Standard_EINode.cpp

示例3:

int
run_main (int, ACE_TCHAR *[])
{
  ACE_START_TEST (ACE_TEXT ("Bug_1576_Regression_Test"));

  ACE_DLL dll;

  const ACE_TCHAR * dll_name = ACE_TEXT ("NOT_A_DLL") ACE_DLL_SUFFIX;

  // Normally applications should check the return value, but if they
  // ignore it...
  int result = dll.open (dll_name);

  if(result == -1)
  {
    // Use dll.error() is you want to get the error text, but we don't this in
    // this test because else the error is shown on the scoreboard
    ACE_DEBUG ((LM_DEBUG,
                ACE_TEXT ("Load failed, as expected\n")));
  }
  else
  {
    ACE_ERROR((LM_ERROR,
               ACE_TEXT ("Success loading %s ? It should have failed!\n"),
               dll_name));
  }

  // ... and then use the DLL library, the program crashes (instead of
  // just getting an error ...
  void * symbol = dll.symbol (ACE_TEXT ("SHOULD_CRASH"));

  if(symbol == 0)
  {
    // Use dll.error() is you want to get the error text, but we don't this in
    // this test because else the error is shown on the scoreboard
    ACE_DEBUG((LM_DEBUG,
               ACE_TEXT ("Symbol lookup failed, as expected\n")));
  }
  else
  {
    ACE_ERROR ((LM_ERROR,
                ACE_TEXT ("Found symbol ? It should have failed!\n")));
  }

  ACE_END_TEST;

  return 0;
}
开发者ID:BackupTheBerlios,项目名称:pyasynchio-svn,代码行数:48,代码来源:Bug_1576_Regression_Test.cpp

示例4: magazine

int
ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
  ACE_UNUSED_ARG (argc);
  ACE_UNUSED_ARG (argv);

  ACE_DLL dll;

  int retval = dll.open (ACE_DLL_PREFIX ACE_TEXT("DLL_Today"));

  if (retval != 0)
    ACE_ERROR_RETURN ((LM_ERROR,
                       "%p",
                       "dll.open"),
                      -1);
  Magazine_Creator mc;

  // Cast the void* to non-pointer type first - it's not legal to
  // cast a pointer-to-object directly to a pointer-to-function.
  void *void_ptr = dll.symbol (ACE_TEXT ("create_magazine"));
  ptrdiff_t tmp = reinterpret_cast<ptrdiff_t> (void_ptr);
  mc = reinterpret_cast<Magazine_Creator> (tmp);

  if (mc == 0)
    {
      ACE_ERROR_RETURN ((LM_ERROR,
                         "%p",
                         "dll.symbol"),
                        -1);
    }

  {
    auto_ptr <Magazine> magazine (mc ());

    magazine->title ();
  }

  dll.close ();

  // The other library is now loaded on demand.

  retval = dll.open (ACE_DLL_PREFIX ACE_TEXT ("DLL_Newsweek"));

  if (retval != 0)
    {
      ACE_ERROR_RETURN ((LM_ERROR,
                         "%p",
                         "dll.open"),
                        -1);
    }

  // Cast the void* to non-pointer type first - it's not legal to
  // cast a pointer-to-object directly to a pointer-to-function.
  void_ptr = dll.symbol (ACE_TEXT ("create_magazine"));
  tmp = reinterpret_cast<ptrdiff_t> (void_ptr);
  mc = reinterpret_cast<Magazine_Creator> (tmp);

  if (mc == 0)
    {
      ACE_ERROR_RETURN ((LM_ERROR,
                         "%p",
                         "dll.symbol"),
                        -1);
    }

  {
    auto_ptr <Magazine> magazine (mc ());

    magazine->title ();
  }

  dll.close ();

  return 0;
}
开发者ID:azraelly,项目名称:knetwork,代码行数:75,代码来源:test_dll.cpp

示例5: LoadPlugins

void LoadPlugins(std::list<ACE_DLL>& pluginDlls)
{
	CStdString pluginsDirectory = CONFIG.m_pluginsDirectory;
#ifdef WIN32
	if(pluginsDirectory.size() == 0)
	{
		// default windows plugins directory
		pluginsDirectory = "./plugins/";
	}
	CStdString pluginExtension = ".dll";
#else
	if(pluginsDirectory.size() == 0)
	{
		// default unix plugins directory
		pluginsDirectory = "/usr/lib/orkaudio/plugins/";
	}
	CStdString pluginExtension = ".so";
#endif
	CStdString pluginPath;
	ACE_DLL dll;

	ACE_DIR* dir = ACE_OS::opendir((PCSTR)pluginsDirectory);
	if (!dir)
	{
		LOG4CXX_ERROR(LOG.rootLog, CStdString("Plugins directory could not be found:" + pluginsDirectory + " check your config.xml"));
	}
	else
	{
		dirent* dirEntry = NULL;
		while((dirEntry = ACE_OS::readdir(dir)))
		{	
			CStdString dirEntryFilename = dirEntry->d_name;
			int extensionPos = dirEntryFilename.Find(pluginExtension);

			if ( extensionPos != -1 && (dirEntryFilename.size() - extensionPos) == pluginExtension.size() )
			{
				pluginPath = pluginsDirectory + "/" + dirEntry->d_name;
				dll.open((PCSTR)pluginPath);
				ACE_TCHAR* error = dll.error();
				if(error)
				{
					LOG4CXX_ERROR(LOG.rootLog, CStdString("Failed to load plugin: ") + pluginPath);
#ifndef WIN32
					CStdString logMsg;
					logMsg.Format("DLL Error: %s", dlerror());
					LOG4CXX_ERROR(LOG.rootLog, logMsg);
#endif
				}
				else
				{
					LOG4CXX_INFO(LOG.rootLog, CStdString("Loaded plugin: ") + pluginPath);

					InitializeFunction initfunction;
					initfunction = (InitializeFunction)dll.symbol("OrkInitialize");

					if (initfunction)
					{
						initfunction();
						pluginDlls.push_back(dll);
					}
					else
					{
						LOG4CXX_ERROR(LOG.rootLog, CStdString("Failed to initialize plugin: ") + pluginPath);
					}
				}
			}
		}
		ACE_OS::closedir(dir);
	}
}
开发者ID:HiPiH,项目名称:Oreka,代码行数:70,代码来源:OrkAudio.cpp

示例6: singleton_test

// Check that the ACE_Based_Pointer_Repository can be accessed
// from a Windows DLL
// (see http://bugzilla.dre.vanderbilt.edu/show_bug.cgi?id=1991)
int singleton_test (void)
{
    void* baddr1 = ACE_BASED_POINTER_REPOSITORY::instance();
    void* baddr2 = ACE_BASED_POINTER_REPOSITORY::instance();

    if (baddr1 != baddr2)
    {
      ACE_ERROR_RETURN ((LM_ERROR,
                         ACE_TEXT ("ACE_Based_Pointer_Repository is not a singleton\n")),
                        -1);
    }

// Protection against this test being run on platforms not supporting Dlls.
#if defined(ACE_HAS_DYNAMIC_LINKING)

    ACE_TString dll_file;
    const char *subdir_env = ACE_OS::getenv ("ACE_EXE_SUB_DIR");
    if (subdir_env)
      {
        dll_file = ACE_TEXT_CHAR_TO_TCHAR (subdir_env);
        dll_file += ACE_DIRECTORY_SEPARATOR_STR;
      }

    dll_file += OBJ_PREFIX ACE_TEXT ("Based_Pointer_Test_Lib") OBJ_SUFFIX;

    // If DLL causes multiple instances of singleton
    // then the ACE_Cleanup object registered
    // with the ACE_Object_manager will no longer be valid,
    // at exit time if the library is unloaded. Override
    // the default close on destruct.
    ACE_DLL dll;
    int retval = dll.open (dll_file.c_str (),
                           ACE_DEFAULT_SHLIB_MODE,
                           0);

    if (retval != 0)
       {
       ACE_TCHAR *dll_error = dll.error ();
       ACE_ERROR_RETURN ((LM_ERROR,
                           ACE_TEXT ("Error in DLL Open: %s\n"),
                           dll_error ? dll_error : ACE_TEXT ("unknown error")),
                           -1);
       }

#if defined (ACE_OPENVMS)
    // with OPENVMS symbol names > 31 cause us trouble with dlsym()
    void* foo = dll.symbol (ACE_TEXT ("get_based_pointer_repo_inst"));
#else
    void* foo = dll.symbol (ACE_TEXT ("get_based_pointer_repository_instance"));
#endif

    // Cast the void* to function* with a long as intermediate.
    ptrdiff_t tmp = reinterpret_cast<ptrdiff_t> (foo);
    Get_Bp_Repository_Inst get_bp_repository_inst =
       reinterpret_cast<Get_Bp_Repository_Inst> (tmp);
    if (get_bp_repository_inst == 0)
       ACE_ERROR_RETURN ((LM_ERROR,
                          ACE_TEXT ("%p\n"),
                          dll.error ()),
                         -1);

    void* baddr_dll = get_bp_repository_inst ();

    dll.close ();

    if (baddr_dll != baddr1)
      {
        ACE_ERROR_RETURN ((LM_ERROR,
                           ACE_TEXT ("ACE_Based_Pointer_Repository is not a ")
                           ACE_TEXT ("singleton in DLL <%@> <%@>\n"),
                           baddr_dll,
                           baddr1),
                          -1);
      }
#endif /* ACE_HAS_DYNAMIC_LINKING */

    return 0;
}
开发者ID:DOCGroup,项目名称:ACE_TAO,代码行数:81,代码来源:Based_Pointer_Test.cpp


注:本文中的ACE_DLL::open方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。