|
|
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 );
}
|
|
|
|
|
You'll get much more favorable responses by providing only relevant code. No one likes spending their time wading through code that is not part of the problem.
How are you verifying that ThreadFunc() is not being called?
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
I am putting the Break Point in the ThreadFunc() but it is not going to that function.
Shailesh
|
|
|
|
|
aman2006 wrote:
I am putting the Break Point in the ThreadFunc()
On the BOOL bSuccess = TRUE statement, I assume? If so, could it be possible that the primary thread is terminating before the secondary thread has had a chance to start up?
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
I want to write one function in which I want to pass Computer Domain, Account Name, Password and absolute path of any one directory or file. From this four parameters I want to find out whether the entered user has privileges to get content of given file or directory or he is impersonating other user or such things...
Can any one help me ...Any function that you think will be helpful to me or any link which contain such similar example or any material to read ...plz I m waiting eagrly for it..
Thanking You
Chuy Ji Lee.
|
|
|
|
|
You want to do this on NTFS?
Security is a big pain, but this is what I think you have to do.
First, you need to get the security descriptor (The DACL is what you want I think) of the file. You can do this with "GetFileSecurity".
Then you need to have an access token of the client. If this is an RPC call, the user has already called in this context. You can call like "ImpersonateUser()" and then get the user's token with GetToken or something I forget the function, and you can then use one of the "AccessCheck" functions to check if that user has access. You can also call "LogonUser" since you have the password and username to get the user's token I believe. Those are the functions I'm pretty sure you want to look into.
|
|
|
|
|
Thanks a lot dear
Your answer helped me a lot.
Thank you again
Bye
|
|
|
|
|
Hi,
I am trying to implement a 'Help' file/dialogue (the standard Microsoft kind with the purple book in the L-hand corner). I have so far used the MFC Application Wizard, and selected that I do want a 'Help file' before beginning (the initialization process where you select whether or not you want ActiveX support, comments in your code, whether your app is multiple documents or dialogue-based etc.)
I understand that the text in the Help file is located in AfxDlg.rtf
When you choose to add a Help file to your application (my application is dialogue-based with buttons), the MFC Wizard automatically adds a 'Help' button to your Dialogue Box GUI. When you click the 'Help' button, it supposedly loads 'AfxDlg.rtf' (a text file that says #<<your app="">> Help Index
<<write a="" topic="" here="" that="" discusses="" your="" application's="" main="" dialog="">>).
But, my problem is: after I edit AfxDlg.rtf, when I click the Help button,
it is the same 'original' document (the document with the original #<<your app="">> Help Index <<write a="" topic="" here="" ...),="" and="" it="" doesn't="" even="" seem="" to="" recognize="" my="" changes="" (i="" changed="" afxdlg.rtf="" read="" #<<my="" app="">> Help Index ...); Does anyone know how to make the changes to AfxDlg.rtf get recognized? Or how to add on to the Help file? Is it a matter of linking?
Or editing a certain header file?
Thanks alot for your time.
Regards,
Tim Hsieh
Trex Enterprises
my changes.
|
|
|
|
|
If the help SDK is installed correctly on your mahcine, and your MFC project built correctly originally, then each time you 'rebuild all' your Help file should be recompiled into the HLP file. The Help system does not load RTF files, it loads files 'compiled' into an HLP file. You should have an HPJ - help project file - that controls the building, and if you look, it should be part of your project, along with a couple other files related to help. Watch the build output window for something about 'microsoft windows help compiler' to go by, if it is missing, then your help file is not being recompiled as part of your project.
|
|
|
|
|
I'm using VC6 and creating a dialog in a DLL. I'm trying to add the Web Browser (ActiveX) Control to the dialog. I do this and a CWebBrowser2 class is automatically created for me. I use class wizard to add it as a member variable. But when I execute the code, the dialog will not show up. If I take the control out, it works. And if I try it in a dialog in an EXE, it works. Anyone have any ideas?
|
|
|
|
|
I'm writing an app and connects a computer to another peice of hardware via the serial port. I've got everything working however while writing my comm port settings to the registry, I found that I do not know how to determine what the flow control setting is set to. Has anyone worked with the flow control settings and know what from the DCB structure I'm suppsed to use that dertmines that?
Thanks
Tom Wright
tawright915@yahoo.com
|
|
|
|
|
The documentation for the DCB structure did not help answer that question for you? Please explain how/why it is not sufficient.
"No matter where you go, there your are." - Buckaroo Banzai
-pete
|
|
|
|
|
it does not directly tell you whether it is xon/xoff or hardware or none. Not sure what in the DCB I need to look to determine what the user has set that setting for.
Tom Wright
tawright915@yahoo.com
|
|
|
|
|
Oh, sorry, didn't understand your goal.
"No matter where you go, there your are." - Buckaroo Banzai
-pete
|
|
|
|
|
Tom:
This is probably what you are looking for.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/devio/base/dcb_str.asp
In particular:
(For XON/XOFF)
fOutX
Indicates whether XON/XOFF flow control is used during transmission. If this member is TRUE, transmission stops when the XoffChar character is received and starts again when the XonChar character is received.
fInX
Indicates whether XON/XOFF flow control is used during reception. If this member is TRUE, the XoffChar character is sent when the input buffer comes within XoffLim bytes of being full, and the XonChar character is sent when the input buffer comes within XonLim bytes of being empty.
fRtsControl
RTS (request-to-send) flow control. This member can be one of the following values. Value Meaning
RTS_CONTROL_DISABLE Disables the RTS line when the device is opened and leaves it disabled.
RTS_CONTROL_ENABLE Enables the RTS line when the device is opened and leaves it on.
RTS_CONTROL_HANDSHAKE Enables RTS handshaking. The driver raises the RTS line when the "type-ahead" (input) buffer is less than one-half full and lowers the RTS line when the buffer is more than three-quarters full. If handshaking is enabled, it is an error for the application to adjust the line by using the EscapeCommFunction function.
RTS_CONTROL_TOGGLE Specifies that the RTS line will be high if bytes are available for transmission. After all buffered bytes have been sent, the RTS line will be low.
Windows Me/98/95: This value is not supported.
fOutxCtsFlow
If this member is TRUE, the CTS (clear-to-send) signal is monitored for output flow control. If this member is TRUE and CTS is turned off, output is suspended until CTS is sent again.
And Possibly ...
fDtrControl
DTR (data-terminal-ready) flow control. This member can be one of the following values. Value Meaning
DTR_CONTROL_DISABLE Disables the DTR line when the device is opened and leaves it disabled.
DTR_CONTROL_ENABLE Enables the DTR line when the device is opened and leaves it on.
DTR_CONTROL_HANDSHAKE Enables DTR handshaking. If handshaking is enabled, it is an error for the application to adjust the line by using the EscapeCommFunction function.
fOutxDsrFlow
If this member is TRUE, the DSR (data-set-ready) signal is monitored for output flow control. If this member is TRUE and DSR is turned off, output is suspended until DSR is sent again.
Let me know if you need any other help, hopefully these are enough to get you by!
|
|
|
|
|
I understand what the MSDN is saying about this structure but my problem is that while the COMMCONFIG dialog box is returning back the users configuration choices, I do not see anything for flow control. For instance I know what the user choose for baud by looking at dcb.baudrate or for parity by looking at dcb.parity, but I do not know what to look at for flow control.
Tom Wright
tawright915@yahoo.com
|
|
|
|
|
How about something such as this:
if ((m_DCB.fRtsControl == RTS_CONTROL_HANDSHAKE) && (m_DCB.fOutxCtsFlow)) {
// CTS/RTS control is enabled (This is hardware flow control)...
}
if ( (m_DCB.fOutX) && (m_DCB.fInX)) {
// XON / XOFF is enabled (Software flow control)
}
If neither of the above statements are true, flow control (hardware and software) is disabled.
Hopefully that is what you are looking for.
|
|
|
|
|
Here's a little chunk of code that may help you with the various forms of Flow Control ... Knowing what to set for each mode of flow control.
case NoFlowControl:
{
dcb.fOutxCtsFlow = FALSE;
dcb.fOutxDsrFlow = FALSE;
dcb.fOutX = FALSE;
dcb.fInX = FALSE;
break;
}
case CtsRtsFlowControl:
{
dcb.fOutxCtsFlow = TRUE;
dcb.fOutxDsrFlow = FALSE;
dcb.fRtsControl = RTS_CONTROL_HANDSHAKE;
dcb.fOutX = FALSE;
dcb.fInX = FALSE;
break;
}
case CtsDtrFlowControl:
{
dcb.fOutxCtsFlow = TRUE;
dcb.fOutxDsrFlow = FALSE;
dcb.fDtrControl = DTR_CONTROL_HANDSHAKE;
dcb.fOutX = FALSE;
dcb.fInX = FALSE;
break;
}
case DsrRtsFlowControl:
{
dcb.fOutxCtsFlow = FALSE;
dcb.fOutxDsrFlow = TRUE;
dcb.fRtsControl = RTS_CONTROL_HANDSHAKE;
dcb.fOutX = FALSE;
dcb.fInX = FALSE;
break;
}
case DsrDtrFlowControl:
{
dcb.fOutxCtsFlow = FALSE;
dcb.fOutxDsrFlow = TRUE;
dcb.fDtrControl = DTR_CONTROL_HANDSHAKE;
dcb.fOutX = FALSE;
dcb.fInX = FALSE;
break;
}
case XonXoffFlowControl:
{
dcb.fOutxCtsFlow = FALSE;
dcb.fOutxDsrFlow = FALSE;
dcb.fOutX = TRUE;
dcb.fInX = TRUE;
dcb.XonChar = 0x11;
dcb.XoffChar = 0x13;
dcb.XoffLim = 100;
dcb.XonLim = 100;
break;
}
|
|
|
|
|
Hi,
As my subject says, I'm trying to get the active projet of a solution opened in visual studio .net 2003.
The only code that I found on that is the following :
CComVariant varActiveSolutionProjects;
pDTE->get_ActiveSolutionProjects(&varActiveSolutionProjects);
if(varActiveSolutionProjects.vt == (VT_ARRAY|VT_VARIANT))
{
CComVariant varProj;
LONG lLBound, lUBound;
SafeArrayGetLBound(varActiveSolutionProjects.parray, 1, &lLBound);
SafeArrayGetUBound(varActiveSolutionProjects.parray, 1, &lUBound);
if((lUBound - lLBound) != 0)
{
return;
}
SafeArrayGetElement(varActiveSolutionProjects.parray, &lLBound, &varProj);
pActiveProjectDisp = varProj.pdispVal;
pProject = pActiveProjectDisp;
}
The problem is that I can't do
pProject = pActiveProjectDisp
Is there a way to assing cast pActiveProjectDisp to pProject ?
Thanks.
Nic
|
|
|
|
|
I've got a multidocument MFC application: a text view and OpenGL view. I've used accelerators for arrows, Home, End keystrokes to provide user some keyboard interface for OpenGL view. But these accelerators are engaged as weel in text view, and, as there're no handlers for them in text view class, won't work at all.
My question is: how can I 'divide' these accelerators between two views using default handlers in text view and my own handlers in OpenGL view?
Thank you for your attention.
|
|
|
|
|
In an SDI app , I m trying to do the following :
My View creates a Wnd and I am trying to dynamically create some controls ( CStatics)
Something like this
Test Test status
test 1 Running ....
test 2 Untested
test 3 Untested
All text are within their CStatics . I was trying to Color Code the Test Status
Like blue while running
red for failed
green for passed
grey for untested .
So I create a Class that inherits from CStatics and according to the article
HOWTO: Change the Color of an MFC Child Control Class
ID: Q132080
I overrode the OnChildNotify method
Here is what I do .
<br />
int value = 0; <br />
#define BACKCOLOR RGB(190,190,190)<br />
<br />
<br />
const COLORREF colors [] = { <br />
RGB(255,0,0),<br />
RGB(0,255,0),<br />
RGB(0,0,255)<br />
};<br />
<br />
<br />
#define VALUECOLOR colors[value]<br />
<br />
BOOL CColoredStatic::OnChildNotify(UINT message, WPARAM wParam, LPARAM lParam, LRESULT* pLResult) <br />
{<br />
<br />
if (message != WM_CTLCOLORSTATIC)<br />
{<br />
return CStatic::OnChildNotify(message,wParam,lParam,pLResult);<br />
}<br />
<br />
HDC hdcChild = (HDC)wParam;<br />
COLORREF oldTextColor = GetTextColor(hdcChild);<br />
COLORREF oldBkColor = GetBkColor(hdcChild);<br />
SetTextColor(hdcChild, VALUECOLOR );<br />
<br />
SetBkColor(hdcChild, BACKCOLOR);<br />
<br />
*pLResult = (LRESULT)(m_brush.GetSafeHandle());<br />
<br />
<br />
<br />
return TRUE;<br />
<br />
}<br />
<br />
void CColoredStatic::ChangeValue(const int &newVal)<br />
{<br />
value = newVal;<br />
Invalidate();<br />
}<br />
What I find is that after changing the value of "value" externally for the first CColorStatic object , all the CStatics get painted with the same color . Where the desired effect is to just update that Object .
My questions
when i do this
SetTextColor(hdcChild, VALUECOLOR );<br />
<br />
SetBkColor(hdcChild, BACKCOLOR);
So I have to restore the Color setting for the remaining controls ?
If yes what is that Call ? Something like a restoreObject !!!!!!!!
|
|
|
|
|
If I am reading your code correctly: value is a global variable, which is the problem. The variable value should be a class member, so that it only applies to the current CColoredStatic derived control, instead of all of them.
INTP
|
|
|
|
|
I m sorry it is a private data member of the class .
|
|
|
|
|
i have an compiled HtmlHelp file I'm using with my application. When I call the following function from MainFrame.cpp
<br />
::HtmlHelp(GetSafeHwnd(), "GameOn.chm::/Welcome.html", HH_DISPLAY_TOC, 0);<br />
it works fine. Using the same code in a DLL for my application, I doesn't work. What's more weird is that if I call Help from MainFrame first, then call help from a DLL, it works. If I call help from the DLL first and then try to call help from the MainFrame.cpp it doesn't work.
Is there something I might be missing from my DLL call that should be included? The htmlhelp.lib is being imported and the htmlhelp.h is referenced.
Thanks!
|
|
|
|
|