Mercurial > hg > vamp-plugin-sdk
comparison src/vamp-hostsdk/PluginLoader.cpp @ 284:1ed95908a397
* Win32 build fixes for UNICODE. Not yet tested
author | cannam |
---|---|
date | Mon, 15 Jun 2009 14:30:05 +0000 |
parents | 4454843ff384 |
children | c97e70ed5abc |
comparison
equal
deleted
inserted
replaced
283:6c9f10b8a53a | 284:1ed95908a397 |
---|---|
511 void * | 511 void * |
512 PluginLoader::Impl::loadLibrary(string path) | 512 PluginLoader::Impl::loadLibrary(string path) |
513 { | 513 { |
514 void *handle = 0; | 514 void *handle = 0; |
515 #ifdef _WIN32 | 515 #ifdef _WIN32 |
516 #ifdef UNICODE | |
517 int len = path.length(); // cannot be more wchars than length in bytes of utf8 string | |
518 wchar_t *buffer = new wchar_t[len]; | |
519 int rv = MultiByteToWideChar(CP_UTF8, 0, path.c_str(), len, buffer, len); | |
520 if (rv <= 0) { | |
521 cerr << "Vamp::HostExt::PluginLoader: Unable to convert library path \"" | |
522 << path << "\" to wide characters " << endl; | |
523 delete[] buffer; | |
524 return handle; | |
525 } | |
526 handle = LoadLibrary(buffer); | |
527 delete[] buffer; | |
528 #else | |
516 handle = LoadLibrary(path.c_str()); | 529 handle = LoadLibrary(path.c_str()); |
530 #endif | |
517 if (!handle) { | 531 if (!handle) { |
518 cerr << "Vamp::HostExt::PluginLoader: Unable to load library \"" | 532 cerr << "Vamp::HostExt::PluginLoader: Unable to load library \"" |
519 << path << "\"" << endl; | 533 << path << "\"" << endl; |
520 } | 534 } |
521 #else | 535 #else |
562 PluginLoader::Impl::listFiles(string dir, string extension) | 576 PluginLoader::Impl::listFiles(string dir, string extension) |
563 { | 577 { |
564 vector<string> files; | 578 vector<string> files; |
565 | 579 |
566 #ifdef _WIN32 | 580 #ifdef _WIN32 |
567 | |
568 string expression = dir + "\\*." + extension; | 581 string expression = dir + "\\*." + extension; |
582 #ifdef UNICODE | |
583 int len = expression.length(); // cannot be more wchars than length in bytes of utf8 string | |
584 wchar_t *buffer = new wchar_t[len]; | |
585 int rv = MultiByteToWideChar(CP_UTF8, 0, expression.c_str(), len, buffer, len); | |
586 if (rv <= 0) { | |
587 cerr << "Vamp::HostExt::PluginLoader: Unable to convert wildcard path \"" | |
588 << expression << "\" to wide characters" << endl; | |
589 delete[] buffer; | |
590 return files; | |
591 } | |
592 WIN32_FIND_DATA data; | |
593 HANDLE fh = FindFirstFile(buffer, &data); | |
594 if (fh == INVALID_HANDLE_VALUE) { | |
595 delete[] buffer; | |
596 return files; | |
597 } | |
598 | |
599 bool ok = true; | |
600 while (ok) { | |
601 wchar_t *fn = data.cFileName; | |
602 int wlen = wcslen(fn); | |
603 int maxlen = wlen * 6; | |
604 char *conv = new char[maxlen]; | |
605 int rv = WideCharToMultiByte(CP_UTF8, 0, fn, wlen, conv, maxlen, 0, 0); | |
606 if (rv > 0) { | |
607 files.push_back(conv); | |
608 } | |
609 delete[] conv; | |
610 ok = FindNextFile(fh, &data); | |
611 } | |
612 | |
613 FindClose(fh); | |
614 delete[] buffer; | |
615 #else | |
569 WIN32_FIND_DATA data; | 616 WIN32_FIND_DATA data; |
570 HANDLE fh = FindFirstFile(expression.c_str(), &data); | 617 HANDLE fh = FindFirstFile(expression.c_str(), &data); |
571 if (fh == INVALID_HANDLE_VALUE) return files; | 618 if (fh == INVALID_HANDLE_VALUE) return files; |
572 | 619 |
573 bool ok = true; | 620 bool ok = true; |
575 files.push_back(data.cFileName); | 622 files.push_back(data.cFileName); |
576 ok = FindNextFile(fh, &data); | 623 ok = FindNextFile(fh, &data); |
577 } | 624 } |
578 | 625 |
579 FindClose(fh); | 626 FindClose(fh); |
580 | 627 #endif |
581 #else | 628 #else |
582 | 629 |
583 size_t extlen = extension.length(); | 630 size_t extlen = extension.length(); |
584 DIR *d = opendir(dir.c_str()); | 631 DIR *d = opendir(dir.c_str()); |
585 if (!d) return files; | 632 if (!d) return files; |