Click here to Skip to main content
16,004,806 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionDialog based application with background Pin
Rostfrei6-Apr-06 6:31
Rostfrei6-Apr-06 6:31 
AnswerRe: Dialog based application with background Pin
Hamid_RT6-Apr-06 6:45
Hamid_RT6-Apr-06 6:45 
AnswerRe: Dialog based application with background Pin
Hamid_RT6-Apr-06 6:52
Hamid_RT6-Apr-06 6:52 
GeneralRe: Dialog based application with background Pin
Rostfrei6-Apr-06 7:45
Rostfrei6-Apr-06 7:45 
GeneralRe: Dialog based application with background Pin
Rostfrei6-Apr-06 8:59
Rostfrei6-Apr-06 8:59 
QuestionCall a function from provided DLL Pin
BenHieu6-Apr-06 6:25
BenHieu6-Apr-06 6:25 
AnswerRe: Call a function from provided DLL Pin
Blake Miller6-Apr-06 10:51
Blake Miller6-Apr-06 10:51 
QuestionRe: Call a function from provided DLL Pin
BenHieu3-May-06 11:34
BenHieu3-May-06 11:34 
My application is creating a COM wrapper (using Visual C++ version 6.0)that call a function from a NCRPOSAPI.dll
The CMonitor cMon object is exposed and could be initialized from another VB.NET project and following with a call cMon.Start("NCR 7167 Receipt").
In Start function of CMonitor object, a CreateThread function is called which perform another thread; here it is TimerThreadProc(). The TimerThreadProc function calls TimerThread function of CMonitor object. A TimerThread calls a GetNCRMonStatus function. This function never return properly.
GetNCRMonStatus function is a function that calling an exported function from NCRPOSAPI.dll.
If I call the "GetNCRMonStatus" function directly from the Start function ( not put it in the function of CreateThread), it will work fine.
Something conflict in multiple threads and calling a function from a DLL which is loaded at run time.
I have no linking problem, the app. is not working. I want to keep communicating to printer and get the printer status back. But after the first polling, the thread is lost and exited. Please help !!!!

I want to attach the zip file of my C++ project, but don't know how... Below is the functions and methods related... Hope you could help.

STDMETHODIMP CMonitor::Start(BSTR printerName)
{
Stop();
_bstr_t usbPrinterName = printerName;
if (!OpenPrinter(usbPrinterName, &hPrinter, NULL))
return E_INVALIDARG;

events[EVT_NOTIFY] = FindFirstPrinterChangeNotification(hPrinter, PRINTER_CHANGE_ADD_JOB | PRINTER_CHANGE_DELETE_JOB, 0, NULL);
if (!events[EVT_NOTIFY])
{
ClosePrinter(hPrinter);
hPrinter = NULL;
return E_INVALIDARG;
}
ResetEvent(events[EVT_STOP]);
LoadNCRLibrary();

/* If I call getMCRMonStatus() here, the function return fine
GetNCRMonStatus();
return S_OK; */

DWORD timerThreadId = 0;
timerThread = CreateThread(NULL, 0, TimerThreadProc, this, 0, &timerThreadId);
return S_OK;
}

STDMETHODIMP CMonitor::Stop()
{
if (timerThread != NULL)
{
ReleaseLibrary();

SetEvent(events[EVT_STOP]);
WaitForSingleObject(timerThread, INFINITE);
CloseHandle(timerThread);
timerThread = NULL;

}

FindClosePrinterChangeNotification(events[EVT_NOTIFY]);
events[EVT_NOTIFY] = NULL;

ClosePrinter(hPrinter);
hPrinter = NULL;


FreeLibrary(hLibrary);
hLibrary=NULL;
hFunction=NULL;
return S_OK;
}

bool CMonitor::LoadNCRLibrary()
{
char Path[256];
char SystemDir[256];

if(hLibrary == NULL)
{
GetSystemDirectory((LPTSTR)SystemDir,MAX_PATH);
strcpy(Path,SystemDir);
strcat(Path,"\\");
strcat(Path,"NCRPOSAPI.DLL");

hLibrary =LoadLibrary(Path) ;
}

_ASSERTE(hLibrary);

hFunction = (UVOID) GetProcAddres(hLibrary,"NCRPOS_PrinterStatus");
return (hFunction!=NULL);

}
DWORD WINAPI TimerThreadProc(LPVOID ptr)
{
CoInitialize(NULL);
CMonitor* pMon = dynamic_cast<cmonitor*>((CMonitor*)ptr);
_ASSERTE(pMon != NULL);
pMon->TimerThread();
CoUninitialize();
return 0;
}

void CMonitor::TimerThread()
{
DWORD waitHandle = WAIT_TIMEOUT; // Triggers initial status check befor
do {
GetNCRMonStatus();
}while ((waitHandle = WaitForMultipleObjects(NUM_EVTS, events, FALSE, timerInterval)) != WAIT_OBJECT_0 + EVT_STOP);
}

int CMonitor::GetNCRMonStatus()
{

DWORD NCRPOSMsg=5;

if (hFunction("NCR 7167 Receipt",(LPDWORD)&NCRPOSMsg)==0)
{
int i= 0; //ErrorPrinter /Driver
}
Sleep(5000);
return NCRPOSMsg;
}







BH
AnswerRe: Call a function from provided DLL Pin
Blake Miller5-May-06 6:42
Blake Miller5-May-06 6:42 
QuestionI need project members for X-10 Pin
Xsss4hell6-Apr-06 6:14
Xsss4hell6-Apr-06 6:14 
AnswerRe: I need project members for X-10 Pin
toxcct6-Apr-06 6:32
toxcct6-Apr-06 6:32 
GeneralRe: I need project members for X-10 Pin
Xsss4hell6-Apr-06 6:49
Xsss4hell6-Apr-06 6:49 
GeneralRe: I need project members for X-10 Pin
toxcct6-Apr-06 6:52
toxcct6-Apr-06 6:52 
Questionfree() fails in vc 6 debug mode Pin
leowwl6-Apr-06 5:57
leowwl6-Apr-06 5:57 
QuestionRe: free() fails in vc 6 debug mode Pin
David Crow6-Apr-06 6:14
David Crow6-Apr-06 6:14 
AnswerRe: free() fails in vc 6 debug mode Pin
hint_546-Apr-06 6:21
hint_546-Apr-06 6:21 
GeneralRe: free() fails in vc 6 debug mode Pin
David Crow6-Apr-06 7:04
David Crow6-Apr-06 7:04 
GeneralRe: free() fails in vc 6 debug mode Pin
hint_546-Apr-06 7:24
hint_546-Apr-06 7:24 
GeneralRe: free() fails in vc 6 debug mode Pin
David Crow6-Apr-06 7:39
David Crow6-Apr-06 7:39 
GeneralRe: free() fails in vc 6 debug mode Pin
hint_546-Apr-06 7:42
hint_546-Apr-06 7:42 
AnswerRe: free() fails in vc 6 debug mode Pin
hint_546-Apr-06 6:18
hint_546-Apr-06 6:18 
AnswerRe: free() fails in vc 6 debug mode Pin
HvalaMne6-Apr-06 12:32
HvalaMne6-Apr-06 12:32 
AnswerRe: free() fails in vc 6 debug mode Pin
toxcct6-Apr-06 21:27
toxcct6-Apr-06 21:27 
AnswerRe: free() fails in vc 6 debug mode Pin
James R. Twine7-Apr-06 0:38
James R. Twine7-Apr-06 0:38 
QuestionUsing DLL in VC++ Pin
RockyJames6-Apr-06 5:51
RockyJames6-Apr-06 5:51 

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.