Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 667063
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T23:53:14+00:00 2026-05-13T23:53:14+00:00

I’ve successfully compiled my library on Linux and Mac and used it with Java

  • 0

I’ve successfully compiled my library on Linux and Mac and used it with Java Native Access. Unfortunately nothing I do seems to work with Visual Studio’s compiler and Java Native Access.

I’m going back to the basics and trying to create a super simple dll in Visual Studio that Java Native Access will work with, any help would be appreciated.

Here’s GimmeFiveDll.c:

__declspec(dllexport) int gimmeFive()
{
    return 5;
}

Here’s SystemLibrary.java:

import com.sun.jna.Native;


public class SystemLibrary {

public static final SystemLibrary instance = new SystemLibrary();

    static {
        Native.register("GimmeFiveDll");
    }

    public native int gimmeFive();
}

I have already tried switching the call interface to stdcall in Visual Studio. I did not make any other changes from the new project wizard’s empty project dll win32 console defaults.
In the example above the resulting dll doesn’t even export the function correctly according to dumpbin.exe /exports. My real project does export them correctly but either way I always get the same JNA exception:

Exception in thread "main" java.lang.UnsatisfiedLinkError: Unable to load library 'GimmeFiveDll': The specified module could not be found.

(Yes, I put the GimmeFiveDll.dll in System32. Yes I am able to use JNA to access other dlls in System32 that come with Windows).

Anyone willing to help me round out this minimalist example of a dll created by Visual Studio that JNA likes?

Many many thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T23:53:15+00:00Added an answer on May 13, 2026 at 11:53 pm

    After two days of banging my head against a wall I figured it out. The problem was that C:\Windows\System32 is NOT a directory System.loadLibrary() (which Native.register() uses) can load a dll from on a 64 bit machine! So instead JNA was apparently attempting to copy the library to a temporary location and load it, but that failed. The “specified module could not be found” message wasn’t terribly helpful and set me down the wrong track :-\

    Anyway to answer my own question here is an example of a dll that can be built with MSVC that Java (and JNA) can use (just put it in the right directory for your system!):

    GimmeFiveDll.c:

    #ifdef __cplusplus
    #error no C++, to keep this example simple
    #endif
    
    __declspec(dllexport) int gimmeFive()
    {
        return 5;
    }
    

    DllTest.java:

    import com.sun.jna.Native;
    
    public class DllTest {
    
        static {
            Native.register("GimmeFiveDll");
        }
    
        public static native int gimmeFive();
    
        public static void main(String[] args) {
            System.out.println("I got: " + DllTest.gimmeFive());
        }
    }
    

    If all goes well Java will print “I got: 5”.

    Note that I did not find it necessary to change the compiler settings to use stdcall or to declare __stdcall in the function signature. In fact no compiler changes were needed from the normal empty dll project the wizard creates.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have thousands of HTML files to process using Groovy/Java and I need to
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.