dchell
asked on
CDO using Borland C++ Builder 5
I'm trying to write a simple routine to send emails using CDO and Borland C++ Builder 5 on a Win2k machine.
The MSDN Example listed below (listing1) doesn't work with BCB. It sometimes gets and internal compiler error and finds duplicate declarations. The BCB help says that using the #import is not a recommended method and that I should use the "Import type library" menu option instead. I tried that approach also and what I have now is listing 2:
It compiles and runs Ok, but nothing is sent or received. If I use :
fld = Flds->get_Item(cdoURLProxy Server);
fld->set_Value(TVariantInP aram("Serv er:8080")) ;
fld->Release();
instead of :
Flds->get_Item(cdoURLProxy Server)->s et_Value(T VariantInP aram("Serv er:8080")) ;
fld->Release();
then I get and AV on the fld->set_Value line.
There's to be no Flds->Update() method.
and the Stm->SaveToFile(... line also causes and AV.
Any help would be appreciated.
Listing 1: MSDN Example;
========================
#import "d:\program files\common files\system\ado\msado15.d ll" no_namespace
#import <cdosys.dll> no_namespace
#include <iostream.h>
void main()
{
CoInitialize();
{
IMessagePtr iMsg(__uuidof(Message));
IBodyPartPtr iBp;
IBodyPartsPtr iBps;
_StreamPtr Stm;
_bstr_t filepath;
IConfigurationPtr iConf(__uuidof(Configurati on));
FieldsPtr Flds;
Flds = iConf->Fields;
Flds->Item[cdoSendUsingMet hod]->Valu e =
_variant_t(cdoSendUsingPor t);
Flds->Item[cdoSMTPServerNa me]->Value =
_variant_t("somehost@micro soft.com") ;
Flds->Item[cdoSMTPConnecti onTimeout] ->Value = _variant_t((long)10);
Flds->Item[cdoSMTPAuthenti cate]->Val ue = _variant_t(cdoBasic);
Flds->Item[cdoSendUserName ]->Value = _variant_t("username");
Flds->Item[cdoSendPassword ]->Value = _variant_t("password");
Flds->Item[cdoURLProxyServ er]->Value = _variant_t("server:80");
Flds->Item[cdoURLProxyBypa ss]->Value = _variant_t("<local>");
Flds->Item[cdoURLGetLatest Version]-> Value =
_variant_t(VARIANT_TRUE);
Flds->Update();
iMsg->To = "\"SomeOne\" <someone@fake.microsoft.co m>";
iMsg->From = "\"Another\" <another@fake.microsoft.co m>";
iMsg->Subject = "Here is a subject for the message.";
/*
** attach an html file to message
** your local path goes in the "path"
** variable below
*/
try
{
filepath = _bstr_t(path) + _bstr_t("\\htmlfile.html") ;
iMsg->AddAttachment(filepa th,"","");
}
catch (_com_error e)
{
//...
}
/*
** Attach Word 2000 file to message
*/
try {
filepath = _bstr_t(path) + _bstr_t("\\wordfile.doc");
iMsg->AddAttachment(filepa th,"","");
}
catch (_com_error e)
{
//...
}
/*
** Create MTHML body.
*/
try
{
iMsg->CreateMHTMLBody(
"http://mypage",
cdoSuppressAll,
"",
"");
}
catch (_com_error e)
{
//...
}
iMsg->Send();
// save message
Stm = iMsg->GetStream();
Stm->SaveToFile(_bstr_t("m essage.eml "),adSaveC reateOverW rite);
}
CoUninitialize();
}
Listing 2:
============
#pragma hdrstop
#include <cdo_tlb.h>
#include <cdosysstr.h>
#include "cdosys_i.c"
extern "C" int TestMessage()
{
TCOMIMessage iMsg;
TCOMIConfiguration iConf;
IBodyPart *iBp;
IBodyParts *iBps;
_Stream *Stm;
int rcode;
HRESULT hr;
TInitOle tInit;
/*
** Create an instance of the Message and configuration COM class.
*/
iMsg = CoMessage::Create();
iConf = CoConfiguration::Create();
Fields *Flds;
Flds = iConf->get_Fields();
Field *fld;
fld = Flds->get_Item(cdoSendUsin gMethod);
fld->set_Value(TVariantInP aram((shor t)cdoSendU singPort)) ;
fld->Release();
fld = Flds->get_Item(cdoSMTPServ er);
fld->set_Value(TVariantInP aram("192. 168.0.1")) ;
fld->Release();
fld = Flds->get_Item(cdoSMTPServ erPort);
fld->set_Value(TVariantInP aram((long )25));
fld->Release();
fld = Flds->get_Item(cdoSMTPConn ectionTime out);
fld->set_Value(TVariantInP aram((long )10));
fld->Release();
Flds->get_Item(cdoSMTPAuth enticate)- >set_Value (TVariantI nParam(cdo Basic));
// fld->Release();
fld = Flds->get_Item(cdoSendUser Name);
fld->set_Value(TVariantInP aram("soft lif2"));
fld->Release();
fld = Flds->get_Item(cdoSendPass word);
fld->set_Value(TVariantInP aram("j3ra boam"));
fld->Release();
Flds->get_Item(cdoURLProxy Server)->s et_Value(T VariantInP aram("Stan :3128"));
// fld->Release();
Flds->get_Item(cdoURLProxy Bypass)->s et_Value(T VariantInP aram("<loc al>"));
// fld->Release();
Flds->get_Item(cdoURLGetLa testVersio n)->set_Va lue(TVaria ntInParam( VARIANT_TR UE));
// fld->Release();
// Flds->Update();
Flds->Release();
iMsg->set_Configuration(iC onf);
wchar_t from[] = L"\"Someone\" <someone@somewhere.co.nz>" ;
iMsg->set_To(from);
iMsg->set_From(L"\"Another \" <someone@somewhere.co.nz>" );
iMsg->set_Subject(L"Here is a subject for the message.");
/*
** attach an html file to message
** your local path goes in the "path"
** variable below
*/
if (iMsg->Send() != S_OK)
rcode = R_ERROR;
// save message
Stm = iMsg->GetStream();
Stm->SaveToFile(L"e:\\temp \\message. eml",adSav eCreateOve rWrite);
Stm->Release();
iMsg->Release();
iConf->Release();
return(rcode);
The MSDN Example listed below (listing1) doesn't work with BCB. It sometimes gets and internal compiler error and finds duplicate declarations. The BCB help says that using the #import is not a recommended method and that I should use the "Import type library" menu option instead. I tried that approach also and what I have now is listing 2:
It compiles and runs Ok, but nothing is sent or received. If I use :
fld = Flds->get_Item(cdoURLProxy
fld->set_Value(TVariantInP
fld->Release();
instead of :
Flds->get_Item(cdoURLProxy
fld->Release();
then I get and AV on the fld->set_Value line.
There's to be no Flds->Update() method.
and the Stm->SaveToFile(... line also causes and AV.
Any help would be appreciated.
Listing 1: MSDN Example;
========================
#import "d:\program files\common files\system\ado\msado15.d
#import <cdosys.dll> no_namespace
#include <iostream.h>
void main()
{
CoInitialize();
{
IMessagePtr iMsg(__uuidof(Message));
IBodyPartPtr iBp;
IBodyPartsPtr iBps;
_StreamPtr Stm;
_bstr_t filepath;
IConfigurationPtr iConf(__uuidof(Configurati
FieldsPtr Flds;
Flds = iConf->Fields;
Flds->Item[cdoSendUsingMet
_variant_t(cdoSendUsingPor
Flds->Item[cdoSMTPServerNa
_variant_t("somehost@micro
Flds->Item[cdoSMTPConnecti
Flds->Item[cdoSMTPAuthenti
Flds->Item[cdoSendUserName
Flds->Item[cdoSendPassword
Flds->Item[cdoURLProxyServ
Flds->Item[cdoURLProxyBypa
Flds->Item[cdoURLGetLatest
_variant_t(VARIANT_TRUE);
Flds->Update();
iMsg->To = "\"SomeOne\" <someone@fake.microsoft.co
iMsg->From = "\"Another\" <another@fake.microsoft.co
iMsg->Subject = "Here is a subject for the message.";
/*
** attach an html file to message
** your local path goes in the "path"
** variable below
*/
try
{
filepath = _bstr_t(path) + _bstr_t("\\htmlfile.html")
iMsg->AddAttachment(filepa
}
catch (_com_error e)
{
//...
}
/*
** Attach Word 2000 file to message
*/
try {
filepath = _bstr_t(path) + _bstr_t("\\wordfile.doc");
iMsg->AddAttachment(filepa
}
catch (_com_error e)
{
//...
}
/*
** Create MTHML body.
*/
try
{
iMsg->CreateMHTMLBody(
"http://mypage",
cdoSuppressAll,
"",
"");
}
catch (_com_error e)
{
//...
}
iMsg->Send();
// save message
Stm = iMsg->GetStream();
Stm->SaveToFile(_bstr_t("m
}
CoUninitialize();
}
Listing 2:
============
#pragma hdrstop
#include <cdo_tlb.h>
#include <cdosysstr.h>
#include "cdosys_i.c"
extern "C" int TestMessage()
{
TCOMIMessage iMsg;
TCOMIConfiguration iConf;
IBodyPart *iBp;
IBodyParts *iBps;
_Stream *Stm;
int rcode;
HRESULT hr;
TInitOle tInit;
/*
** Create an instance of the Message and configuration COM class.
*/
iMsg = CoMessage::Create();
iConf = CoConfiguration::Create();
Fields *Flds;
Flds = iConf->get_Fields();
Field *fld;
fld = Flds->get_Item(cdoSendUsin
fld->set_Value(TVariantInP
fld->Release();
fld = Flds->get_Item(cdoSMTPServ
fld->set_Value(TVariantInP
fld->Release();
fld = Flds->get_Item(cdoSMTPServ
fld->set_Value(TVariantInP
fld->Release();
fld = Flds->get_Item(cdoSMTPConn
fld->set_Value(TVariantInP
fld->Release();
Flds->get_Item(cdoSMTPAuth
// fld->Release();
fld = Flds->get_Item(cdoSendUser
fld->set_Value(TVariantInP
fld->Release();
fld = Flds->get_Item(cdoSendPass
fld->set_Value(TVariantInP
fld->Release();
Flds->get_Item(cdoURLProxy
// fld->Release();
Flds->get_Item(cdoURLProxy
// fld->Release();
Flds->get_Item(cdoURLGetLa
// fld->Release();
// Flds->Update();
Flds->Release();
iMsg->set_Configuration(iC
wchar_t from[] = L"\"Someone\" <someone@somewhere.co.nz>"
iMsg->set_To(from);
iMsg->set_From(L"\"Another
iMsg->set_Subject(L"Here is a subject for the message.");
/*
** attach an html file to message
** your local path goes in the "path"
** variable below
*/
if (iMsg->Send() != S_OK)
rcode = R_ERROR;
// save message
Stm = iMsg->GetStream();
Stm->SaveToFile(L"e:\\temp
Stm->Release();
iMsg->Release();
iConf->Release();
return(rcode);
ASKER
Thanks, That's solved the Internal Compiler error problems, now I get:
MSADO15.LH(844) Unrecognized __declspec modifier
MSADO15.TLH(844) Declaration does not specifiy a tag or an identifier
MSADO15.TLH(840) 'GetRow' is not a member of 'ADORecordConstruction'
MSADO15.LH(844) Unrecognized __declspec modifier
MSADO15.TLH(844) Declaration does not specifiy a tag or an identifier
MSADO15.TLH(840) 'GetRow' is not a member of 'ADORecordConstruction'
ASKER
Don't panic, I've fixed that one - the following line was missing two close brackets/
Which line was that? I have no problem compiling that file with VC++
-- Dan
-- Dan
ASKER
Now it compiles fine but I have the following 3 unresolved externals at link time:
__stdcall_com_issue_error( long)
_com_dispatch_method(IDisp atch *, long, unsigned short, unsigned short, void *, const wchar_t *, ...)
_stdcall_com_util::Convert StringToBS TR(const char *)
MSDN says that _com_dispatch_method is an undocumented runtime library function. It's obviously not in BCB's runtime library - I've searched all files on my disk for _com_dispatch_method - nothing.
__stdcall_com_issue_error(
_com_dispatch_method(IDisp
_stdcall_com_util::Convert
MSDN says that _com_dispatch_method is an undocumented runtime library function. It's obviously not in BCB's runtime library - I've searched all files on my disk for _com_dispatch_method - nothing.
According to the MSDN article:
PRB: Use IDispatch for Objects Created by a DataSpace Object
it should be easy to create a replacement for that function. I don't have the code.
Do you have a file named COMSUPP.LIB ? that seems to provide the code for a number of these utility fns.
-- Dan
PRB: Use IDispatch for Objects Created by a DataSpace Object
it should be easy to create a replacement for that function. I don't have the code.
Do you have a file named COMSUPP.LIB ? that seems to provide the code for a number of these utility fns.
-- Dan
ASKER
I didn't have a comsupp.lib, so I hunted around and found one - but BCB doesn't like the format of it. I get a linker error: COMSUPP.LIB contains and invalid OMF record, type 0x21 (possible COFF).
The problem is that there's 111 calls to _com_dispatch_method in the automatically generated cdosys.tli file and then there's _stdcall_com_issue_error and ConvertStringToBSTR to replace.
The problem is that there's 111 calls to _com_dispatch_method in the automatically generated cdosys.tli file and then there's _stdcall_com_issue_error and ConvertStringToBSTR to replace.
If you can get the comsupp.dll, you can use the borland tools to generate a .LIB file for it.
-- Dan
-- Dan
ASKER
Yep, I'd thought of that too, but it's not an import library - it's part of the VC static runtime library.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Well I started off using MAPI and Extended MAPI but I have a problem with the MAPI Spooler hanging - see https://www.experts-exchange.com/questions/20513569/MAPI-Spooler-hangs-while-submitting-email-using-Extended-MAPI.html
In my travels through MSDN I spotted CDO as a possibility and thought I'd give it a try.
I do have another option - and that is to install Visual Studio (I have it on CD) and compile just the CDO module with that - but I'm a bit short of disk space (need to clean out some games). It's not a favoured option as it makes debugging somewhat tiresome. I've also left a message on the Borland newsgroups and am waiting for a response.
In my travels through MSDN I spotted CDO as a possibility and thought I'd give it a try.
I do have another option - and that is to install Visual Studio (I have it on CD) and compile just the CDO module with that - but I'm a bit short of disk space (need to clean out some games). It's not a favoured option as it makes debugging somewhat tiresome. I've also left a message on the Borland newsgroups and am waiting for a response.
Compile once. The #import will generate a .H files like,
d:\myproj\test\debug\cdosy
and
d:\myproj\test\debug\msado
At that point, comment out the #import lines and add these lines:
#include "d:\myproj\test\debug\cdos
#include "d:\myproj\test\debug\msad
But you should also check into the files that you are #import-ing. DO a full-disk search for msado15.dll and cdosys.dll and make sure that you are importing the right files. You must import the same dll that will be loaded when you instantiate the object and if there are two or more copies of the a DLL then that becomes a bit iffy.
-- Dan