C # Notes

Source: Internet
Author: User

C # Notes
Read webpage:

Using system. net;
Using system. text;
Using system. Web;
Using system. IO;
Public void getpagecontent (string URL)

{
Webrequest request = webrequest. Create (URL );
Try
{
// Request service
Webresponse response = request. getresponse ();
// Return information
Stream resstream = response. getresponsestream ();
Streamreader sr = new streamreader (resstream, system. Text. encoding. Default );
String tempcode = Sr. readtoend ();
Resstream. Close ();
Sr. Close ();

Textbox1.text = (tempcode );
}
Catch
{
MessageBox. Show ("error occurred. Check whether the network is connected ;");
}
}

Http://www.xgdown.com/article/32/ArticleList32_1.htm

# Hosting C ++ Environment Settings

Create a hosted C ++ Application

You can use three methods to create hosted C ++ applications and components:

Create a hosted C ++ application from the draft.
Converts an existing C ++ application into a hosted C ++ application.
To create a hosted C ++ application or component, You can package existing components in the hosted C ++ shell.

Instance:

Create an MFC Application and pass it to CLR. You need to change the compilation options of some projects;
Open the MFC project.
Solutious Explorer-> properties.
You can select all deployments in the configuration combo box at the top of the Project Properties dialog box.
Select C/C ++ general.
Complie as managed-> Assembly Support (/CLR)
Debug information format-> program database (/Zi)
Select C/C ++ code generation on the left
Enable minimal rebuild-> NO
Basic runtime checks-> default
Click OK.

Note: you may need to handle pre-compilation commands and cancel pre-compilation commands.
C/C ++ precomplied headers-> Create/use precompiled header-> not using precompiled headers

In this way, the project can be effectively converted to CLR for compilation.

When you add a. net base class library to an MFC application, pay attention to the details.

The debug version of MFC redefined the new operator to track allocated memory and identify memory leaks in applications. however.. Net object is not compatible. therefore. # pragma push_macro, pop_macro and # UNDEF commands are used to redefine the new operator so that managed objects can be used.

# Ifdef _ debug
# Pragma push_macro ("new ")
# UNDEF new
# Endif

String * s;
S = new string ("this is a managed string for test .");

# Ifdef _ debug
# Pragma pop_macro ("new ")
# Endif

# In C #, how do I call a self-written DLL file?
Reward score: 10-resolution time:
I wrote a DLL file myself and how to call it in the program

Create a new project, right-click the project "Reference", and click "add reference" to browse to your DLL file. Then you can use it ~

### How to call a DLL written in C ++
I know it is very convenient to drop functions written in C ++ in C #.
Using system. runtime. interopservices;

[Dllimport ("user32.dll")]
Public static extern int activatekeyboardlayout (
Int HKL,
Int flags
);
# C # Call the COM Component
Just add reference directly.

# If it is drawn on a form
Image imgpic = image. fromfile (yourimagefile );
Graphics G = This. creategraphics ();
G. drawimage (imgpic, yourstartx, yourstarty, imagewidth, imageheight );
G. Dispose ();

/////////////////
First convert byte [] to system. Io. Stream stream;
Then:
Bitmap BMP = new Bitmap (Stream );
G. drawimage (BMP, 0, 0 );

For example:
Byte [] imgbytearray = getimage ("2"); // This Is Your byte array
Memorystream stream = new memorystream ();
Stream. Write (imgbytearray, 0, imgbytearray. Length );
// Display the image
Image m_bitmap = image. fromstream (Stream );
This. creategraphics (). drawimage (m_bitmap, 0, 0 );
Stream. Close ();

##

RTSP: // 219.223.252.38: 554/movie2/zoujinkexue15/01. rmvb

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.