Click here to Skip to main content
15,917,709 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralShell doesnt give long filename Pin
KnaveWave9-Aug-04 8:04
KnaveWave9-Aug-04 8:04 
GeneralRe: Shell doesnt give long filename Pin
OBRon9-Aug-04 8:12
OBRon9-Aug-04 8:12 
GeneralRe: Shell doesnt give long filename Pin
Toby Opferman9-Aug-04 12:02
Toby Opferman9-Aug-04 12:02 
GeneralRe: Shell doesnt give long filename Pin
KnaveWave9-Aug-04 16:24
KnaveWave9-Aug-04 16:24 
GeneralRe: Shell doesnt give long filename Pin
OBRon10-Aug-04 1:55
OBRon10-Aug-04 1:55 
QuestionUpdate VS .NET 7.0 to 7.1 possible? Pin
Maarten Kools9-Aug-04 7:42
professionalMaarten Kools9-Aug-04 7:42 
AnswerRe: Update VS .NET 7.0 to 7.1 possible? Pin
OBRon9-Aug-04 8:16
OBRon9-Aug-04 8:16 
GeneralThread is not going to the Function Pin
aman20069-Aug-04 6:33
aman20069-Aug-04 6:33 
Hi
Here is my Full code in which i am creating a thread in DLL and passing the function name as ThreadFunc . But it is not going to the ThreadFunc after creating it. See the Func PrepareThread() below

BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
return TRUE;
}


extern "C" __declspec(dllexport) BOOL Connect ( char *pPort , char *pBuff )
{


int nDataSize = 0;
int nSentSize = 0;

if(strcmp(pPort,"") == 0)
{
strcpy(pBuff,"Please supply a COM port");
return false;
}

g_hPort = Rs232Open(pPort);
if ( l_bTaskAbort )
{
Rs232CleanUp(FALSE);
return false;
}
if ( g_hPort == NULL )
{
l_dwErrCode = GetLastError();
ShowRegError(l_dwErrCode);
Rs232CleanUp(FALSE);
return false;
}
// wake up printer
char wakeUpChars[2];
wakeUpChars[0]=(char)'0x0H';
wakeUpChars[1]='\0';
nDataSize = strlen(wakeUpChars);
nSentSize = Rs232SendBlk(g_hPort, wakeUpChars, nDataSize);
Sleep(100);

if ( l_bTaskAbort )
{
Rs232CleanUp(FALSE);
return(false);
}

//Lets check for oneil printer attached or not
nDataSize = 6;
nSentSize = Rs232SendBlk(g_hPort,"\x1b{ST?}",nDataSize);
if(nSentSize != nDataSize)
return false;
// Sleep(100);
char szData[36];
memset(szData,0x00,sizeof(szData));
if(Rs232RecvBlk(g_hPort,szData,35 ) >0)
{
if(strncmp(szData,"{ST!E:N;",8) != 0)
{
strcpy(pBuff,"Printer is not connected.");
return false;
}

}
else
{
strcpy(pBuff,"Printer is not connected.");
return false;
}



return true;
}

extern "C" __declspec(dllexport) BOOL ReadCard(char *pData)
{


if(g_hPort == NULL)
{
strcpy(pData,"COM port is not opened");
return false;
}

PrepareThread();

return true;
}

extern "C" __declspec(dllexport)void Disconnect()
{

//Terminate Read thread and close msr3000
TerminateThread(g_hThreadRead, 0);
g_hThreadRead = NULL;
Rs232CleanUp(FALSE);


}
DWORD WINAPI ThreadFunc(LPVOID param)
{
BOOL bSuccess = TRUE;
while(1)
{
int index = 0;

// Clear the dara buffer first.
memset(g_strResult,0x00,500);
if ( l_bTaskAbort )
{
Disconnect();
return(false);
}
//if card is seated
// Ask the user to remove the card
// if the card is removed then read the data
if(GetCardData())
{


//MyMSR_ShowResult(0);
break;
}





}

return bSuccess;
}

static void PrepareThread()
{
g_hThreadRead = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)ThreadFunc, 0, 0,&dwThreadID);


}


