Solved

Can we use COM and MFC simultaneously

Posted on 2000-02-23
12
617 Views
Last Modified: 2013-11-25
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.
0
Comment
Question by:arpit080399
  • 6
  • 5
12 Comments
 

Author Comment

by:arpit080399
ID: 2550613
Also it is possible to use CDOSYS to send emails but it works only on Windows 2000.
0
 
LVL 9

Expert Comment

by:ShaunWilde
ID: 2551249
can you paste in the exact error you get from the compiler?
0
 
LVL 32

Expert Comment

by:jhance
ID: 2551611
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
 

Author Comment

by:arpit080399
ID: 2553354
#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
 
LVL 9

Expert Comment

by:ShaunWilde
ID: 2553627
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
 

Author Comment

by:arpit080399
ID: 2553839
// 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 9

Expert Comment

by:ShaunWilde
ID: 2553961
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
 

Author Comment

by:arpit080399
ID: 2554105
Sorry man
there is no entry at all for namespace in my .tli or .tlh files
Please suggest some other method
0
 
LVL 9

Accepted Solution

by:
ShaunWilde earned 100 total points
ID: 2554646
okay can you post your .tlh and .tli files ?
0
 

Author Comment

by:arpit080399
ID: 2554756
shaun Actually your proposed answer was right so I am accepting your comment as answer
0
 

Author Comment

by:arpit080399
ID: 2554765
Actually I was referring to the old .tlh file
0
 
LVL 9

Expert Comment

by:ShaunWilde
ID: 2555330
ah - glad to help
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

707 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now