Linking MFC C++ function with Standard C 
Author Message
 Linking MFC C++ function with Standard C

Is it poosible to link a funktion using MFC into a regular C program.
? can't get it to work, can sbdy help me please.

/Erik



Mon, 31 Jul 2000 03:00:00 GMT  
 Linking MFC C++ function with Standard C

Hi Erik,

The problem is that MFC is based on C++. And the C++ calling interface is
not identical to the C interface. So unless you write a C++ wrapper that
calls MFC you will not be able to do so. The C++ wrapper must define its
entries with the "C" type interface (i'm sorry that I do not have to
correct syntax at hand now).

Quote:

> Is it poosible to link a funktion using MFC into a regular C program.
> ? can't get it to work, can sbdy help me please.

> /Erik

--
Rob Goudvis




Tue, 01 Aug 2000 03:00:00 GMT  
 Linking MFC C++ function with Standard C

The simple answer: no.

MFC requires that the full MFC library be available and be properly
initialized.  A C program has no provision for doing such
initialization, including making sure any necessary constructors on
static data objects have run before main() is called.

For C++, you would have to have a C++ version of main() so that the
C++ runtime started up properly; you could then call any C++ functions
thereafter (for example, you could create main.cpp, have it say
        int main(int argc, char * argv[])
           {
             return mymain(argc, argv);
                 }

and that's all, then rename the 'main' of the C program to 'mymain'.
I did this once and it worked.  But MFC makes a *lot* more assumptions
about the environment it is running in, and as good as I am at MFC I'd
be terrified to try this.

This is not to say it is impossible.  For example, you might chage
your InitInstance to call 'mymain' (using the same renaming trick),
e.g.,
        BOOL MyApp::InitInstance()
            {
              //...lots of standard InitInstance stuff
             mymain(__ARGC, __ARGV);
                  return FALSE;
                 }

This will violate fewer assumptions but is still a bit dicey, because
MFC assumes there is a main window and you probably won't have one.
Given this is a C program, it is either a GUI-based program or a
console app.  If it is a console app, life is hard in one way; if it
is an existing GUI app, life is hard (much harder, actually) in
another way.

I've heard that some MFC functionality such as CString is now
available separate from the bulk of the MFC library, but I've not
looked into this because I tend to build full MFC apps.
                                joe



Quote:

>Is it poosible to link a funktion using MFC into a regular C program.
>? can't get it to work, can sbdy help me please.

>/Erik

Joseph M. Newcomer

http://www3.pgh.net/~newcomer


Wed, 02 Aug 2000 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Newbie: separate big .cs file into small .cs files

2. linking standard c programs with MFC

3. Static linking in VC++ .NET Standard to MFC?

4. Need C++ text for non cs major course

5. Standard C++ Library Link Error

6. static linking to c++ standard libraris

7. C++ 4.0 doesn't work like C++ 2.0 for function exports and explicit linking

8. Standard C++ function calling convention

9. Convert an app to MFC from standard C++??

10. MFC Vs Standard C++ Library

11. MFC class able to implement the standard C++ library iostream functionalities in a scrolled window

12. Standard C++ library and MFC

 

 
Powered by phpBB® Forum Software