public interface ExampleDLL extends Library {
ExampleDLL INSTANCE = (ExampleDLL) Native.loadLibrary("crypt32.dll", ExampleDLL.class);
}
But i don't know how do declare this function as native function in my class and which typed the c++ datatypes from the arguments match in java? So it would be so great and helpful if someone could paste a little bit of code here. So that i can understand it and go on.HCERTSTORE WINAPI CertOpenStore( _In_ LPCSTR lpszStoreProvider, _In_ DWORD dwMsgAndCertEncodingType, _In_ HCRYPTPROV_LEGACY hCryptProv, _In_ DWORD dwFlags, _In_ const void *pvPara );
--
You received this message because you are subscribed to the Google Groups "Java Native Access" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jna-users+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
package com.sun.jna.platform.win32;
import com.sun.jna.Native;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.win32.W32APIOptions;
public interface Crypt32 extends StdCallLibrary {
Crypt32 INSTANCE = (Crypt32) Native.loadLibrary("Crypt32", Crypt32.class, W32APIOptions.UNICODE_OPTIONS);
public HCERTSTORE CertOpenStore(LPCSTR lpszStoreProvider, int dwMsgAndCertEncodingType, HCRYPTPROV_LEGACY hCryptProv, int dwFlags, const void *pvPara);
}
And how did i initialize and declare these Strings? For example the lpszStoreProvider? in C++ Documentation i could use CERT_STORE_PROV_SYSTEM. How do i match this in java? thanks.
--
You received this message because you are subscribed to the Google Groups "Java Native Access" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jna-users+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Codpublic class Example {
public interface Crypt32 extends Library {
public boolean CertOpenStore(String lpszStoreProvider, int dwMsgAndCertEncodingType, Pointer hCryptProv, int dwFlags, Pointer pvPara);
/*
HCERTSTORE WINAPI CertOpenStore(
_In_ LPCSTR lpszStoreProvider,
_In_ DWORD dwMsgAndCertEncodingType,
_In_ HCRYPTPROV_LEGACY hCryptProv,
_In_ DWORD dwFlags,
_In_ const void *pvPara
);
*/
}
public static void main(String[] args) {
Crypt32 lib = (Crypt32) Native.loadLibrary("Crypt32", Crypt32.class);
System.out.println(lib.CertOpenStore(10, 0, null, 0, null));
}
}LPCSTR lpszStoreProvider is a Pointer to a String, so here it should be a String or not? An what are the exact values i have to set when i want to access the keystore MY on the local machine? and don't know what the return type is. it's very hard and complex for me :((
--
You received this message because you are subscribed to the Google Groups "Java Native Access" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jna-users+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
public class Example {
public interface Crypt32 extends StdCallLibrary {
//public boolean CertEnumSystemStore(int dwFlags, Pointer pvSystemStoreLocationPara, Pointer pvArg, Pointer pfnEnum);
public HANDLE CertOpenStore(int lpszStoreProvider, int dwMsgAndCertEncodingType, int hCryptProv, int dwFlags, String pvPara);
// HANLDE
/*
HCERTSTORE WINAPI CertOpenStore(
_In_ LPCSTR lpszStoreProvider,
_In_ DWORD dwMsgAndCertEncodingType,
_In_ HCRYPTPROV_LEGACY hCryptProv,
_In_ DWORD dwFlags,
_In_ const void *pvPara
);
*/
public HANDLE CertEnumCertificatesInStore(HANDLE hCertStore, int pPrevCertContext);
// int certstore
/*
PCCERT_CONTEXT WINAPI CertEnumCertificatesInStore(
_In_ HCERTSTORE hCertStore,
_In_ PCCERT_CONTEXT pPrevCertContext
*/
// pcert = CAPI.CertEnumCertificatesInStore(store,pcert);
/*
public native String CertGetNameStringW(
int pCertContext,
int dwType,
int dwFlags,
int TypePara) throws CryptoAPIException;
*/
public String CertGetNameStringW(HANDLE pCertContext, int dwType, int dwFlags, int TypePara);
/* int pCertContext
DWORD WINAPI CertGetNameString(
_In_ PCCERT_CONTEXT pCertContext,
_In_ DWORD dwType,
_In_ DWORD dwFlags,
_In_ void *pvTypePara,
_Out_ LPTSTR pszNameString,
_In_ DWORD cchNameString
);
*/
}
public static void main(String[] args) throws UnsupportedEncodingException, CryptoAPIException {
Crypt32 lib2 = (Crypt32) Native.loadLibrary("Crypt32", Crypt32.class);
HANDLE x = lib2.CertOpenStore(9, 0, 0, 65536, "My");
if(x != null) {
System.out.println("yes " + x);
}
HANDLE pcert = null;
String pszNameString = null;
pcert = lib2.CertEnumCertificatesInStore(x, 0);
System.out.println(pcert);
String certname = lib2.CertGetNameStringW(pcert, 4, 0, 0);
--
You received this message because you are subscribed to the Google Groups "Java Native Access" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jna-users+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
public String CertGetNameStringW(HANDLE pCertContext, int dwType, int dwFlags, Pointer TypePara, String pszNameString, int cchNameString);CertGetNameStringW(pcert, 4, 0, null, pszNameString, 128);/* int pCertContext
DWORD WINAPI CertGetNameString(
_In_ PCCERT_CONTEXT pCertContext,
_In_ DWORD dwType,
_In_ DWORD dwFlags,
_In_ void *pvTypePara,
_Out_ LPTSTR pszNameString,
_In_ DWORD cchNameString
);
*/
pszNameString is the return value so you can't pass a String.public String CertGetNameStringW(HANDLE pCertContext, int dwType, int dwFlags, Pointer TypePara, char[] pszNameString, int cchNameString);
CertGetNameStringW(..., myNameString, myNameString.length);--
You received this message because you are subscribed to the Google Groups "Java Native Access" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jna-users+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
by my own in java for the CertEnumCertificatesInStore() or is it enough to take the argument there (public HANDLE CertEnumCertificatesInStore(HANDLE hCertStore, HANDLE pPrevCertContext);) ?typedef struct _CERT_CONTEXT {
DWORD dwCertEncodingType;
BYTE *pbCertEncoded;
DWORD cbCertEncoded;
PCERT_INFO pCertInfo;
HCERTSTORE hCertStore;
} CERT_CONTEXT, *PCERT_CONTEXT;typedef const CERT_CONTEXT *PCCERT_CONTEXT;
CertGetNameStringW(pcert, 5, 0, null, myNameString, myNameString.length);
public String CertGetNameStringW(HANDLE pCertContext, int dwType, int dwFlags, Pointer TypePara, char[] pszNameString, int cchNameString); --> invalid Memory Access Error
public String CertGetNameStringW(HANDLE pCertContext, int dwType, int dwFlags, int TypePara); -> No Error and no output
--
You received this message because you are subscribed to the Google Groups "Java Native Access" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jna-users+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.