Dllimport defect of Visual Studio

Source: Internet
Author: User
Tags crypt

To write a CS file in Visual Studio, you need to use dllimport to call an unmanaged Win32 API, such

 

1 Using System;
2 Using System. runtime. interopservices;
3
4 Class Example
5 {
6 // Use dllimport to import the Win32 MessageBox function.
7 [Dllimport ( " User32.dll " , Charset = Charset. Auto)]
8 Public   Static   Extern   Int MessageBox (intptr hwnd, string text, string caption, Uint Type );
9
10 Static   Void Main ()
11 {
12 // Call the MessageBox function using platform invoke.
13 MessageBox ( New Intptr ( 0 ), " Hello world! " , " Hello Dialog " , 0 );
14 }
15 }
16

 I often have the following problems:

Dllimport andPublic StaticThe most important part of the two rows should be manually typed in, such as the function name MessageBox and the parameter list (intptr hwnd, string text, string caption, uint type ), why cannot powerful Visual Studio be automatically completed?

 

I think if Visual Studio is more user-friendly, it should be like this:

In *. right-click the CS file and choose "win api call" or "dllimport" from the shortcut menu. The DLL file selection window is displayed (commonly used Win32 dll can be listed here, so that you do not need to go to system32 ), select the DLL file and click OK. The DLL function list is displayed. Each function name has a checkbox before it. Select checkbox. OK.

[Dllimport ( " User32.dll " , Charset = Charset. Auto)]
Public   Static   Extern   Int MessageBox (intptr hwnd, string text, string caption, Uint Type );

Insert it to the head of the CS file, and automatically convert the function parameter list to the CSHARP type and fill it in completely. How cool. Why is Ms not done? It should not be unexpected. You can useDumpbin/exports user32.dllOr Link/dump/exports user32.dll Command.

 

What worries me most is the parameter list and parameter type.If a third-party vendor threw you a crypt. DLL without documentation, the boss asked you to use C # To Call crypt. DL to implement some features of the product, even if I usedDumpbinI have obtained the function list, but I don't know the parameters. Isn't it possible? Also, if some function parameters are not the basic data type of C #, isn't it possible? Let's talk about it.

 

I am not a newbie, please kindly advise me.

 

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.