C#中调用API函数

2024-11-29 09:29:56
推荐回答(2个)
回答1:

C#中调用API函数
umFontFamilies
The EnumFontFamilies function enumerates the fonts in a specified font family that are available on a specified device.

Note This function is provided only for compatibility with 16-bit versions of Windows. Applications should use the EnumFontFamiliesEx function.

int EnumFontFamilies(
HDC hdc, // handle to DC
LPCTSTR lpszFamily, // font family
FONTENUMPROC lpEnumFontFamProc, // callback function
LPARAM lParam // additional data
);
Parameters
hdc
[in] Handle to the device context.
lpszFamily
[in] Pointer to a null-terminated string that specifies the family name of the desired fonts. If lpszFamily is NULL, EnumFontFamilies selects and enumerates one font of each available type family.
lpEnumFontFamProc
[in] Point to the application definedcallback function. For information, see EnumFontFamProc.
lParam
[in] Pointer to application-supplied data. The data is passed to the callback function along with the font information.
Return Values
The return value is the last value returned by the callback function. Its meaning is implementation specific.

喜居宝地千年旺 福照家门万事兴 喜迎新春

回答2:

首先要在文件开头加上using System.Runtime.InteropServices;
调用某个API函数之前声明一下,例如FindWindow
[DllImport("USER32.DLL")]
public static extern IntPtr FindWindow(string lpClassName,string lpWindowName);
DllImport后面指定API函数所在的dll文件名,IntPtr 对应的是指针类型