messagebox.cpp
来自「Vc.Net入门与提高源码」· C++ 代码 · 共 23 行
CPP
23 行
#using <mscorlib.dll>
using namespace System;
using namespace System::Runtime::InteropServices;
__gc struct S
{
[DllImport("user32", CharSet=CharSet::Ansi)] //通过P/Invoke导入
static int MessageBox(void* hWnd,
String* pText,
String* pCaption,
unsigned int uType);
};
__delegate int MyMessageBox (void* hWnd, // 代理的声明
String * pText,
String * pCaption,
unsigned int uType);
int main()
{
MyMessageBox* myb = new MyMessageBox(0, &S::MessageBox); // 实例化
String * pText = S"Hello, World!";
String * pCaption = S"Pinvoke Test";
myb(0, pText, pCaption, 0); // 通过代理myb调用MessageBox调用Windows API函数
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?