. Net platform interoperability technology: 03. technical verification

Source: Internet
Author: User

The above two Articles respectively introduce the problems faced by the. Net platform interoperability technology, and focus on the technical implementation of calling the Native C ++ class library through P/Invoke. Simply put, it is a false handle. In this article, I will design an experiment to prove the feasibility of P/Invoke calling technology.

1Tutorial Scheme

Through the above analysis, the method of calling the Native C ++ class library will adopt the platform calling Technology (P \ Invoke). The overall solution can be expressed as follows:

= CallingConvention. stdCall, CharSet = QAFun (STR_PARAM, LONG_PARAM, DB_PARAM, IntPtr VAR_PARAM, = CallingConvention. stdCall, CharSet = GetVarProtocol (Str_Param = Long_Param = DB_Param = (I =; I <memoryParser. rows; I ++ str = memoryParser. getElementString (I, db = memoryParser. getElementDouble (I, integer = memoryParser. getElementInt (I, ++ _ declspec (dllexport) _ stdcall QAFun (* STR_PARAM, LONG_PARAM, DB_PARAM, * VAR_PARAM, ** <(I =; I <; I ++ str = iVar. getElemString (I, db = iVar. getElemDouble (I, integer = iVar. getElemInt (I, <str <db <integer <, (I =; I <; I ++ <STR_PARAM <DB_PARAM <LONG_PARAM <* OUT_VAR_PARAM = <_ declspec (dllexport) _ stdcall GetVarProtocol (**, (I =; I <; I ++, I, <* OUT_VAR_PARAM = <

3 Experiment results and analysis

3.1Lab results

Through experiments, we can draw a conclusion: C # Calling C ++ Library is feasible, and memory data blocks can be completely transferred between the Native C ++ environment and the C # environment, and can be correctly parsed. The experiment results are as follows:

3.2Potential risks

C # Calls the Native C ++ class Library. You only need to verify that the C # language can manipulate the memory. Then, you can use the C # language to call the Native C ++ Library function. The experiment has proved that the memory can be operated by C # using the unsafe and fixed keywords, And the C # function can be called by using the Import C ++ Dll and C. However, when calling the Native C ++ library, there will be some new problems due to the complexity of the actual data structure.

4References

1. Huang Jizhou Cui xiaoyuan is proficient in. Net interoperability P \ Invoke, C ++ Interop and COM Interop

2. http://msdn.microsoft.com/zh-cn/library/aa686045.aspx

3. http://www.cnblogs.com/xumingming/archive/2008/10/10/1308248.html

4. http://www.cnblogs.com/Jianchidaodi/archive/2009/03/09/1407270.html

5. http://www.jb51.net/article/23074.htm

6. http://blogs.microsoft.co.il/blogs/sasha/archive/2008/02/16/net-to-c-bridge.aspx

7. http://msdn.microsoft.com/zh-cn/library/ms228628

Http://blog.csdn.net/zhangzxy161723/archive/2009/04/28/4132853.aspx

9. http://hi.baidu.com/linzi1128/blog/item/dda5371fa7fa40cea6866946.html

Http://blog.csdn.net/jadeflute/archive/2010/06/23/5689502.aspx

11. http://blog.csdn.net/null1/archive/2009/03/03/3953155.aspx

12. http://msdn.microsoft.com/en-us/library/eyzhw3s8 (VS.80). aspx

13. http://www.cnblogs.com/suyang/archive/2008/03/06/1093827.html

14. http://ondotnet.com/pub/a/dotnet/2003/03/03/mcppp2.html

Http://ondotnet.com/pub/a/dotnet/2003/01/13/intromcpp.html

16. http://ondotnet.com/pub/a/dotnet/2004/03/29/mcpp_part3.html

17. http://www.codeproject.com/KB/mcpp/cpptomancpp.aspx

18. http://blog.csdn.net/yingzai621/archive/2010/02/01/5278316.aspx

19. http://www.pinvoke.net/

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.