jsoncpp icon indicating copy to clipboard operation
jsoncpp copied to clipboard

Passing Json::Value to a function in C++ dll is throwing read access violation exception

Open Suresh3d opened this issue 3 years ago • 0 comments

Hi , I am using JsonCPP library in my C++ project . I created a C++ dll with a function which will take Json::Value as input parameter . I have created another one exe which calls this function by passing Json::Value as argument. Inside the dll function, while reading this json value , it throws read access violation exception .

I was passing string as well which used to give error . I changed string to char* which resolves my problem . But I don't know how to handle passing json value .

below is the example code snippet .

C++ dll :

foo(json::value jsonValue)
{
auto value = jsonValue["name"];
}

another exe:

I linked dll with this exe project . And while debuging I can go inside foo function . so there is no problem in loading dll and calling function .

I am reading json from my local json file and storing it in jsonValue.

json::value jsonValue = readFromLocalFile();

cout<<jsonValue["name"];    // works well

foo(jsonValue);             // goes inside foo function and breaks wile reading jsonValue["name"]

I am using visual studio 2019 to build both the projects .

image

Can anyone please help me with this error .

Suresh3d avatar May 18 '22 09:05 Suresh3d