Can we use COM and MFC simultaneously

Hi!
I am using Win-32 console Application with MFC support on Win-NT.
Now for database connection and getting current time I am using MFC classes like CDatabase and CTime.
For sending emails I am using CDONTS.dll in which I wanna use INewMail interface (which has methods like to,cc,bcc,attachfile etc......), but it does not allow me to compile the program at all since there is conflict between MFC classes and COM objects. It's giving me error of to be specific redefinition of folder option etc..
I have tried /FORCE:MULTIPLE to avoid the conflict but still the same errors.
It gives me 26 errors.
It may be because I don't have cdonts_i.c and cdonts.idl file for CDONTS but I am directly using import "CDONTS.dll" named_guids,no_namespace

Please guide me If I wanna send email How do I send it?
Any other suggestions rather than I am using is welcome, but should be as flexible as CDONTS since it takes care of multiple recepients and file attachments.

ThankYou.
arpit080399Asked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
ShaunWildeConnect With a Mentor Commented:
okay can you post your .tlh and .tli files ?
0
 
arpit080399Author Commented:
Also it is possible to use CDOSYS to send emails but it works only on Windows 2000.
0
 
ShaunWildeCommented:
can you paste in the exact error you get from the compiler?
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
jhanceCommented:
MFC and COM are not in conflict.  They are not even necessarily related to each other.  MFC is a set of class libraries where COM is an component object technology.  COM objects can be written using MFC or not.  MFC programs as well as non-MFC programs can use COM objects.



You need to be more specific about the problem you are having and post the exact error you are getting.  It would also help to see the code that is creating the error.
0
 
arpit080399Author Commented:
#include "stdafx.h"
#include "cdontstest.h"

#import "cdonts.dll" named_guids, no_namespace


#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// The one and only application object

CWinApp theApp;

using namespace std;

int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
      int nRetCode = 0;

      // initialize MFC and print and error on failure
      if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
      {
            // TODO: change error code to suit your needs
            cerr << _T("Fatal Error: MFC initialization failed") << endl;
            nRetCode = 1;
      }
      else
      {
            // TODO: code your application's behavior here.
            CoInitialize(NULL);
            INewMail *sendmail = 0;
            HRESULT hr;
            hr = CoCreateInstance(CLSID_NewMail,NULL,CLSCTX_ALL,IID_INewMail,(void **)&sendmail);
            if(SUCCEEDED(hr))
            {
                  printf("Created NewMail Object.......\n");
            }
            

      }

      return nRetCode;
}



error

e:\platsdk\cdontstest\cdonts.tlh(31) : error C2367: 'Folder' : redefinition; different uuid specifiers
        e:\program files\microsoft visual studio\vc98\include\exdisp.h(4584) : see declaration of 'Folder'
e:\platsdk\cdontstest\cdonts.tlh(577) : error C2011: 'Folder' : 'struct' type redefinition
e:\platsdk\cdontstest\cdonts.tli(467) : error C2039: 'GetApplication' : is not a member of 'Folder'
        e:\program files\microsoft visual studio\vc98\include\exdisp.h(4584) : see declaration of 'Folder'
e:\platsdk\cdontstest\cdonts.tli(470) : error C2065: 'get_Application' : undeclared identifier
e:\platsdk\cdontstest\cdonts.tli(471) : error C2673: 'GetApplication' : global functions do not have 'this' pointers
e:\platsdk\cdontstest\cdonts.tli(471) : error C2673: 'GetApplication' : global functions do not have 'this' pointers
e:\platsdk\cdontstest\cdonts.tli(475) : error C2039: 'GetParent' : is not a member of 'Folder'
        e:\program files\microsoft visual studio\vc98\include\exdisp.h(4584) : see declaration of 'Folder'
e:\platsdk\cdontstest\cdonts.tli(478) : error C2065: 'get_Parent' : undeclared identifier
e:\platsdk\cdontstest\cdonts.tli(479) : error C2673: 'GetParent' : global functions do not have 'this' pointers
e:\platsdk\cdontstest\cdonts.tli(479) : error C2673: 'GetParent' : global functions do not have 'this' pointers
e:\platsdk\cdontstest\cdonts.tli(483) : error C2039: 'GetSession' : is not a member of 'Folder'
        e:\program files\microsoft visual studio\vc98\include\exdisp.h(4584) : see declaration of 'Folder'
