VB.net calls the C++dll string delivery problem __.net

Source: Internet
Author: User

The company wants to use vb.net to call Hkust's voice synthesizer interface

The first is to write their own tts_sample demo, but because C + + and vb.net data structure is not the same, so gave up the custom demo this method

So simply take that demo as DLL file call interface on the line
In fact, my DLL is written in C, read a lot of examples on the internet just understand
__declspec (dllexport) int add ();
This method can generate DLL files
However, there are many problems with vb.net calls
Like what:
Garbled when passing in strings
The reason may be that the managed PInvoke signature does not match the unmanaged target signature
The entry point cannot be found
Wait

Public Declare Function add Lib "Edr.dll" (ByVal params as String) as Integer
You need to use the int __stdcall keyword in C + + and you need a def file to use the Declare method
Use the DllImport method to use __declspec (dllexport) in C + + without def files
Here I use the Declare method
C + + function definition
int __stdcall Add (const char* login_params)
def file definition
LIBRARY EDR
Exports
Add @ 1
vb.net function call
Public Declare Function Add Lib "Edr.dll" (ByVal Login_params as String) as Integer

Passing parameters by using the ByVal method

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.