Edix
Edix

Reputation: 13

call Windows Color System from Java

I need to call Windows Color System functions from Java. Following this tutorial i tried to call DLL function using Java Native Access. All examples from this tutorial works fine. When i try to load and use Mscms.dll (one of the WCS libraries) that DLL seems to be loaded successfully, but i can not call any functions. List of functions is here.

I got a message:

Exception in thread "main" java.lang.UnsatisfiedLinkError: Error looking up function 'GetColorDirectory'

What's wrong with my code? Could you help me please?

import com.sun.jna.Library;
import com.sun.jna.Native;

public class WCS_test {

public interface Mscms extends Library {
    // http://msdn.microsoft.com/en-us/library/dd316928%28v=vs.85%29.aspx
    boolean GetColorDirectory(String pMachineName, String[] pBuffer, int pdwSize);
}

private static Mscms mscms = (Mscms) Native.loadLibrary("C:/Windows/system32/Mscms.dll", Mscms.class);

public static void main(String[] args) {

    if (mscms != null)
        System.out.println("Library loaded\n");
    else
        System.err.println("Library loading error\n");

    String[] pBuffer = new String[1024];
    mscms.GetColorDirectory(null, pBuffer, pBuffer.length);
}
}

Upvotes: 1

Views: 133

Answers (1)

Andrew
Andrew

Reputation: 93

When you get a java.lang.UnsatisfiedLinkError that means that it could not find the function 'GetColorDirectory' inside of the Mscms.dll. Looking at the link from your source code http://msdn.microsoft.com/en-us/library/dd316928%28v=vs.85%29.aspx you should try the Unicode name GetColorDirectoryW.

Upvotes: 1

Related Questions