Click here to Skip to main content
16,006,709 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralGetting a blank document by clicking OnNewDocument Pin
mr20031-Jun-01 6:45
mr20031-Jun-01 6:45 
GeneralRe: Getting a blank document by clicking OnNewDocument Pin
2-Jun-01 5:11
suss2-Jun-01 5:11 
GeneralLoad CBitmap with LoadBitmap(); Pin
Paul Goodyear1-Jun-01 6:12
Paul Goodyear1-Jun-01 6:12 
Question"Printing" to a bitmap? - How? Pin
Jim Howard1-Jun-01 6:10
Jim Howard1-Jun-01 6:10 
AnswerRe: Pin
Tomasz Sowinski1-Jun-01 7:54
Tomasz Sowinski1-Jun-01 7:54 
Generaluse a C function from a C++ program Pin
hearties1-Jun-01 5:55
hearties1-Jun-01 5:55 
GeneralRe: use a C function from a C++ program Pin
Stephen Kellett1-Jun-01 6:24
Stephen Kellett1-Jun-01 6:24 
GeneralRe: use a C function from a C++ program Pin
Jim Howard1-Jun-01 6:28
Jim Howard1-Jun-01 6:28 
To use a 'C' libary in a 'C++' program, in the header file for the c program, you prefix function declarations with "extern C" preprocessor commands.

For example, if you are using only C++, just do this in driver.h:

extern "C" void ExportedFunction(void* pBlah);

This tells the C++ complier that this function is to be treated as a plain ole 'C' function.

If you have several exported functions in the header file, you don't have write "extern C" for each one, you can use braces:

extern "C"
{
char ShowChar( char ch );
char GetChar( void );
}

If driver.h might also be used by a 'C' compiler, you use the processor to make sure that only the C++ compiler sees the "extern" command:

#ifdef __cplusplus
extern "C"
{
#endif
void ExportedCfunction1(void *pBlah);
void ExportedCfunction2(void *pBlah);
void ExportedCfunction3(void *pBlah);
#ifdef __cplusplus
}
#endif

If you don't want to change driver.h, you can surround the include statement in the cpp file for the driver with the extern command:

// Cause everything in the header file "cinclude.h"
// to have C linkage.
extern "C"
{
#include <cinclude.h> //from MSDN
}

See "Linkage to Non-C++ Functions" in MSDN for more fun with "extern".

Of course you want to be sure that the linker knows where to find driver.lib. In Visual Studio you do this with the project settings->linker.

Jim
GeneralCatching ESCape key in a CDialog window Pin
1-Jun-01 4:58
suss1-Jun-01 4:58 
GeneralRe: Catching ESCape key in a CDialog window Pin
Tim Deveaux1-Jun-01 5:38
Tim Deveaux1-Jun-01 5:38 
GeneralCComboBox problem Pin
David Burrows1-Jun-01 4:55
David Burrows1-Jun-01 4:55 
GeneralRe: CComboBox problem Pin
Tomasz Sowinski1-Jun-01 7:42
Tomasz Sowinski1-Jun-01 7:42 
GeneralPlease help : problem with distributing ActifveX control Pin
Bartek1-Jun-01 4:55
Bartek1-Jun-01 4:55 
General#pramga startup equivilent Pin
Steve Thresher1-Jun-01 4:41
Steve Thresher1-Jun-01 4:41 
GeneralRe: #pramga startup equivilent Pin
Tim Deveaux1-Jun-01 5:30
Tim Deveaux1-Jun-01 5:30 
GeneralRe: #pramga startup equivilent Pin
Tomasz Sowinski1-Jun-01 7:36
Tomasz Sowinski1-Jun-01 7:36 
GeneralRe: #pramga startup equivilent Pin
Steve Thresher2-Jun-01 1:39
Steve Thresher2-Jun-01 1:39 
Generallinking error: library conflict Pin
hearties1-Jun-01 3:29
hearties1-Jun-01 3:29 
GeneralRe: linking error: library conflict Pin
Dave Carkeet1-Jun-01 4:32
Dave Carkeet1-Jun-01 4:32 
GeneralMsComm example ... Pin
Hadi Rezaee1-Jun-01 1:09
Hadi Rezaee1-Jun-01 1:09 
GeneralLinker error 2005 Pin
1-Jun-01 0:56
suss1-Jun-01 0:56 
GeneralRe: Linker error 2005 Pin
Tim Deveaux1-Jun-01 4:42
Tim Deveaux1-Jun-01 4:42 
GeneralCStringArray Pin
1-Jun-01 0:13
suss1-Jun-01 0:13 
GeneralRe: CStringArray Pin
Mukkie2-Jun-01 8:36
Mukkie2-Jun-01 8:36 
GeneralRe: CStringArray Pin
5-Jun-01 3:47
suss5-Jun-01 3:47 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.