Problems in JNA Development

Source: Internet
Author: User

[Qboy original] a third-party C dll needs to be called during project development in December 28, 2013. Since JNA was used in the project for the first time, many of them install development documents, but there are many problems. Since many interfaces have not been completed, I still don't know how many problems will occur. First, record the detected items. 1. One of the interfaces of the long type is defined as void * CreatePoint (const char * pip, const long port, const char * name, I quickly wrote out Pointer CreatePoint (String pip, long port, String name). The test reports an error. The error is Invaild memory access, after reading this for a long time, I didn't find my own mistake, even though I knew that the memory address was invalid. I also tried many methods, such as changing String to Pointer and byte [], but an error will still be reported. Finally, I can't find the cause of the problem. I wrote a dll using C according to the interface. The interface is the same, but the method is implemented as follows: void * CreatePoint (const char * pip, const long port, const char * name) {cout <pip <endl; cout <port <endl; cout <name <endl;} finally finds that both of the first two can be properly output, and the third one is to survive or die, which makes me even more depressed. Why? Again, const char * Why Are there different treatments? Besides, after the address is output, it is also 0? Later, I tried to remove the long type parameter from the company's notice, and found that it was the long type. But what is it? Later, I asked Lu to see if the length definitions of the long type are inconsistent between the two development languages. I changed the long type in java to an int and found that the long type is also output in name. In C, sizeof (long) is found to be 4 bytes, while Long. Size = 64 (8 bytes) int is 32 bits (4 bytes). Everything is clear. Ii. Self-righteous definition many Pointer sub-classes can be customized well because there is a typedef in C language. In this project, many void * types are converted to other well-remembered data types, because the other party does not provide the structure of such data types. My first thought is that these types are not easy to remember. Do I also define some child classes of the Pointer type. When the interface returns a void * type, an exception is thrown, and the Pointer type cannot be converted into a subclass defined by myself. I understand that I am too self-righteous. 3. Memory in the interface is also used to allocate space due to the first problem. Remember this. 4. At the beginning of int * processing, I got a glimpse of it. There is no pointer in JAVA. How can I pass this, however, such parameters in C/C ++ seem to be normal. Later, many classes, such as IntByRefrence, were found in the com. sum. jnj. ptr package. I think int * should be used to pass the value. There are many other types in this package.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.