Commit 9f6e033a authored by jan.koester's avatar jan.koester
Browse files

fixed

parent dba4f554
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -7,6 +7,8 @@ project(dbpp)
set(LIBV "1.0.0")
set(Upstream_VERSION 1.0.0)

set(CMAKE_CXX_STANDARD 20)

configure_file(config.h.in ${CMAKE_BINARY_DIR}/config.h)

set(WINDOWS_EXPORT_ALL_SYMBOLS ON)
+3 −2
Original line number Diff line number Diff line
@@ -4,15 +4,16 @@ else()
    set(DESTDIR lib/dbpp)
endif()

find_package(PostgreSQL)
if(${PostgreSQL_FOUND})
    if(NOT TARGET PostgreSQL::pq)
        add_library(PostgreSQL::pq STATIC IMPORTED)

        set_target_properties(PostgreSQL::pq PROPERTIES
            [cite_start]INTERFACE_INCLUDE_DIRECTORIES "${PostgreSQL_INCLUDE_DIRS}" [cite: 2]
            INTERFACE_INCLUDE_DIRECTORIES "${PostgreSQL_INCLUDE_DIRS}"
        )
        set_target_properties(PostgreSQL::pq PROPERTIES
            [cite_start]IMPORTED_LOCATION "${PostgreSQL_LIBRARIES}" [cite: 3]
            IMPORTED_LOCATION "${PostgreSQL_LIBRARIES}" 
        )
    endif()
    
+6 −14
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@
#include <cstdio>
#include <string>
#include <database.h>
#include <filesystem>

#ifdef Windows
#include <windows.h>
@@ -40,22 +41,13 @@

dbpp::Database::Database(const std::string &dbdriver,const std::string &connstr){
#ifdef Windows
    wchar_t bufExePath[MAX_PATH + 1] = { 0 };
    DWORD dwNumCharacters = ::GetCurrentDirectoryW(MAX_PATH, bufExePath);
    std::filesystem::path currentPath = std::filesystem::current_path();
    std::string filename = dbdriver + ".dll";
    std::filesystem::path fullPath = currentPath / filename;

    int size_dbdriver_w = MultiByteToWideChar(CP_UTF8, 0, dbdriver.c_str(), -1, nullptr, 0);
    std::wstring dbdriver_w(size_dbdriver_w, L'\0');
	std::cerr << "Loading DLL from path: " << fullPath << std::endl;

    MultiByteToWideChar(CP_UTF8, 0, dbdriver.c_str(), -1, &dbdriver_w[0], size_dbdriver_w);

    std::wstring fullPath = std::wstring(bufExePath) + L"\\" + dbdriver_w + L".dll";

    // Convert to a char* if LoadLibraryA is needed (or use LoadLibraryW)
    std::cerr << "Attempting to load: " << std::string(fullPath.begin(), fullPath.end()) << std::endl;

    // Load the DLL
    // LoadLibrary returns an HMODULE handle, which is the Windows equivalent of the handle returned by dlopen.
    _handle = LoadLibraryW(fullPath.c_str()); // Use LoadLibraryA for char* strings
    _handle = LoadLibraryW(fullPath.wstring().c_str());

    if (_handle == nullptr) {
        DWORD lastError = GetLastError();