C # rename the file-Discard moveTo and reference rename in VC to generate rename. dll

Source: Internet
Author: User

1: Create a Win32 simple dynamic link library in vc6

2: add the rename. cpp file as follows:

 

# Include <string>
# Include <stdlib. h>
Using namespace STD;

Extern "C" int _ declspec (dllexport) renamefile (char * _ oldname, char * _ newname );

Int renamefile (char * _ oldname, char * _ newname)
{
Char oldname [1000], newname [1000];
Strcpy (oldname, _ oldname );
Strcpy (newname, _ newname );
If (Rename (oldname, newname) = 0)
Return 0;
Else
Return 1;
}

3: Generate rename. dll

4: Call in C #

Copy rename. DLL to ApplicationProgramBin directory

C # program:

Using system. runtime. interopservices;

Namespace winapp
{
Public partial class form4: Form
{
[Dllimport ("RENAME. dll", entrypoint = "renamefile")]
Public static extern int renamefile (string source, string DEST );
Public form4 ()
{
Initializecomponent ();
}

Private void button#click (Object sender, eventargs E)
{
This. Text = renamefile (@ "C: \ 1.txt", @" C: \ 2.txt"). tostring ();
}
}
}

Attachment: vc6 rename Program/files/94 cool/rename.rar

Rename. dll/files/94 cool/rename.dll.rar

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.