e:\platsdk\cdontstest\cdonts.tli(486) : error C2065: 'get_Session' : undeclared identifier
e:\platsdk\cdontstest\cdonts.tli(487) : error C2673: 'GetSession' : global functions do not have 'this' pointers
e:\platsdk\cdontstest\cdonts.tli(487) : error C2673: 'GetSession' : global functions do not have 'this' pointers
e:\platsdk\cdontstest\cdonts.tli(491) : error C2039: 'GetClass' : is not a member of 'Folder'
        e:\program files\microsoft visual studio\vc98\include\exdisp.h(4584) : see declaration of 'Folder'
e:\platsdk\cdontstest\cdonts.tli(493) : error C2065: 'get_Class' : undeclared identifier
e:\platsdk\cdontstest\cdonts.tli(494) : error C2673: 'GetClass' : global functions do not have 'this' pointers
e:\platsdk\cdontstest\cdonts.tli(494) : error C2673: 'GetClass' : global functions do not have 'this' pointers
e:\platsdk\cdontstest\cdonts.tli(498) : error C2039: 'GetName' : is not a member of 'Folder'
        e:\program files\microsoft visual studio\vc98\include\exdisp.h(4584) : see declaration of 'Folder'
e:\platsdk\cdontstest\cdonts.tli(500) : error C2065: 'get_Name' : undeclared identifier
e:\platsdk\cdontstest\cdonts.tli(501) : error C2673: 'GetName' : global functions do not have 'this' pointers
e:\platsdk\cdontstest\cdonts.tli(501) : error C2673: 'GetName' : global functions do not have 'this' pointers
e:\platsdk\cdontstest\cdonts.tli(505) : error C2039: 'GetMessages' : is not a member of 'Folder'
        e:\program files\microsoft visual studio\vc98\include\exdisp.h(4584) : see declaration of 'Folder'
e:\platsdk\cdontstest\cdonts.tli(508) : error C2065: 'get_Messages' : undeclared identifier
e:\platsdk\cdontstest\cdonts.tli(509) : error C2673: 'GetMessages' : global functions do not have 'this' pointers
e:\platsdk\cdontstest\cdonts.tli(509) : error C2673: 'GetMessages' : global functions do not have 'this' pointers
Error executing cl.exe.

cdontstest.exe - 26 error(s), 0 warning(s)

The CDONTS.dll is registered successfully.
I hope now u will be able to help me better.
0
 
ShaunWildeCommented:
I don't have NT2000 to test what will happen but I suspect you will have to fiddle with the options to your #import statement

1) remove the no_namespace and named_guids options and see what happens.

2) you can 'exclude' problematic functions and methods and others with name clashes can be renamed.

HTH
0
 
arpit080399Author Commented:
// cdontstest.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "cdontstest.h"
#include "CDONTS.h"

#import "e:\winnt\system32\cdonts.dll"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// The one and only application object

CWinApp theApp;

using namespace std;

int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
      int nRetCode = 0;

      // initialize MFC and print and error on failure
      if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
      {
            // TODO: change error code to suit your needs
            cerr << _T("Fatal Error: MFC initialization failed") << endl;
            nRetCode = 1;
      }
      else
      {
OleInitialize(NULL);
HRESULT hr =
 INewMailPtr pNewMail ("CDONTS.NewMail.1");
if(SUCCEEDED(hr))
{
printf("Created NewMail Object.......\n");
}
OleUninitialize();
}

return nRetCode;
}


E:\platsdk\cdontstest\cdontstest.cpp(45) : error C2065: 'INewMailPtr' : undeclared identifier
E:\platsdk\cdontstest\cdontstest.cpp(45) : error C2146: syntax error : missing ';' before identifier 'pNewMail'
E:\platsdk\cdontstest\cdontstest.cpp(45) : error C2065: 'pNewMail' : undeclared identifier
Error executing cl.exe.

cdontstest.obj - 3 error(s), 0 warning(s)

I AM USING NT-SERVER4.0 WITH IIS4.0 alongwith it this CDONTS.dll also gets installed.
0
 
ShaunWildeCommented:
Okay I think we are there now - all you have to do is look in the .tlh /.tli file and see what the namespace is and then in your header file type
 
using namespace XXXX;

where XXXX is the namespace in your header file

or you can

type

XXXX::INewMailPtr pNewMail("CDONTS.NewMail.1");
0
 
arpit080399Author Commented:
Sorry man
there is no entry at all for namespace in my .tli or .tlh files
Please suggest some other method
0
 
arpit080399Author Commented:
shaun Actually your proposed answer was right so I am accepting your comment as answer
0
 
arpit080399Author Commented:
Actually I was referring to the old .tlh file
0
 
ShaunWildeCommented:
ah - glad to help
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.