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

  • SEARCH
  • Home
  • 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 7052421
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:22:54+00:00 2026-05-28T03:22:54+00:00

I’m looking to get a Java string to ‘ WlanHostedNetworkSetSecondaryKey ‘ and ‘ WlanHostedNetworkSetProperty

  • 0

I’m looking to get a Java string to ‘WlanHostedNetworkSetSecondaryKey‘ and ‘WlanHostedNetworkSetProperty‘. One wants a struct within a struct with a CHAR[] and the first one wants a PUCHAR. I tried using String, char[], byte[] and Memory, but they will keep producing me the same errors (Bad parameters or Bad profile something for the first). Any way maybe to debug more with JNA (probably not :()?
I also can’t read anywhere the characterencoding which is used, except that it’s not ANSI.. Any help would be great!

        * DWORD WINAPI WlanHostedNetworkSetSecondaryKey(
        __in        HANDLE hClientHandle,
        __in        DWORD dwKeyLength,
        __in        PUCHAR pucKeyData,
        __in        BOOL bIsPassPhrase,
        __in        BOOL bPersistent,
        __out_opt   PWLAN_HOSTED_NETWORK_REASON pFailReason,
        __reserved  PVOID pvReserved


     * DWORD WINAPI WlanHostedNetworkSetProperty(
        __in        HANDLE hClientHandle,
        __in        WLAN_HOSTED_NETWORK_OPCODE OpCode,
        __in        DWORD dwDataSize,
        __in        PVOID pvData,
        __out_opt   PWLAN_HOSTED_NETWORK_REASON pFailReason,
        __reserved  PVOID pvReserved
        );

For the most documentation on this

http://msdn.microsoft.com/en-us/library/dd439496(v=VS.85).aspx

http://jna.java.net/javadoc/overview-summary.html#pointers

http://en.wikipedia.org/wiki/Java_Native_Access

Following comment:

   String buffer = "test";
   ByteBuffer buf = ByteBuffer.allocateDirect(buffer.length()); buf.put(buffer.getBytes()); 
   Pointer pucKeyData = Native.getDirectBufferPointer(buf);

   System.out.println(
           CLibrary.INSTANCE.WlanHostedNetworkSetSecondaryKey(handle.getValue(), 5, pucKeyData, 0, 0, reason, reserved));
  • 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-28T03:22:54+00:00Added an answer on May 28, 2026 at 3:22 am

    I am rephrasing what I have commented so far (plus some corrections):

    UCHAR is defined as a C macro u_byte which is an unsigned byte. But, in Java, we don’t have an unsigned byte type, just a signed byte from the byte type. Don’t worry, to get an unsigned byte in Java, we use this trick: ((int)mybyte & 0xFF)

    PUCHAR is defined as a C macro POINTER(u_byte) which is a C pointer, unsigned byte * that points to an unsigned byte array. The reason is to have a dynamic array.

    But, if you use byte[] or char[] in JNA Structure, JNA will complain, Array fields must be initialized for uninitialized byte[] or char[] field. In your case, it defeats the purpose of having dwKeyLength field to define the size of dynamic unsigned byte array pucKeyData.

    The right JNA type for the pucKeyData is Pointer. But, you need to find a way to assign an array to this Pointer field for pucKeyData field based on the size given by dwKeyLength length in WlanHostedNetworkSetSecondaryKey structure.

    To assign an initialized unsigned byte array to a Pointer, we need to use direct ByteBuffer. Remember to release this direct buffer manually after use since it is no longer managed by Java GC…

    String buffer = "1234567890";
    DWORD dwKeyLength = new DWORD(buffer.length());
    ByteBuffer buf = ByteBuffer.allocateDirect(dwKeyLength.intValue()); 
    buf.put(buffer.getBytes()); 
    Pointer pucKeyData = Native.getDirectBufferPointer(buf);
    
    System.out.println("pucKeyData data:" + pucKeyData.getString(0));
    
    buf = null;
    pucKeyData = null;
    

    If you get bad parameters from JNA exception, it means one or more parameters of your JNA method are using incorrect data types.

    JNA provides a few WinDef class types like DWORD. But a few WinDef types like PUCHAR are not included. But, to assign an integer value to a DWORD type and retrieve it back, you need to do like this:

    DWORD dwKeyLength = new DWORD(5);
    System.out.println("dwKeyLength integer value: " + dwKeyLength.intValue());
    

    Note: this post is based on JNA platform version 3.3.0

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm making a simple page using Google Maps API 3. My first. One marker
I have a jquery bug and I've been looking for hours now, I can't
I would like to count the length of a string with PHP. The string
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace
Specifically, suppose I start with the string string =hello \'i am \' me And
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this

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.