简体   繁体   English

无法在C中定义函数类型

[英]Can not define a function type in C

It just confused me: 它让我很困惑:

typedef bool(*pGetNameByPid)(DWORD PID, TCHAR lpszProcessName[MAX_PATH]);

Is there anything with the sentence above? 上面的句子有什么问题吗? I want to export an function named GetNameByPid from an DLL written in C++. 我想从用C ++编写的DLL中导出一个名为GetNameByPid的函数。 But the compile reports that: 但编译报告说:

error C2143: syntax error : missing ')' before '*'

Any help? 有帮助吗?

There is no bool type in C89, which is the C standard that the Microsoft Compilers support. C89中没有bool类型,这是Microsoft Compilers支持的C标准。 You could use an int or WINAPI's BOOL as the return type: 您可以使用int或WINAPI的BOOL作为返回类型:

typedef BOOL (*pGetNameByPid)(DWORD PID, TCHAR lpszProcessName[MAX_PATH]);

To export a function from DLL: 要从DLL导出函数:

__declspec(dllexport) BOOL GetNameByPid(DWORD PID, TCHAR* lpszProcessName)
{
    /* Do some work */
    return TRUE;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM