
Renaming a Function in C# and C++
You can use the DllImportAttribute..::.EntryPoint field to specify a DLL function by name or ordinal. If the name of the function in your method definition is the same as the entry point in the DLL, you do not have to explicitly identify the function with the EntryPoint field. Otherwise, use one of the following attribute forms to indicate a name or ordinal:
[DllImport("dllname", EntryPoint="Functionname")]
[DllImport("dllname", EntryPoint="#123")]
Notice that you must prefix an ordinal with the pound sign (#).
The following example demonstrates how to replace MessageBoxA with MsgBox in your code by using the EntryPoint field.
using System.Runtime.InteropServices;
public class Win32 {
[DllImport("user32.dll", EntryPoint="MessageBoxA")]
public static extern int MsgBox(int hWnd, String text, String caption,
uint type);
}
using namespace System::Runtime::InteropServices;
typedef void* HWND;
[DllImport("user32", EntryPoint="MessageBoxA")]
extern "C" int MsgBox(HWND hWnd,
String* pText,
String* pCaption,
unsigned int uType);