I wrote a C++ program that could sendKey. the code is as Follows;


this piece if code is inside a function.

Now, i need to access this method from a C code. When i added the includes, i get alot of errors. Some says, that you can't access C++ code from a C program. is this statement correct?

If so, Could someone tell me or give me a sample code to have key press in C. like what i did in C++.

I am new to C, google didn't help me, please help me solve this

6 Years
Discussion Span
Last Post by Narue

is this statement correct?

Nope, but there are caveats. You can't directly access C++-specific features without wrapping them in a C-compatible interface. This is done with the extern "C" construct to force C linkage and disable name mangling:

extern "C" void c_send_key(const char *key)
    // ...

In the C program, you can link to the C++ object file and call the function:

extern void c_send_key(const char *key);

int main(void)
    return 0;

Further reading.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.