trouble using LoadLibrary(filename) in C++ Builder 10.2 [duplicate] - c++builder

This question already has answers here:
cannot convert 'const char*' to 'LPCWSTR {aka const wchar_t*}'
(4 answers)
Cannot convert const char[16] to LPCWSTR [closed]
(1 answer)
cannot convert parameter 1 from 'const char *' to 'LPCWSTR'
(6 answers)
Closed 3 months ago.
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.

Related

Fade2D library & C++ Builder

I wish to use Fade2D library in my C++Builder projects.
Libraries are in MS Visual Studio's and using them raised an exception:
[ilink32 Error] Error contains invalid OMF record, type 0x21 (possibly COFF)
I tried the two tools from Embarcadero to build the .lib file for C++ Builder:
COFF2OMF to convert the .lib from VS format and
IMPLIB to produces the .lib file starting form DLL
In both cases I have the error:
[ilink32 Error] Error: Unresolved external 'GEOM_FADE2D::setLic(const char *, const char *, const char *, const char *, const char *)' referenced from MAIN.OBJ
Any suggestions? Thanks in advance.

error: storage class may not be specified here when using __align() in MDK ARM uVision v5 ARM Compiler 5

I am migrating a project from CubeIDE (GCC) to the most comprehensive software development solution for ArmĀ®-based microcontrollers uVision (ARM Compiler 5) and have a difficulty using __align keyword.
CubeIDE code which compiles fine in CubeIDE:
#include <stdalign.h>
typedef struct {
volatile alignas(uint32_t) uint16_t imageDark[320];
} test_results;
First issue is that uVision cannot locate <stdalign.h> which is part of standard library of the C programming language:
..\Src\device_tests.c(3): error: #5: cannot open source input file "stdalign.h": No such file or directory
So I removed <stdalign.h> and based on these KEIL documentation rewrote my code to
typedef struct {
volatile __align(__ALIGNOF__(uint32_t)) uint16_t imageDark[320];
} test_results;
Now I am receiving the following error:
..\Src\device_tests.c(46): error: #80: a storage class may not be specified here
volatile __align(__ALIGNOF__(uint32_t)) uint16_t imageDark[320];
..\Src\device_tests.c(46): error: #328: invalid storage class for a class member
volatile __align(__ALIGNOF__(uint32_t)) uint16_t imageDark[320];
Any help on how to make alignment work in uVision would be greatly appreciated.
I found out that the problem was that I was trying to align inside a struct. The above-mentioned syntax works for variables outside a struct. However to make it work inside struct I used the following syntax:
typedef struct {
volatile uint16_t imageDark[320] __attribute__((aligned (4)));
} test_results;

opencv installation error while mingw32-make on windows