static BOOL GetCardData()
{
BOOL bSuccess = TRUE;
char szData[100];
int nDataSize = 0;
int nSentSize = 0;
DWORD dwStartTime;
dwStartTime = GetTickCount();

szData[0] = 0x1B;
szData[1]='{';
szData[2]='M';
szData[3]='R';
szData[4]='?';
szData[5]='}';
szData[6]='\0';
nDataSize = strlen(szData);

while ( !l_bTaskAbort )
{
DWORD dwEllapsedTime = GetTickCount() - dwStartTime;
//time out
if ( dwEllapsedTime >= READTIMEOUT )
{
bSuccess = FALSE;
break;
}
nSentSize = Rs232SendBlk(g_hPort, szData, nDataSize);
if ( nSentSize != nDataSize )
{
bSuccess = FALSE;
break;
}
Sleep(100);
if( Rs232RecvBlk(g_hPort, g_strResult, 500) >0)
{

// No card data
if(strncmp(g_strResult,"{N}",3) == 0)
{
Sleep(10);
}
else
{

break;
}
}

else
{
Sleep(10);
}
}
return bSuccess;
}










//----------------------------------------------------------------------------
// Rs232Open
//----------------------------------------------------------------------------
static HANDLE Rs232Open(char *pPort)
{
DCB PortDCB;

HANDLE hPort;
BOOL bSuccess = FALSE;
COMMTIMEOUTS CommTimeouts;


PortDCB.DCBlength = sizeof(DCB);

hPort = CreateFile(pPort,
GENERIC_READ | GENERIC_WRITE,
0,
NULL,
OPEN_EXISTING,
0,
NULL);

if ( hPort == INVALID_HANDLE_VALUE )
{
l_dwErrCode = GetLastError();
return NULL;
}

// set up detail
SetupComm(hPort,INQUEUESIZE,OUTQUEUESIZE);
bSuccess = GetCommState(hPort,&PortDCB);
if (bSuccess == FALSE)
{
l_dwErrCode = ERROR_NOT_READY;
CloseHandle(hPort);
//if (g_hStatus != NULL)
// SetWindowText(g_hStatus, TEXT("Err setting Comm"));
return NULL;
}

//CBR_9600, CBR_19200,CBR_38400,CBR_57600,CBR_115200
PortDCB.BaudRate = CBR_9600;
PortDCB.fBinary = TRUE;
PortDCB.fParity = TRUE;
PortDCB.fOutxCtsFlow = FALSE;
PortDCB.fOutxDsrFlow = FALSE;
PortDCB.fDtrControl = DTR_CONTROL_ENABLE;
PortDCB.fDsrSensitivity = FALSE;
PortDCB.fTXContinueOnXoff = TRUE;
PortDCB.fOutX = FALSE;
PortDCB.fInX = FALSE;
PortDCB.fErrorChar = FALSE;
PortDCB.fNull = FALSE;
PortDCB.fAbortOnError = FALSE;
PortDCB.ByteSize = 8;
PortDCB.Parity = NOPARITY;
PortDCB.StopBits = ONESTOPBIT;
PortDCB.fRtsControl = RTS_CONTROL_ENABLE;
PortDCB.XoffLim = INQUEUESIZE/5;
PortDCB.XonLim = INQUEUESIZE/5;
bSuccess = SetCommState(hPort,&PortDCB);

// set time out
bSuccess = GetCommTimeouts(hPort,&CommTimeouts);
CommTimeouts.ReadIntervalTimeout = MAXDWORD;
CommTimeouts.ReadTotalTimeoutMultiplier = 0;
CommTimeouts.ReadTotalTimeoutConstant = 0;
CommTimeouts.WriteTotalTimeoutMultiplier = 0;
CommTimeouts.WriteTotalTimeoutConstant = 3000;
bSuccess = SetCommTimeouts(hPort,&CommTimeouts);

if ( l_bTaskAbort )
{
l_dwErrCode = ERROR_NOT_READY;
CloseHandle(hPort);
// if (g_hStatus != NULL)
// SetWindowText(g_hStatus, TEXT("Err setting timeout"));
return(NULL);
}

Sleep(1000);
PurgeComm(hPort,PURGE_TXCLEAR|PURGE_RXCLEAR);
return(hPort);
}

//----------------------------------------------------------------------------
// Rs232SendBlk
//----------------------------------------------------------------------------
static int Rs232SendBlk(HANDLE hPort, LPSTR lpcData, int nSize)
{
int nLen = 0;
DWORD dwWrite;
l_dwErrCode = ERROR_SUCCESS;
while ( ( nLen < nSize ) && !l_bTaskAbort )
{
if ( !WriteFile(g_hPort,lpcData+nLen,nSize-nLen,&dwWrite,0) )
{
l_dwErrCode = GetLastError();
dwWrite = 0;
}

if ( dwWrite == 0 )
{
break;
}

nLen += dwWrite;
}

return(nLen);
}

