Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I've resorted to using chdir as @technomage (I can't seem to upvote his/her comment with my current account status) has also suggested. </p> <p>To do this, I used the following piece of code before I load up my C++ DLL through JNA.</p> <pre><code>NativeLibrary clib = NativeLibrary.getInstance(null); int result = clib.getFunction("_chdir").invokeInt(new Object[]{"&lt;PATH GOES HERE&gt;"}); </code></pre> <p>Source: <a href="https://www.java.net/node/643965#comment-821128" rel="nofollow">https://www.java.net/node/643965#comment-821128</a></p> <p>You can also check the result by checking the <code>result</code> variable. Should be zero if everything went well. </p> <p>I am not quite sure why <code>null</code> works for <code>NativeLibrary.getInstance</code>. The documentation doesn't say anything specifically about this and I haven't been able to glean anything from the source here: <a href="https://github.com/twall/jna/blob/master/src/com/sun/jna/NativeLibrary.java" rel="nofollow">https://github.com/twall/jna/blob/master/src/com/sun/jna/NativeLibrary.java</a> - But passing null does seem to get you the default libc or equivalent for your platform. </p> <p>Note also that I had to add an <code>_</code> (underscore) to the function name. This has to do with how function calls get mangled when compiled on Windows. As far as I know, this isn't required on other platforms, but I don't have the ability to test this right now. </p> <p>Since I was unsure about whether my call was actually working, I did the following first:</p> <pre><code>Function f = clib.getFunction("_chdir"); </code></pre> <p>This returns a function "pointer" <code>f</code> that you can trace/debug to see if you have a valid reference. Luckily, in my case, all I had to do was add the underscore as was suggested in the source link above. </p> <p>After this call to <code>chdir</code>, the C++ DLL I need to access has been happily accessing files relative to the location specified in <code>chdir</code>.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload