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