trouble using LoadLibrary(filename) in C++ Builder 10.2

325 Views Asked by At

I'm trying to import an XE5 project over to C++Builder 10.2. I used the first example in the XE5 project and it ran fine. I've built this project from scratch starting with New VCL Project, then just added all my cpp files and forms to the project and am now trying to compile it.

The original code is this:

extern "C++" __declspec(dllimport) HID_SMBUS_STATUS HidSmbus_GetNumDevices();
//load the library dynamically
HINSTANCE load = LoadLibrary("SLABHIDDevice.dll");

I get a compile error that says:

libloaderapi.h(648): candidate function not viable: no known conversion from 'const char [18]' to 'LPCWSTR' (aka 'const wchar_t *') for 1st argument

That worked in XE5 on the same computer so I don't understand why I'm getting that error in 10.2.

I then tried this to comply with the error:

extern "C++" __declspec(dllimport) HID_SMBUS_STATUS HidSmbus_GetNumDevices();
LPCWSTR a;
*a = "SLABHIDDevice.dll"; 
HINSTANCE load = LoadLibrary(a); 

But there is something wrong with my syntax that I don't understand as I get this error now:

[bcc32c Error] worksurface.cpp(73): C++ requires a type specifier for all declarations

I thought I had declared 'a' in the line above it, so I don't understand that. In any case, I then tried to load the library statically instead of dynamically by doing this instead:

#pragma comment(lib, "SLABHIDDevice.dll")
extern "C++" __declspec(dllimport) HID_SMBUS_STATUS HidSmbus_GetNumDevices();

But then I get the following error:

[ilink32 Error] Error: Error processing module (path)\SLABHIDDEVICE.DLL

In all cases, SLABDIDDEVICE.DLL is in the project directory.

0

There are 0 best solutions below