//----------------------------------------------------------------------------
// Rs232RecvBlk
//----------------------------------------------------------------------------
static int Rs232RecvBlk(HANDLE hPort, LPSTR lpcData, int nSize)
{
int nLen = 0;
DWORD dwRead;
DWORD dwStartTime;
l_dwErrCode = ERROR_SUCCESS;
dwStartTime = GetTickCount();
while ( ( nLen < nSize ) && !l_bTaskAbort )
{
DWORD dwEllapsedTime = GetTickCount() - dwStartTime;
if ( dwEllapsedTime >= l_dwTimeout )
{
return(nLen);
}

if ( !ReadFile(g_hPort,lpcData+nLen,nSize-nLen,&dwRead,0) )
{
l_dwErrCode = GetLastError();
dwRead = 0;
}

if ( dwRead > 0 )
{
nLen += dwRead;
dwStartTime = GetTickCount();
}
else
{
Sleep(10);
}
}
return(nLen);
}
//----------------------------------------------------------------------------
// Rs232CleanUp
//----------------------------------------------------------------------------
static int Rs232CleanUp(BOOL bSuccess)
{
//l_bTaskAbort = TRUE;

// If there is an open port
if ( g_hPort != NULL )
{
PurgeComm(g_hPort,PURGE_TXABORT|PURGE_TXCLEAR|PURGE_RXABORT|PURGE_RXCLEAR);
// Close the port
CloseHandle(g_hPort);
// Mark it not open
g_hPort = NULL;
}

// Indicate that Rs232 shutdown is complete
l_bTaskDone = TRUE;

// Return what was passed in
return(bSuccess);
}

void ShowRegError(DWORD nReturnVal)
{


LPVOID lpMsgBuf;
FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM,
NULL,
nReturnVal,
0, // Default language
(LPTSTR) &lpMsgBuf,
0,
NULL
);


MessageBox( NULL, (LPCTSTR)lpMsgBuf, TEXT("Error"), MB_OK | MB_ICONINFORMATION );
// Free the buffer.
LocalFree( lpMsgBuf );



}
GeneralRe: Thread is not going to the Function Pin
David Crow9-Aug-04 9:18
David Crow9-Aug-04 9:18 
GeneralRe: Thread is not going to the Function Pin
aman20069-Aug-04 10:37
aman20069-Aug-04 10:37 
GeneralRe: Thread is not going to the Function Pin
David Crow10-Aug-04 4:53
David Crow10-Aug-04 4:53 
QuestionHow to know Security Context &amp; Impersonation ? Pin
Anonymous9-Aug-04 6:31
Anonymous9-Aug-04 6:31 
AnswerRe: How to know Security Context &amp; Impersonation ? Pin
Toby Opferman9-Aug-04 11:40
Toby Opferman9-Aug-04 11:40 
GeneralRe: How to know Security Context &amp; Impersonation ? Pin
Amarelia9-Aug-04 14:52
Amarelia9-Aug-04 14:52 
GeneralHelp on Help Pin
Tim Hsieh9-Aug-04 6:29
Tim Hsieh9-Aug-04 6:29 
GeneralRe: Help on Help Pin
Blake Miller9-Aug-04 8:07
Blake Miller9-Aug-04 8:07 
Generalweb browser control in a dll Pin
Phil Hamer9-Aug-04 6:20
Phil Hamer9-Aug-04 6:20 
GeneralSerial Port Question Pin
Tom Wright9-Aug-04 5:52
Tom Wright9-Aug-04 5:52 
GeneralRe: Serial Port Question Pin
palbano9-Aug-04 9:40
palbano9-Aug-04 9:40 
GeneralRe: Serial Port Question Pin
Tom Wright9-Aug-04 10:21
Tom Wright9-Aug-04 10:21 
GeneralRe: Serial Port Question Pin
palbano9-Aug-04 18:01
palbano9-Aug-04 18:01 
GeneralRe: Serial Port Question Pin
shultas9-Aug-04 15:26
shultas9-Aug-04 15:26 
GeneralRe: Serial Port Question Pin
Tom Wright10-Aug-04 3:43
Tom Wright10-Aug-04 3:43 
GeneralRe: Serial Port Question Pin
shultas10-Aug-04 5:46
shultas10-Aug-04 5:46 
GeneralRe: Serial Port Question Pin
shultas10-Aug-04 5:50
shultas10-Aug-04 5:50 

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.