But I'm not trying to run it in DOS mode!

  • Thread starter Thread starter John
  • Start date Start date
J

John

Greetings,

I am running XP Professional.

I have an exe file written in VC++. When I try to run it it flashes a
command window at me and shuts down. I created a shortcut for it so I
could set it not to close the window right away and I see the message:
"This program cannot be run in DOS mode".

I did some reading on it (every message I could find about that
message on the newsgroups and the web). I tried starting up the
command window first (cmd.exe) and navigating to that directory and
running it that way and I got the same error.

I don't need it to run in DOS mode. There is no GUI front end on it,
but I'm perfectly fine with it being a 32 bit Windows app. Can
somebody point me in the right direction here?
 
John said:
Greetings,

I am running XP Professional.

I have an exe file written in VC++. When I try to run it it flashes a
command window at me and shuts down. I created a shortcut for it so I
could set it not to close the window right away and I see the message:
"This program cannot be run in DOS mode".

I did some reading on it (every message I could find about that
message on the newsgroups and the web). I tried starting up the
command window first (cmd.exe) and navigating to that directory and
running it that way and I got the same error.

I don't need it to run in DOS mode. There is no GUI front end on it,
but I'm perfectly fine with it being a 32 bit Windows app. Can
somebody point me in the right direction here?

Do you want a persistent console window or no window at all? If the latter,
start over as a Win32 app instead of a console app. Just do what needs doing
and don't create any windows. If the former, I'm sure it's easy but I don't
know.
 
Jeff,

Thanks for the suggestion. I tried that. Here's what happened:

I got the error: unresolved external symbol _WinMain@16

Then I added mainCRTStartup as the entry point symbol in my Projects
Settings => Links => Output and I'm back where I started (Dos mode
error).

I guess the program needs to be run in a console window, as it's
written to supply output to the screen. Any attempt to do so results
in confusion on the part of Windows as to whether it's an MS-DOS
program or a Win32 program.

BTW I am using VC++ 5.0.
 
Jeff (or anyone of course),

Maybe it would help if I posted my code.

The basic idea is to be able to create an appointment in Outlook (or
Exchange).

My boss's boss (i.e. the owner) has already told sales that we will
have this capability, so there are a number of people looking over my
shoulder here (although unobtrusively). I'm obviously not a C++
programmer by trade, and I actually don't need the program to be in
C++, but we don't have VB or DS.NET (yet) and I just need a working
prototype to wow the prospects for now. I got this code off the
internet.

Here are my questions, if anybody can help me out:

How can I get this program to compile and run?
How can I provide output (to a file would be fine)?
Should I be running this on the client or the server?

Here is my code:


// class1.cpp: implementation of the class1 class.
//
//////////////////////////////////////////////////////////////////////
#include <iads.h>
#include <adshlp.h>
#include <activeds.h>
#include <stdio.h>
#include <tchar.h>
#import <msado15.dll> no_namespace raw_interfaces_only
#import <cdoex.dll> rename_namespace("CDO") raw_interfaces_only
#import <cdosys.dll> no_namespace raw_interfaces_only
#include "class1.h"
#include <cdosysstr.h>
#include <cdosyserr.h>
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
enum CdoFrequency
{
cdoSecondly = 1,
cdoMinutely = 2,
cdoHourly = 3,
cdoDaily = 4,
cdoWeekly = 5,
cdoMonthly = 6,
cdoYearly = 7,
};
enum CdoAttendeeRoleValues
{
cdoRequiredParticipant = 0,
cdoOptionalParticipant = 1,
cdoNonParticipant = 2,
cdoChair = 3
};
HRESULT GetDomainName(BSTR * bstrDomainName);
HRESULT SendMeetingRequest(BSTR bstrDomainName, BSTR bstrUser, BSTR
bstrRecipient);

struct StartOle {
StartOle() { CoInitialize(NULL); }
~StartOle() { CoUninitialize(); }
} _inst_StartOle;


//}

//class1::~class1()
//{
void main()
{
HRESULT hr = S_OK;
//
BSTR bstrDomainDNSName;
// Get Domain Name
hr = GetDomainName(&bstrDomainDNSName);

//printf("1");

// Create and send a recurring meeting request to a user
// TODO: change the second parameter to your mailbox name (meeting
organizer)
// TODO: change the third parameter to the recipient's e-mail address
or mailbox name
hr = SendMeetingRequest(bstrDomainDNSName, L"JohnS", L"JohnD");
}