opencv installation using mingw32-make command in windows 10 platform, then likely end up in getting the below error.
Windows version : 10
OpenCv:3.2.0
Please suggest me in installing.
D:\installers\opencv\sources\modules\ts\src\ts_gtest.cpp: In constructor 'testing::internal::Mutex::Mutex()':
D:\installers\opencv\sources\modules\ts\src\ts_gtest.cpp:8829:45: error: cannot convert 'CRITICAL_SECTION* {aka _CRITICAL_SECTION*}' to '_RTL_CRITICAL_SECTION*' in initialization
critical_section_(new CRITICAL_SECTION) {
^
D:\installers\opencv\sources\modules\ts\src\ts_gtest.cpp:8830:48: error: cannot convert '_RTL_CRITICAL_SECTION*' to 'LPCRITICAL_SECTION {aka _CRITICAL_SECTION*}' for argument '1' to 'void InitializeCriticalSection(LPCRITICAL_SECTION)'
::InitializeCriticalSection(critical_section_);
^
D:\installers\opencv\sources\modules\ts\src\ts_gtest.cpp: In destructor 'testing::internal::Mutex::~Mutex()':
D:\installers\opencv\sources\modules\ts\src\ts_gtest.cpp:8840:46: error: cannot convert '_RTL_CRITICAL_SECTION*' to 'PCRITICAL_SECTION {aka _CRITICAL_SECTION*}' for argument '1' to 'void DeleteCriticalSection(PCRITICAL_SECTION)'
::DeleteCriticalSection(critical_section_);
^
D:\installers\opencv\sources\modules\ts\src\ts_gtest.cpp: In member function 'void testing::internal::Mutex::Lock()':
D:\installers\opencv\sources\modules\ts\src\ts_gtest.cpp:8848:43: error: cannot convert '_RTL_CRITICAL_SECTION*' to 'LPCRITICAL_SECTION {aka _CRITICAL_SECTION*}' for argument '1' to 'void EnterCriticalSection(LPCRITICAL_SECTION)'
::EnterCriticalSection(critical_section_);
^
D:\installers\opencv\sources\modules\ts\src\ts_gtest.cpp: In member function 'void testing::internal::Mutex::Unlock()':
D:\installers\opencv\sources\modules\ts\src\ts_gtest.cpp:8858:43: error: cannot convert '_RTL_CRITICAL_SECTION*' to 'LPCRITICAL_SECTION {aka _CRITICAL_SECTION*}' for argument '1' to 'void LeaveCriticalSection(LPCRITICAL_SECTION)'
::LeaveCriticalSection(critical_section_);
^
D:\installers\opencv\sources\modules\ts\src\ts_gtest.cpp: In member function 'void testing::internal::Mutex::ThreadSafeLazyInit()':
D:\installers\opencv\sources\modules\ts\src\ts_gtest.cpp:8879:27: error: cannot convert 'CRITICAL_SECTION* {aka _CRITICAL_SECTION*}' to '_RTL_CRITICAL_SECTION*' in assignment
critical_section_ = new CRITICAL_SECTION;
^
D:\installers\opencv\sources\modules\ts\src\ts_gtest.cpp:8880:54: error: cannot convert '_RTL_CRITICAL_SECTION*' to 'LPCRITICAL_SECTION {aka _CRITICAL_SECTION*}' for argument '1' to 'void InitializeCriticalSection(LPCRITICAL_SECTION)'
::InitializeCriticalSection(critical_section_);
^
modules\ts\CMakeFiles\opencv_ts.dir\build.make:237: recipe for target 'modules/ts/CMakeFiles/opencv_ts.dir/src/ts_gtest.cpp.obj' failed
mingw32-make[2]: *** [modules/ts/CMakeFiles/opencv_ts.dir/src/ts_gtest.cpp.obj] Error 1
CMakeFiles\Makefile2:5379: recipe for target 'modules/ts/CMakeFiles/opencv_ts.dir/all' failed
mingw32-make[1]: *** [modules/ts/CMakeFiles/opencv_ts.dir/all] Error 2
Makefile:159: recipe for target 'all' failed
mingw32-make: *** [all] Error 2
I also faced the same problem while trying to build OpenCV 3.2.0 using mingw32 on Windows10. I searched a bit to find a fix on Github for similar problem. It said the problem was:
MinGW defined _CRITICAL_SECTION and _RTL_CRITICAL_SECTION as two separate (equivalent) structs, instead of using typedef
So, you have to add another typedef GTEST_CRITICAL_SECTION for _CRITICAL_SECTION and _RTL_CRITICAL_SECTION and use this typedef for either case.
Here is what to do :
Edit "ts_gtest.h" which is inside "opencv\sources\modules\ts\include\opencv2\ts\"
Replace this line (probably line 723)
// assuming CRITICAL_SECTION is a typedef of _RTL_CRITICAL_SECTION.
// This assumption is verified by
// WindowsTypesTest.CRITICAL_SECTIONIs_RTL_CRITICAL_SECTION.
struct _RTL_CRITICAL_SECTION;
with
#if GTEST_OS_WINDOWS_MINGW
// MinGW defined _CRITICAL_SECTION and _RTL_CRITICAL_SECTION as two
// separate (equivalent) structs, instead of using typedef
typedef struct _CRITICAL_SECTION GTEST_CRITICAL_SECTION;
#else
// Assume CRITICAL_SECTION is a typedef of _RTL_CRITICAL_SECTION.
// This assumption is verified by
// WindowsTypesTest.CRITICAL_SECTIONIs_RTL_CRITICAL_SECTION
typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION;
#endif
Replace this line (probably on line 3060 before your edit - line number would have changed as you modified first part)
_RTL_CRITICAL_SECTION* critical_section_;
with
GTEST_CRITICAL_SECTION* critical_section_;
These two changes should fix your above error.
It was fixed by using TDM-gcc mingw compiler.

OmniThreadLibrary C++ builder Build issues

I'v been trying to get OmniThreadLibrary to run in builder, i've built it with all the c++ required files it builds ok but when i use it in an c++ builder app i get a bunch of error messages that look like the following
[bcc32 Error] DSiWin32.hpp(385): E2040 Declaration terminated incorrectly
one points at this line of code in the generated hpp file
static const System::Int8 CSIDL_ADMINTOOLS = System::Int8(0x30);
has anyone had this working in C++ builder or know the best way to resolve these issues
I'm using c++ builder settle and OmniThreadLibrary version 3.06
The Win32 API (and Delphi, for that matter) already declares CSIDL_ADMINTOOLS, Omni should not be declaring it at all. It should be using Delphi's Shlobj unit instead.
The Win32 API declares CSIDL_ADMINTOOLS using a #define statement:
#define CSIDL_ADMINTOOLS 0x0030
So the declaration in Omni's .hpp is getting modified by the C++ preprocessor to this:
static const System::Int8 0x0030 = System::Int8(0x30);
Thus the "Declaration terminated incorrectly" compiler error.
When Delphi code declares something that already exists in C++, it needs to be declared as either {$EXTERNALSYM} or {$NODECLARE} to avoid duplicate declarations, and then optionally use {$HPPEMIT} to output a relevant #include statement in a generated .hpp file. Delphi's units already do that for its Win32 declarations.
If Omni is not already doing that (and the error would suggest it is not) then it needs to be updated accordingly.

JEDI JCL runtime compiler error E2040 when using JclWin32.hpp

I have installed the current stable JEDI Code library in C++ Builder XE3 on Windows 7 x32. It works fine, but only as long as I don't include files like JclFileUtils.hpp which are including JclWin32.hpp. Then I get always the compiler error E2040: "Declaration terminated incorrectly" (in file JclWin32.hpp, line 682, second line in the following code snippet):
#define NetApi32 L"netapi32.dll"
static const System::Int8 CSIDL_PROGRAM_FILESX86 = System::Int8(0x2a);
#define RT_MANIFEST (System::WideChar *)(0x18)
I neither have an idea were this error comes from, nor could I found any hints to this. What could be the cause? Thanks in advance.
I got help and the solution for this problem. Just replace the static const declaration:
static const System::Int8 CSIDL_PROGRAM_FILESX86 = System::Int8(0x2a);
with this macro definition:
#define CSIDL_PROGRAM_FILESX86 0x2a
This is a bug in JclWin32.pas.
In C/C++, the Win32 API declares CSIDL values in Microsoft's shlobj.h header using preprocessor #define statements, eg:
#define CSIDL_PROGRAM_FILESX86 0x002a
After the preprocessor is run and performs #define symbol replacements, the compiler ends up seeing the following invalid declaration in JclWin32.hpp:
static const System::Int8 0x002a = System::Int8(0x2a);
JCL should not be re-declaring CSIDL_PROGRAM_FILESX86 (or any other CSIDL value) at all. It should be either:
using Delphi's own Winapi.ShlObj unit, which already declares CSIDL values.
if not using the Winapi.ShlObj unit, then it should at least be declaring its manual CSIDL values as {$EXTERNALSYM} so they do not appear in the generated JclWin32.hpp file. If needed, JCL can include an {$HPPEMIT '#include <shlobj.h>'} statement to pull in the existing Win32 API declarations for C/C++ projects to use.

Resources