C # calls C + + dynamic Library

Source: Internet
Author: User

1. If C # calls the VC's dynamic library, and the DLL uses MFC, the MFC must be statically linked to the DLL.

2. C # calls the C + + dynamic Library in three ways: COM components, managed code, unmanaged code.

COM components need client registration, if the customer does not have administrator rights can not be used;

Managed code can export classes in a DLL, but need to write managed code, add work, and the code looks a bit * *;

Unmanaged code cannot export classes in DLLs, only exported functions, but the advantage is that DLLs are more orthodox and can be used for c/c++/c#.

3, C # call the C + + dynamic library should pay attention to the parameter transfer problem, DLL interface string type preferably with char*.

4, the incoming parameter string corresponding interface char*, out parameters with StringBuilder, pay attention to the use of unsafe. If you use an export function in another class, use the Public keyword.

[DllImport (@"HIDUSBLib.dll", EntryPoint ="Receive")] Public extern unsafe Static BOOLReceive (stringDevname, [MarshalAs (UNMANAGEDTYPE.LPSTR)]stringbuilder buf ,                                                            intBuflen,int*Nrecvlen,intTimeout);

C # calls C + + dynamic libraries

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.