/** *DllFunctiontemplateclasshelpstocheckisalibraryfunctionavailableandcallit. *Usageexample: *// RegDeleteKeyExW function (from advapi32.dll) is available on Vista+ or on WinXP 64bit *// so to avoid dependency on the OS version we have to check if it's available at runtime * *// the function definition *typedefLONG(WINAPI*RegDeleteKeyExWFunc)(HKEYhKey,constwchar_t*lpSubKey,REGSAMsamDesired,DWORDReserved); * *DllFunction<RegDeleteKeyExWFunc>_RegDeleteKeyExW(Dll("advapi32",Dll::System()),"RegDeleteKeyExW"); *if(_RegDeleteKeyExW.available()){ *// the function is available, call it *LONGresult=_RegDeleteKeyExW(hKey,subkeyName,samDesired,0); *}else{ *// the function is not available, handle this *throwstd::exception("RegDeleteKeyExWfunctionisnotavailable"); *} * *// or we can just try to call the function. *// if the function is not available, exception with the corresponding description is thrown *DllFunction<RegDeleteKeyExWFunc>_RegDeleteKeyExW(Dll("advapi32",Dll::System()),"RegDeleteKeyExW"); *LONGresult=_RegDeleteKeyExW(hKey,subkeyName,samDesired,0);
*/ template<class funcType> class DllFunction { public:
DllFunction(const Dll& library, const tstrings::any &funcName)
: lib(library), theName(funcName.str()) {
lib.getFunction(funcName, funcPtr);
}
operator funcType() const {
if (!available()) {
JP_THROW(tstrings::any() << theName
<< "() function is not available in "
<< lib.path());
} return funcPtr;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.