Skip to content

Instantly share code, notes, and snippets.

@nikoncode
Last active August 29, 2015 13:57
Show Gist options
  • Select an option

  • Save nikoncode/9375444 to your computer and use it in GitHub Desktop.

Select an option

Save nikoncode/9375444 to your computer and use it in GitHub Desktop.
find
AnsiString search_path = ExtractFileDir(Application->ExeName)+"\\dlls\\"; //файлы будут искаться в папке dlls рядом с программой
...
ListBox1->Items->Clear(); //очищаем лист бокс
WIN32_FIND_DATA w32; //Создаем структура для хранения результатов поиска
HANDLE file = FindFirstFile((search_path+"*.dll").c_str(), &w32); //ищем первый файл с расширением dll, результат пишем в созданную структуру
bool is_finded = true; // помечаем что файл найден
while (is_finded) { //пока файл найден
if(!(w32.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) { //если это не папка, а файл
ListBox1->Items->Add(w32.cFileName); //добавляем имя в список
}
is_finded = FindNextFile(file, &w32); //ищем следующий
}
if (ListBox1->ItemIndex == -1) {
MessageBox(NULL, "Нужно выбрать dll.", "ERROR", MB_ICONSTOP);
return;
}
typedef char * (__cdecl *INFO_PROC)(void);
typedef int (__cdecl *DO_CALC_PROC)(char *);
HINSTANCE dll = LoadLibrary((search_path+ListBox1->Items->Strings[ListBox1->ItemIndex]).c_str());
if (dll != NULL) {
INFO_PROC info_proc_addr = (INFO_PROC) GetProcAddress(dll, "_info");
if (info_proc_addr != NULL) {
char * info = (info_proc_addr)();
DO_CALC_PROC do_calc_proc_addr = (DO_CALC_PROC) GetProcAddress(dll, "_do_calc");
if (do_calc_proc_addr != NULL)
Edit2->Text = Edit1->Text + " " + info + " будет " + IntToStr(do_calc_proc_addr(Edit1->Text.c_str()));
} else {
MessageBox(NULL, "Выбранная dll не соответствует формату.", "ERROR", MB_ICONSTOP);
}
FreeLibrary(dll);
} else {
MessageBox(NULL, "Ошибка при подключении dll.", "ERROR", MB_ICONSTOP);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment