Click here to Skip to main content
15,891,677 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralHelp required !! Pin
Stephan Poirier10-Feb-03 18:32
Stephan Poirier10-Feb-03 18:32 
GeneralCreateDialog failure Pin
Anonymous10-Feb-03 17:07
Anonymous10-Feb-03 17:07 
GeneralI want to Create a Process with CreateProcessAsUser from as PrintMonitor running under the System Account Pin
Karl Bauer10-Feb-03 16:14
Karl Bauer10-Feb-03 16:14 
QuestionDetecting first run ? Pin
autekre10-Feb-03 15:57
autekre10-Feb-03 15:57 
AnswerRe: Detecting first run ? Pin
ColinDavies10-Feb-03 17:56
ColinDavies10-Feb-03 17:56 
GeneralReplacing the MFC WinMain. Pin
Daeriel10-Feb-03 14:22
Daeriel10-Feb-03 14:22 
GeneralRe: Replacing the MFC WinMain. Pin
Alvaro Mendez11-Feb-03 5:36
Alvaro Mendez11-Feb-03 5:36 
GeneralRe: Replacing the MFC WinMain. Pin
Daeriel11-Feb-03 12:07
Daeriel11-Feb-03 12:07 
Thank you Alvaro!

I've changed the type of linked application and included the _tmain() function and MFC initialization code from MFC library. It looks like this: <see below="">

Application starts normally, but it throws the access violation exception while destroying the application document. Wonder why.

Anyway I'll try to change the entry point from linker options.

TServiceApp Service(ServiceStart, ServiceStop); // application service object

int _tmain(int argc, const TCHAR* argv[], TCHAR* envp[])
{
int RetCode = 1;
// if(AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
{
Service.ServiceName = NETACCESS_SERVICENAME;
Service.DisplayName = NETACCESS_DISPLAYNAME;
Service.Initialize(argc, argv);
RetCode = Service.Status.ExitCode;
}
// else
// WriteServiceLog(_T("Fatal Error: MFC initialization failed.\n"));
return RetCode;
}


DWORD __fastcall ServiceStart(DWORD Count, LPTSTR *lpszArgv)
{
Service.Status.Report(SERVICE_START_PENDING); // 3000

STARTUPINFO StartupInfo;
StartupInfo.dwFlags = 0;
GetStartupInfo(&StartupInfo);
HINSTANCE hInstance = GetModuleHandle(NULL);
HINSTANCE hPrevInstance = NULL;
LPTSTR lpCmdLine = GetCommandLine();
int nCmdShow = SW_SHOWDEFAULT;
if(StartupInfo.dwFlags & STARTF_USESHOWWINDOW)
nCmdShow = StartupInfo.wShowWindow;

Service.Status.ExitCode = -1;
CWinThread* pThread = AfxGetThread();
CWinApp* pApp = AfxGetApp();

// AFX internal initialization
if (!AfxWinInit(hInstance, hPrevInstance, lpCmdLine, nCmdShow))
goto InitFailure;

// App global initializations (rare)
if(pApp != NULL && !pApp->InitApplication())
goto InitFailure;

// Perform specific initializations
if(!pThread->InitInstance())
{
if (pThread->m_pMainWnd != NULL)
{
TRACE(traceAppMsg, 0, "Warning: Destroying non-NULL m_pMainWnd\n");
pThread->m_pMainWnd->DestroyWindow();
}
Service.Status.ExitCode = pThread->ExitInstance();
goto InitFailure;
}

Service.Status.Report(SERVICE_RUNNING); // 0
Service.Status.ExitCode = pThread->Run();

InitFailure:
#ifdef _DEBUG
// Check for missing AfxLockTempMap calls
if (AfxGetModuleThreadState()->m_nTempMapLock != 0)
{
TRACE(traceAppMsg, 0, "Warning: Temp map lock count non-zero (%ld).\n",
AfxGetModuleThreadState()->m_nTempMapLock);
}
AfxLockTempMaps();
AfxUnlockTempMaps(-1);
#endif

AfxWinTerm();
return Service.Status.ExitCode;
}

