open-source-parsers / open-source-parsers/jsoncpp

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

Open
#1,403 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug build
Dominant language
C++
Stars
8.9k
Forks
2.7k
Avg merge
31m
Merged PRs (30d)
1

Description

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 .

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the shown foo(Json::Value) call and the Json::Value access at jsonValue["name"] in the DLL, then compare how the DLL and executable are built in Visual Studio 2019. Reproduce the local-file read and cross-DLL call under the debugger; done means the DLL can read the passed name without a read access violation.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
desktop
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.