You are here:

C++/Visual C++ 6: Calling a function in a C program.


Hi David,

Let me put it more clearly.

I am writing a VC++6 MFC application. I want to integrate a third-party C program to create a Message Digest of Clipboard data. I am new to VC++. I somehow managed to obtain the Clipboard data in my VC++ function. Now I want to transfer this data to the C HASH program which I added to my project. Now here I am experiencing problems.

(1) The first problem is that the clipboard data can be of any size. When I transfer this to say function, HASH() of the C program, how to define the data type. Someone suggested me to use HASH(void *data, size_t dataLen).

(2) The second problem is that the C program contains a MAIN function, as it should be. So I need to pass the Clipboard data as an argument to the Main function of this C program.
In my VC++ project the main file RP.CPP contains functions which activate when a menu option is clicked. From these functions, i.e., from this RP.CPP I need to call the Main function of the C program with Clipboard data as an argument.


Followup To
Question -
I have added a C program in my VC++ project and want to call its
functions when an option is clicked from the menu.
Do I need to create a Class for all the functions in the C program?
If a Class needs to be created, then where to create the Class and
what will be the base Class?
Answer -
Rohit , Thank you for your question.

Since C does not include classes, it would make no sense to declare C functions as class members.

C functions can be called from C++ programs. Declare them in C++ source files as follows:

#ifdef __cplusplus
extern "C"{

void func();

#ifdef __cplusplus

David Spector


1. You cannot redefine a function argument list as you have indicated. You must supply the called function with the data in whatever way the called function expects it. The HASH function is declared in the Include file that comes with your library.

2. You cannot combine a Windows program with a C program containing a "main" function. Perhaps you need to run the C program as a separate process. I cannot advise you on this, as it depends on the library.

I suggest you read the instructions on using the library carefully, as well as studying the programming examples that come with it.

Good luck!

If you have further questions, please do not hesitate to ask.



All Answers

Answers by Expert:

Ask Experts


David Spector


Highly knowledgeable in the C++ language, Visual C++ (MSVC), Windows API, documentation and other quality-assurance techniques, and debugging. Knowledgeable in MFC, COM, GUI design, and object-oriented design.


I have been a software engineer since 1965. I have been published. My specializations have been: biomedical programming, compiler implementation, and many kinds of Windows programming. I don't do Databases or other business-oriented stuff.

Windows?/DOS Developer's Journal, ACM SIGPLAN Notices, and Computer Science Press.

ICCP Systems Programming Certification
Master's degree equivalent in Computer Science

©2016 All rights reserved.