Currently I'm trying to re-write the Old program written with C# to the same program but in Qt.
I'm fairly new to C++ (1 and a half month) and have no mentor to ask, so I'm hoping one of you could help answer my problem,
One of the function in the code links to an external dll file and use 2 of the functions from there. And most of the time, it gives me reading access violation error. (sometimes it works)
The code looks like this.
main.cpp
void DecodeImage(QByteArray inputData)
{
int imageSize = inputData.Length();
unsigned char* ptr = DecompressImage((unsigned char*)inputData.data(), &imageSize);
QByteArray result = QByteArray((char*)ptr, imageSize);
FreeMemory(ptr);
}
decompressor.h
#if _WINDLL
#define EXPORT __declspec(dllexport)
#else
#define EXPORT
#endif
#if defined(__cplusplus)
extern "C"
{
#endif
EXPORT unsigned char* DecompressImage(unsigned char* input, int *length);
EXPORT void FreeMemory(unsigned char* pointer);
#if defined(__cplusplus)
}
#endif
And also I do not have access to the dll source code.
I thought that my inputs are wrong, so I compare all the inputs that goes into the dll with the C# version, turns out they are all the same.
The error code is this and the program throws at the DecompressImage function from the dll.
test.exe: 0xC0000005: Access violation reading location 0x0000000007CA4000.
It may also be my negligance since I'm quite new to C++ and Qt. But I'm trying to figure out the issue for the past week and still couldn't fix it. Anyway any kind of input is greatly appreciated.
EDIT : forgot the *at imageSize in result.
EDIT 2: deleted the PNG exporting line
EDIT 3: using a valid address instead of declaring a new pointer
User contributions licensed under CC BY-SA 3.0