//////////////////////////////////////////////////////////////////////////////////////////////////
// SendMeetingRequest
//
// Params: [in] BSTR bstrDomainName Domain DNS Name
// [in] BSTR bstrUser Meeting organizer's mailbox name
// [in] BSTR bstrRecipient Recipient's mailbox name
//
// Output: HRESULT
// Purpose: To demonstrate; 1.How to create a recurring appointment
// 2.How to add an exception to a recurring appointment
// 3.How to create a meeting request and send it
/////////////////////////////////////////////////////////////////////////////////////////////////
HRESULT SendMeetingRequest(BSTR bstrDomainName, BSTR bstrUser, BSTR
bstrRecipient)
{
HRESULT hr = S_OK;

_bstr_t szCalendarURL ="file://./backofficestorage/" +
(_bstr_t)bstrDomainName + "/MBX/" + (_bstr_t)bstrUser + "/Calendar";

try{
CDO::IMessagePtr pMsg(_uuidof(CDO::Message));
CDO::IAppointmentPtr pAppt(_uuidof(CDO::Appointment));
CDO::IRecurrencePatternsPtr pRecPatterns;
CDO::IRecurrencePatternPtr pRecPattern;
CDO::IDataSourcePtr pDataSrc;
CDO::IAttendeesPtr pAttendees;
CDO::IAttendeePtr pAttendee;
CDO::IExceptionsPtr pExceptions;
CDO::IExceptionPtr pException;
CDO::ICalendarMessagePtr pCalendarMessage;

SYSTEMTIME st = {0};
SYSTEMTIME et = {0};

DATE dst, det;

// Specify the StartTime and EndTime values.
st.wYear = 2000;
st.wMonth = 2;
st.wDay = 1;
st.wHour = 13;
st.wMinute = 30;
et.wYear = 2000;
et.wMonth = 2;
et.wDay = 1;
et.wHour = 16;
et.wMinute = 30;

// Convert System value to double DATE
SystemTimeToVariantTime(&st, &dst);
SystemTimeToVariantTime(&et, &det);
// Set Appointment's properties.
pAppt->put_Subject(L"Exchange Server 2000 Training.");
pAppt->put_Location(L"Conference Room 444");
pAppt->put_TextBody(L"Please bring the course notes.");
pAppt->put_StartTime(dst);
pAppt->put_EndTime(det);

// Invite an Attendee.
pAppt->get_Attendees(&pAttendees);
pAttendees->Add(bstrRecipient, &pAttendee);
pAttendee->put_Role((enum
CDO::CdoAttendeeRoleValues)cdoRequiredParticipant);

// Create a Recurrence Pattern.
// Set the RecurrencePattern properties to make the Appointment a
bi-weekly Appointment.
pAppt->get_RecurrencePatterns(&pRecPatterns);
pRecPatterns->Add(L"ADD", &pRecPattern);
pRecPattern->put_Frequency((enum CDO::CdoFrequency)cdoWeekly);
pRecPattern->put_Interval(2); // every 2 weeks
pRecPattern->put_Instances(5); // end after 5 instances

// Create an Exception to the Appointment.
pAppt->get_Exceptions(&pExceptions);

// Delete the second instance from the series.
pExceptions->Add(L"DELETE", &pException);

// Specify the start time of the second Appointment in the series.
st.wYear = 2000;
st.wMonth = 2;
st.wDay = 15;
st.wHour = 13;
st.wMinute = 30;

SystemTimeToVariantTime(&st, &dst);

// dst is the StartTime of the second instance
pException->put_RecurrenceID(dst);

// Create a CalendarMessage
pAppt->CreateRequest(&pCalendarMessage);
pCalendarMessage->get_Message(&pMsg);

// Get the data source to save the Meeting into organizer's calendar.
pAppt->get_DataSource(&pDataSrc);

// Send the Meeting Request
hr = pMsg->Send();
if (SUCCEEDED(hr))
//_tprintf(_T("Recurring meeting request is sent.\n"));

// Optional : You can save the meeting into organizer's calendar.
hr = pDataSrc->SaveToContainer(szCalendarURL,
0,
adModeReadWrite,
adCreateOverwrite,
adOpenSource,
L"",
L"");
//if (SUCCEEDED(hr))
//_tprintf(_T("The meeting is saved to the organizer's calendar.\n"));


}
catch(_com_error &e)
{

//printf("HResult = %x\n", e.Error());
//printf("%S\n", e.Description());

}
return hr;

}

//////////////////////////////////////////////////////////////////////////////////////////////////
// GetDomainName
//
// Params: [out] BSTR * bstrDomainName
// Output: HRESULT
// Purpose: Retrieve the Domain DNS name.
/////////////////////////////////////////////////////////////////////////////////////////////////
HRESULT GetDomainName(BSTR * bstrDomainName)
{
HRESULT hr = S_OK;
IADsADSystemInfo *pADsys;
hr = CoCreateInstance(CLSID_ADSystemInfo,
NULL,
CLSCTX_INPROC_SERVER,
IID_IADsADSystemInfo,
(void**)&pADsys);
hr = pADsys->get_DomainDNSName(bstrDomainName);

if (pADsys)
pADsys->Release();
return hr;
}
 
Back
Top