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

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.