/*
Copyright (C) 2017 Markus Mützel
This file is part of Octave.
Octave is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
Octave is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Octave; see the file COPYING. If not, see
.
*/
#if defined (HAVE_CONFIG_H)
# include "config.h"
#endif
#include
#include
#include
#include "defun-dld.h"
#include "error.h"
#include "oct-shlib.h"
#include "ovl.h"
DEFUN_DLD (check_lib_fcn3, args, ,
"-*- texinfo -*-\
@deftypefn {} {@var{info} =} check_lib_fcn2 (@var{fcnname})\
Return true if function @var{fcnname} exists in library @var{libname}.\
\
@end deftypefn */")
{
if (args.length () != 1)
print_usage ();
// std::string libname = args(0).xstring_value ("check_lib_fcn: LIBNAME must be a string");
std::string fcnname = args(0).xstring_value ("check_lib_fcn: FCNNAME must be a string");
HANDLE proc = GetCurrentProcess ();
if (! proc)
error ("Unable to get handle to own process.");
HMODULE h_libs[1024];
DWORD bytes_all_modules;
void * fcn;
// Get a list of all the modules in this process.
if(EnumProcessModules (proc, h_libs, sizeof (h_libs), &bytes_all_modules))
{
for (int i = 0; i < (bytes_all_modules / sizeof (HMODULE)); i++)
{
// Check for function in module.
fcn = reinterpret_cast (GetProcAddress (h_libs[i], fcnname.c_str ()));
if (fcn != nullptr)
break;
}
}
// Release the handle to the process.
CloseHandle (proc);
bool result = fcn != nullptr;
return ovl (result);
}