简体   繁体   中英

Visual C++: function definition for 'mouse_event' not found

Trying to use some Windows API in my Visual C++ project, encountering compilation issues.

Within my class I have the following code:

public:    
[System::Runtime::InteropServices::DllImport("user32.dll")]
static extern void mouse_event(int dwFlags, int dx, int dy, int cButtons, int dwextrainfo);

This is all I have in my class as I'm currently trying to get mouse_event() to work.

"extern" is throwing:

more than one storage class specified

"mouse_event" is throwing the linking error:

Function definition for "mouse_event" not found

I've declared mouse event as extern, included Windows.h and imported user32.dll, is this not all that's required to link to the definition of mouse_event() within user32.dll?

When changing static extern to just extern , it throws:

Invalid storage class for a class member

Shouldn't extern be ok in a class definition when used on a member's declaration?

I've seen very similar code implementation of this function on stackoverflow before.

If it helps, my class is defined as "ref class"

Any thoughts?

I assume you are trying to emulate interop syntax you found as it pertains to C#? Such action in C++ is a little more involved: https://msdn.microsoft.com/en-us/library/3y1sfaz2.aspx

EDITED FOR EXPOSITION: If this isn't the case, please specify your source inspiration for such an approach, or the rest of your class, because as it stands, I don't see this working in C++, visual or not. That isn't even an extant C++ namespace you're targeting there, but it is a .NET one, substantiating my assumption...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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