程序具有:raw_mouse.h,raw_mouse.c RawInputRegistry.h RawInputRegistry.cpp和main.cpp
在raw_mouse.h中,
我定义了:
typedef WINUSERAPI INT (WINAPI *pGetRawInputDeviceList)(OUT PRAWINPUTDEVICELIST pRawInputDeviceList, IN OUT PINT puiNumDevices, IN UINT cbSize);
void testme();
在raw_mouse.c中,我有:
_RRID = (pRegisterRawInputDevices)GetProcAddress(user32,"RegisterRawInputDevices");
void testme()
{
int a =10;
}
我在raw_mouse.c中包括了raw_mouse.h,在RawInputRegistry.h中也包括了raw_mouse.h,最后在main.cpp中包括了RawInputRegistry.h
但是,我得到了这些错误:
RawInputRegistry.obj : error LNK2005: "int (__stdcall* _GRID)(struct HRAWINPUT__ *,unsigned int,void *,int *,unsigned int)" (?_GRID@@3P6GHPAUHRAWINPUT__@@IPAXPAHI@ZA) already defined in main.obj
RawInputRegistry.obj : error LNK2019: unresolved external symbol "void __cdecl testme(void)" (?testme@@YAXXZ) referenced in function "protected: __thiscall RawInputEventRegistry::RawInputEventRegistry(void)" (??0RawInputEventRegistry@@IAE@XZ)
不知道我是否应该使用extern“C”来包含raw_mouse.c中的所有代码?
最佳答案
您有可以放置s.th。在raw_mouse.h
文件中添加以下内容,以使其同时符合c++和c #include
:
#ifndef RAW_MOUSE_H__
#define RAW_MOUSE_H__
#ifdef __cplusplus
extern "C" {
#endif
/* Your C function declarations go here ... */
#ifdef __cplusplus
}
#endif
#endif /* RAW_MOUSE_H__ */