Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

C/C++ with msvc 1.52

Posted on 2006-07-11
9
Medium Priority
?
453 Views
Last Modified: 2010-04-15

Hello,

I have a DLL application coded in C.

I want to include a C++ header file that I just created to 1 of the C file in this DLL application. Is it possible?

Thanks
0
Comment
Question by:TungVan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 172 total points
ID: 17083976
That depends on what is in the header file. If some is C++ specific, you might need to make it 'invisible' for the C compiler by using

#ifdef __cplusplus

// C++ specific stuff here

#endif
0
 
LVL 16

Expert Comment

by:PaulCaswell
ID: 17084434
Hi TungVan,

The compiler (Ms C8) that shipped with MSVC 1.5.2 is not terribly flexible but it is fully capable of handling both C++ code and C code. Have you tried it? What problems are you having?

Paul
0
 
LVL 86

Expert Comment

by:jkr
ID: 17084578
>>but it is fully capable of handling both C++ code and C code

You will run into trouble if you use e.g. a 'class' in a file with a .c extension.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 16

Expert Comment

by:PaulCaswell
ID: 17084661
jkr is right!

If you need to include a C++ header, try changing the extension of the .C file to .CPP.

What do you need to access from the header? If its just globals or #defines, consider moving those out to a separate header file. If you need to create/access the class you will need to make the compiler treat it as C++ by changing its extension.

Paul
0
 

Author Comment

by:TungVan
ID: 17119517

>Paul

I cannot change the extension (that's one of the requirement) and I won't create classes in this c file.

I just wonder if I put the C++ code in this C file, would the compiler able to compile this DLL?
0
 
LVL 14

Assisted Solution

by:cwwkie
cwwkie earned 164 total points
ID: 17121171
> I just wonder if I put the C++ code in this C file, would the compiler able to compile this DLL?

can you give an example of the c++ code you are trying to compile as c?


> I want to include a C++ header file that I just created to 1 of the C file in this DLL application. Is it possible?

put extern "C" around the declarations, for example:

extern "C" {

    void dllfunc1(void);
    int dllfunc2(int, char*);

}

extern "C" is c++ syntax, so to be able to compile that on both c as c++, you have to combine that with the first comment of jkr:

#ifdef __cplusplus
extern "C" {
#endif

    void dllfunc1(void);
    int dllfunc2(int, char*);

#ifdef __cplusplus
}
#endif
0
 
LVL 16

Assisted Solution

by:PaulCaswell
PaulCaswell earned 164 total points
ID: 17124882
You may be able to lie to the compiler by using #include "File.cpp" inside a "CFile.C" but that should be avoided if at all possible.

Paul
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question