Some Applications of c # Calling C ++ code,

Source: Internet
Author: User

Some Applications of c # Calling C ++ code,

1. dll function import:
Keywords: unmanaged code; managed code;
Specific Application class: System. Runtime. InteropServices
Usage:
[DllImport ("muParser. dll", EntryPoint = "mupSetExpr", SetLastError = true, CharSet = CharSet. Ansi, ExactSpelling = true, CallingConvention = CallingConvention. StdCall)]
Public static extern void mupSetExpr (void * parser_handle, StringBuilder a_szExpr );
Note: EntryPoint is the same as the function name CharSet. Do not use uncode easily.
To use pointers for function parameters, use unsafe.

2. Use of function pointers:
Keyword: delegate
Usage:
C ++: typedef double (* fun_type1) (double );
C #: public delegate double fun_type1 (double );
Note: c # uses the delegate method to implement the function pointer. When used, the pointer in c ++ is removed.
The Parameter definition is the same as that of c ++.

3. Define pointer values
Keyword: fixed
Usage instructions: mainly to return the pointer address, which does not seem to be supported in c # & (may be inaccurate)
You cannot assign values to pointers directly.
Example:
Public double * AddVariable ()
{
Fixed (double * ptrVar = & afValBuf)
{
Return ptrVar;
}
}
Note: Related pointer variables must be included in fixed.

4. Operations on c ++ function parameters being char *
Keyword: StringBuider
Specific instructions for use: the char * operation in c ++ reads data in one byte,
The String in c # is read in two bytes, so it cannot be used.
Therefore, use StringBuilder instead.

No better method yet. If so, let me know.


5. dll Import
If the dll in c ++ is not a component (or COM), it cannot be directly applied through the. NET reference.
My solution:
Application Platform:. net website
Method: Create ClassLibrary and place the dll to be applied in the bin. then compile the project and use the newly generated dll.

6. Use pointers in c:
Keyword: unsafe
Usage: Add unsafe where the pointer is needed


For C Language

While (c = getchar ())! = '\ N ')
This sentence
You can understand it
When the system function getchar is reading characters
No line breaks
Press ENTER
Then the loop continues
If (c> = 'A' & c <= 'Z') | (c> = 'A' & c <= 'Z '))
This is the big condition of if.
You must enter one of the 26 letters
Case Insensitive
Last question
I'm a little dizzy.
I don't know why LZ is working with V.
If (c> 'Z' & c <= 'Z' + 4 | c> 'Z ')
This sentence is equivalent to if (c> = 'A' & c <= 'Z ') | (c> = 'A' & c <= 'Z') The second condition of the else if statement chain

Use break in C Language

Break statement
Break statements are usually used in loop statements and switch statements. When a break is used to switch a switch statement, the program can jump out of the switch and execute the statement after the switch. If there is no break statement, it will become an endless loop and cannot exit. The usage of break in the switch has been met in the previous example when we introduced the switch statement. Here we will not give an example.
When the break statement is used in do-while, for, and while loop statements, the program can terminate the loop and execute the statements following the loop. Generally, the break statement is always associated with the if statement. That is, the loop jumps out when the conditions are met.
Note:
1) The break statement does not work for the if-else Condition Statement.
2) in a multi-tier loop, a break statement only jumps one layer outward.
Your problem is to jump out of the for Loop and execute the statement after the loop, that is, str [I ++] = '.'; Statement

Related Article

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.