Dynamic Features of C #4

Source: Internet
Author: User

1. Call the COM component:

Type type = type. gettypefromprogid ("visualphd. Data"  );
Dynamic PHD = activator. createinstance (type );
PhD. hostname = "192.168.53.186 ";
2. Reflection call DOTNET class

Type type = type. GetType ("leleapplication1.test ");

Dynamic T = activator. createinstance (type );

T. Print ("Hello! ");

 

3. Using pinvoke is simpler

Download open source component http://code.google.com/p/dynamicdllimport/

You can use the following to call an unmanaged DLL, including a Windows API and a self-developed C-format DLL.

 
Dynamic USER32 = new dynamicdllimport ("user32.dll", callingconvention: callingconvention. winapi );
User32.messagebox (0, "Hello World", "platform invoke sample", 0 );
 
Dynamic asmproject = new dynamicdllimport ("asmproject. dll ");
Int value = asmproject. Add <int> (3, 4 );
Console. writeline (value );
 
Dynamic SDL = new dynamicdllimport ("SDL. dll", charset. ANSI );
SDL. sdl_rect rect = new SDL. sdl_rect (
0,
0,
(Short) width,
(Short) height );
Int result = SDL. sdl_fillrect <int> (rgbsurfaceptr, ref rect, 0 );
SDL. sdl_event EVT;
While (SDL. sdl_waitevent (Out EVT )! = 0)
{
If (EVT. type = SDL. sdl_quit)
{
Break;
}
}

 

 

 

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.