VOID __stdcall TServiceApp::Initialize(DWORD Count, LPCTSTR *Args)
{
if(mServiceStart && mServiceStop)
{
SERVICE_TABLE_ENTRY DispatchTable[] =
{
{ mServiceName, TServiceApp::ServiceMain },
{ NULL, NULL }
};

if(Count > 1 && (*Args[1] == '-' || *Args[1] == '/'))
{
TCoreService Service;
TServiceManager Manager;
Service.Name = mServiceName;
Service.DisplayName = mDisplayName;
Service.Dependencies = mDependencies;
if(_stricmp(_T("install"), Args[1] + 1) == 0)
{
Manager.Install(&Service);
Service.__Start(Count, Args);
}
else
if(_stricmp(_T("remove"), Args[1] + 1) == 0)
Manager.Remove(&Service);
else
if(_stricmp(_T("debug"), Args[1] + 1) == 0)
{
TServiceHandle::sDebug = TRUE;
WriteServiceLog(_T("Debugging %s.\n"), mDisplayName);
SetConsoleCtrlHandler(ControlHandler, TRUE);
if(mServiceStart)
mServiceStart(Count, (LPTSTR*)Args);
}
else
goto Dispatch;
}
else
Dispatch:
if(!TCoreService::__StartCtrlDispatcher(DispatchTable))
WriteMessage(_T("Initialize: Failed to start service control dispatcher."));
}
else
WriteServiceLog(_T("Initialize: Start and stop routines must be specified.\n"));
}


/regards/
GeneralExe size Pin
User 988510-Feb-03 12:17
User 988510-Feb-03 12:17 
GeneralRe: Exe size Pin
Chris Losinger10-Feb-03 13:22
professionalChris Losinger10-Feb-03 13:22 
GeneralRe: Exe size Pin
User 988511-Feb-03 13:46
User 988511-Feb-03 13:46 
GeneralRe: Exe size Pin
Chris Losinger11-Feb-03 14:19
professionalChris Losinger11-Feb-03 14:19 
GeneralRe: Exe size Pin
Mike Nordell10-Feb-03 14:58
Mike Nordell10-Feb-03 14:58 
GeneralRe: Exe size Pin
Neville Franks10-Feb-03 23:53
Neville Franks10-Feb-03 23:53 
QuestionCan someone give me examples of using these SQL statements?? Pin
IrishSonic10-Feb-03 12:04
IrishSonic10-Feb-03 12:04 
AnswerRe: Can someone give me examples of using these SQL statements?? Pin
xxhimanshu10-Feb-03 17:35
xxhimanshu10-Feb-03 17:35 
GeneralUsing askey in a file Pin
proprogram10-Feb-03 12:01
sussproprogram10-Feb-03 12:01 
GeneralRe: Using askey in a file Pin
Mike Nordell10-Feb-03 12:29
Mike Nordell10-Feb-03 12:29 
GeneralAccessing data/file when app launched from attachment Pin
Dr Soong10-Feb-03 11:43
Dr Soong10-Feb-03 11:43 
GeneralRe: Accessing data/file when app launched from attachment Pin
JoeSox10-Feb-03 12:09
JoeSox10-Feb-03 12:09 
GeneralRe: Accessing data/file when app launched from attachment Pin
Mike Nordell10-Feb-03 15:08
Mike Nordell10-Feb-03 15:08 
QuestionHow to get my DNS server ? Pin
Yasen Georgiew10-Feb-03 11:05
Yasen Georgiew10-Feb-03 11:05 
AnswerRe: How to get my DNS server ? Pin
Rene De La Garza10-Feb-03 11:37
Rene De La Garza10-Feb-03 11:37 
GeneralNT Service would not start...! Pin
Prabhakar10-Feb-03 10:57
Prabhakar10-Feb-03 10:57 
GeneralRe: NT Service would not start...! Pin
palbano10-Feb-03 11:06
palbano10-Feb-03 11:06 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.