本文整理汇总了C++中ACE_DLL::symbol方法的典型用法代码示例。如果您正苦于以下问题:C++ ACE_DLL::symbol方法的具体用法?C++ ACE_DLL::symbol怎么用?C++ ACE_DLL::symbol使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ACE_DLL
的用法示例。
在下文中一共展示了ACE_DLL::symbol方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: dynamic_cast_test
int dynamic_cast_test (ACE_DLL &dll)
{
Child child;
child.test();
Parent *parent = &child;
void * foo = dll.symbol (ACE_TEXT ("dynamic_cast_test"));
// Cast the void* to long first.
ptrdiff_t tmp = reinterpret_cast<ptrdiff_t> (foo);
PFN pfnAcquire = reinterpret_cast<PFN> (tmp);
if (pfnAcquire == 0)
ACE_ERROR_RETURN ((LM_ERROR,
ACE_TEXT ("%p\n"),
dll.error ()),
-1);
ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("before %@ %@\n"),
&child, dynamic_cast<Child*> (parent)));
if (pfnAcquire (&child) == -1)
ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("dynamic_cast failed.\n")), -1);
return 0;
}
示例2: 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;
}
示例3: 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;
}
示例4:
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;
}
示例5: 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;
}
示例6: 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);
}
}
示例7: 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;
}