About parameter transfer of the dynamic library interface

Source: Internet
Author: User

In the past two daysProgramC To call the corresponding function in dynamic library.

 

Interface prototype in

Prototype: (the actual name is omitted in the example)

Bool openviewa (Cstring strpro1, cstring strpro2, cstring strpro3)

{

...

Return ture;

}

Because C has a similar interface openviewcc, copy it and change its name. Its original prototype is: Note parameter type

Bool openviewcc (Lpcstr strpro1,LpcstrStrpro2,LpcstrStrpro3)

{

...

Return ture;

}

The prototype of the called interface added in C is

 

Extern "C" _ declspec (dllexport) bool openviewa (Cstring strpro1, cstring strpro2, cstring strpro3)

{

// Define the function pointer of the same type in a to be called

Typedef bool (* func )();

 

// Obtain the corresponding function interface from the OBC dynamic library

Func proc = (func) getprocaddress (m_hadll, "openviewa ");

// If a function exists, call it directly.

If (null! = Proc)

{

 

Return proc (strpro1, strpro2, strpro3 );

 

}

 

// If the function does not exist, false is returned.

Return false;

}

 

 

Results An exception occurs during each call. It was later found that it was a parameter problem. The parameter types of interfaces in master C and dynamic library a must be strictly consistent. Either cstring or lcpstr. Otherwise, exceptions are not surprising.

 

Note the parameter type of the interface.

 

 

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.