Click to See Complete Forum and Search --> : C,C++ Linking
Minsu,Yun
April 27th, 1999, 12:55 AM
Now I am programming C program.(About 15,000 line)
But this program consists of only WIN32 APIs.
I want to link my program with VC++ Class.
Because my C program has some bugs in File Open Dialogbox,
I want to use CFileDialog Class.
Is it possible?
Please help me.
textshop@unitel.co.kr
Rob Wainwright
April 28th, 1999, 03:23 PM
It is certainly possible. One of the first things to do is to check through a typical MFC program and notice the headers and libraries that are included in your makefile.
If your program is a console like C program it is probably easiest to create yourself an MFC console application and then just paste your code in.
If your program is a GUI application, you will already have a message loop and you'll need to replace this (and probably lots more) to get a build.
If the worst comes to the worst, you should be able to go into the MFC source code and pull out the class declaration and definition of CFileDialog (and related code) and insert it into your C program without too much hassle.
rajasekar.s
April 30th, 1999, 01:50 AM
hi,
Have an extern function in the C file.
Define the function in the CPP file. This function has to be have the linkage specifier extern "C". dont forget to do this !
A small code have to be written before doing anything with MFC resource.
Call AfxSetResourceHandle ( ) passing it the module handle that has the resource.
If u dont have a seperate DLL give the instance handle that u get in WinMain.
Then instantiate an object of type CFileDialog and use it as u wish !
if u dont call AfxSetResourceHandle u get an assertion failure !
The code will be -
In ur C file have
extern void Somefuncion ( /* your parameters */ );
HINSTANCE ghInstance;
.
.
.
ghInstance = hInstance; /* instance handle of the module containing the resource */
Somefunction ( /* params if u have any */ );
.
.
.
In Another CPP file
extern "C" HINSTANCE ghInstance;
extern "C" void Somefunction ( /* params if u have any */ )
{
AfxSetResourceHandle ( ghInstance );
/* do anything here to process the args */
CFileDialog fd(TRUE);
fd.DoModal();
/* fd.GetPathName() gives the filename */
/* anything u wish here */
}
bye.
pkraman
April 30th, 1999, 03:58 AM
hi,
In MFC when you give File Open Command, it calls the CWinApp's member function DoPromptFileName. this in turn calls CDocManager's DoPromptFileName. the actual code for displaying the open dialog box is present in CDocManager::DoPromptFileName (DOCMGR.CPP). copy that code and make the necessary changes and you'll get the answer.
Regards,
Kalyan
P.S:
you can even customize the Open Dialog box as you wish.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.