|
Yanshof wrote: wcscpy_s
First, if you are using generic string types, you should use generic string functions.
Otherwise, you get no benefit from the portability offered by the generic types.
_tcscpy_s() is the generic for strcpy_s()
Second, you should't be using _tcslen() here. The second parameter should be the
size of the destination buffer, not the length of the source string.
Use sizeof(BufferDestinationto ) / sizeof(TCHAR) instead.
Third, in this case, the size of the destination buffer is known by the compiler,
so you can use the two parameter version of _tcscpy_s() instead, and you
don't need to calculate the destination buffer size yourself.
Try
TCHAR BufferDestinationto[256], strSource[256];<br />
.<br />
. [ Some code that add information to BufferDestinationto ]...<br />
.<br />
<br />
_tcscpy_s(BufferDestinationto, strSource );<br />
<br />
Mark
*edit* changed array types to TCHAR - Thanks led mike
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Yanshof wrote: LPTSTR BufferDestinationto[256], strSource[256];
Try
TCHAR BufferDestinationto[256], strSource[256];
|
|
|
|
|
Oh sh**^%t I missed that
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
In reference to the visual styles uxtheme.dll...
Supposedly, according to MSDN
EnableTheming(BOOL fEnable)
TRUE - Enables visual styles. If the user previously had an active visual style, it becomes active again.
FALSE - Disables visual styles and turns visual styles off.
If I pass in FALSE, in XP and Vista, Visual styles goes away for all apps. However, if I subsequently call it passing in a TRUE, nothing happens.
Does anyone know more about this? Am I doing something wrong?
I've tried both compiling with the .lib and tried loading it dynamically but same results.
Any ideas?
|
|
|
|
|
I have noticed that when I include a common control manifest to a wizard generated Visual C++ 2003 MFC Doc/View app, and run it on XP or Vista with an XP or Vista Theme, the default gripper that comes with the toolbar either uses visual styles or is not using them. I can't figure out which is the case but regardless, the gripper background is not the same as the toolbar background.
I've been playing with uxtheme.dll and noticed some peculiarities with toolbars, menus on XP when themes are supposedly disabled for the app and it's children.
If I remove the manifest file, the toolbars work in the old fashion but popup menu's still have the visual style.
This is just a mess. I'm amazed at the amount of work Microsoft put into the visual styles libraries but when one wants to disable it completely for an app, some pieces refuse the request.
Does anyone know why the gripper stands out so bad when running in XP or vista modes with a common control manifest in a standard MFC wizard generated app? How do I get the gripper (or the toolbar or band) to fit in correctly? How do I force the popup menus to use the system colors so they match the menu colors?
|
|
|
|
|
void CSerialRecieveDlg::OnBtnAutosend()
{
// TODO: Add your control notification handler code here
if(!m_ctrlMSCommCOM1.GetPortOpen())
AfxMessageBox("please open the port!");
else
{
CCreateName Dlg;
CString TB_Name;
CString mstr;
if(Dlg.DoModal()==IDOK)
{
TB_Name=Dlg.m_TableName;
}
m_pRecordset->Close();
//// create a new table in SQL
mstr.Format("IF NOT EXISTS (SELECT * FROM sysobjects WHERE name = '");
mstr+=TB_Name;
mstr+="') CREATE TABLE ";
mstr+=TB_Name;
mstr+=" (ID INT,FangWei TEXT,FuYang TEXT,QingXie TEXT)";
try
{
m_pRecordset->Open(mstr.AllocSysString theApp.m_pConnection.GetInterfacePtr(),
adOpenDynamic,
adLockOptimistic,
adCmdText);
}
catch(_com_error *e)
{
AfxMessageBox(e->ErrorMessage());
}
SetTimer(1,500,NULL);
}
}
when debug to the end, appear an error about "stackoverflow"
what is the problem??
wuhuaiji
|
|
|
|
|
nibabug wrote: SetTimer(1,500,NULL);
What are you doing in response to the WM_TIMER message?
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
get data from three different tables , and then do something , and then show them, look the flowing:
void CSerialRecieveDlg::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
CString strSql;
// int m=atoi(m_strNum);
_variant_t var;
CString str,strnum;
CString strSendFW,strSendFY,strSendQX;
CString strSend;
str="";
SQLNum++;
if(SQLNum==130)
SQLNum-=129;
strSql.Format("%d",SQLNum);
strnum=strSql;
strSql.Format("SELECT * FROM TB_FANGWEI WHERE ID = '%s'",strnum);
try
{
//先关闭已经打开的记录集对象
m_pRecordset->Close();
//根据新的Sql查询语句,重新打开记录集对象
m_pRecordset->Open(strSql.AllocSysString(),
theApp.m_pConnection.GetInterfacePtr(),
adOpenDynamic,
adLockOptimistic,
adCmdText);
}
catch(_com_error *e)
{
AfxMessageBox(e->ErrorMessage());
}
//在ADO操作中建议语句中要常用try...catch()来捕获错误信息,
//因为它有时会经常出现一些想不到的错误。
var = m_pRecordset->GetCollect("Value");
if(var.vt != VT_NULL)
str = (LPCSTR)_bstr_t(var);
m_strAGFW=str;
var = m_pRecordset->GetCollect("HexValue");
if(var.vt != VT_NULL)
str = (LPCSTR)_bstr_t(var);
strSendFW=str;
// char* pszTest = (char*)(LPCTSTR)strSendFW;
// unsigned char* ptr=(unsigned char*)pszTest;
// unsigned char uchartemp;
// unsigned char m=4;
unsigned int intFW=(unsigned int)_tcstoul(strSendFW, 0, 16);
intFW&=0x3fff;
intFW<<=2;
intFW|=0x0000;
strSql.Format("SELECT * FROM TB_FUYANG WHERE ID = '%s'",strnum);
try
{
//先关闭已经打开的记录集对象
m_pRecordset->Close();
//根据新的Sql查询语句,重新打开记录集对象
m_pRecordset->Open(strSql.AllocSysString(),
theApp.m_pConnection.GetInterfacePtr(),
adOpenDynamic,
adLockOptimistic,
adCmdText);
}
catch(_com_error *e)
{
AfxMessageBox(e->ErrorMessage());
}
var = m_pRecordset->GetCollect("Value");
if(var.vt != VT_NULL)
str = (LPCSTR)_bstr_t(var);
m_strAGFY=str;
var = m_pRecordset->GetCollect("HexValue");
if(var.vt != VT_NULL)
str = (LPCSTR)_bstr_t(var);
strSendFY=str;
unsigned int intFY=(unsigned int)_tcstoul(strSendFY, 0, 16);
intFY&=0x3fff;
intFY<<=2;
intFY|=0x0001;
SQLNumQX++;
if(SQLNumQX==458)
SQLNumQX-=457;
strSql.Format("%d",SQLNum);
strnum=strSql;
strSql.Format("SELECT * FROM TB_QINGXIE WHERE ID = '%s'",strnum);
try
{
//先关闭已经打开的记录集对象
m_pRecordset->Close();
//根据新的Sql查询语句,重新打开记录集对象
m_pRecordset->Open(strSql.AllocSysString(),
theApp.m_pConnection.GetInterfacePtr(),
adOpenDynamic,
adLockOptimistic,
adCmdText);
}
catch(_com_error *e)
{
AfxMessageBox(e->ErrorMessage());
}
var = m_pRecordset->GetCollect("Value");
if(var.vt != VT_NULL)
str = (LPCSTR)_bstr_t(var);
m_strAGQX=str;
var = m_pRecordset->GetCollect("HexValue");
if(var.vt != VT_NULL)
str = (LPCSTR)_bstr_t(var);
strSendQX=str;
unsigned int intQX=(unsigned int)_tcstoul(strSendQX, 0, 16);
intQX&=0x3fff;
intQX<<=2;
intQX|=0x0002;
strSend="";
// strSend+="$";
str.Format("%4x",intFW);
strSend+=str;
str.Format("%4x",intFY);
strSend+=str;
str.Format("%4x",intQX);
strSend+=str;
// CString m_str;
unsigned int crc;
unsigned char* ptr;
unsigned char len;
str=strSend;
char* pszTest = (char*)(LPCTSTR)str;
ptr=(unsigned char*)pszTest;
len=str.GetLength();
crc=0;
crc=ban_crc(ptr,len);//计算校验值
strSend.Format("$");
strSend+=str;
// str=m_sSendData;
// m_str+=str;
str.Format("*");
strSend+=str;
str.Format("%04x",crc);
strSend+=str;
m_ctrlMSCommCOM1.SetOutput(COleVariant(strSend));//发送数据
UpdateData(FALSE);
// m_AccessList.AddString( strName + " --> "+strAge );
// m_pRecordset->MoveNext();
CDialog::OnTimer(nIDEvent);
}
wuhuaiji
|
|
|
|
|
You are doing WAY too much in response to a WM_TIMER message that occurs every 1/2 second.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
|
What, pray tell, are you finding amusing?
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
it was just obvious, but i loved the way you said it
|
|
|
|
|
it has no businiss with the timer, because when i change it to 2second, it also appear error:
(step debug)
unhandled exception in SerialRecieve.exe(KERNEL32.DLL):0xE06D7363:Microsoft C++ EXCEPTION
no matter where the error appears, it appears always in the CSerialRecieveDlg::OnTimer(UINT nIDEvent)
wuhuaiji
|
|
|
|
|
nibabug wrote: it has no businiss with the timer...it appears always in the CSerialRecieveDlg::OnTimer(UINT nIDEvent)
Do you see the irony in this statement? Yes, the timer is the problem. Changing the frequency to 2 seconds won't necessarily solve the problem if it takes longer than that to process a single WM_TIMER request. Put a flag in the function indicating whether it is busy or not. Check that flag before continuing.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
It's not just the timer - a thread hosting Windows UI can only process one message at a time, after all. The problem is that the MessageBox call and the modal dialog create nested message loops, which will process timer messages and thereby cause recursion.
Most likely it's one of the AfxMessageBox calls in the exception handlers in the OnTimer routine which is causing OnTimer to go re-entrant.
DoEvents : Generating unexpected recursion since 1991
|
|
|
|
|
thanks a lot
wuhuaiji
|
|
|
|
|
Try single stepping through your code in the debugger, it should be obvious then.
|
|
|
|
|
Hello!
I am trying to monitor the hard drive LED via a program I am writing in C++ for Windows XP. I just need to know if the light is on/off (the hard drive running). The user will not be able to see the light because of the placement of the computer & we cannot crack open the computer to wire it someplace else because of warranty issues. I need to incorporate it directly into a program I am writing - I cannot use any off the shelf program to show me the LED in the corner of the windows page because my custom display will take up the whole screen.
Any suggestions of how to get to status of the hard drive LED from my c++ program?
Thanks!
Margaret
|
|
|
|
|
Why don't you just monitor disk activity itself, rather than mess with the LED (which is probably not accessible anyway)?
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Mine is not question .. I just the worker bee. They want to mimick the light for the panel I am creating. If there is another way to monitor that the hard drive is being used/written to - am way open to suggestions!
Thanks
|
|
|
|
|
isikorsky91 wrote: They want to mimick the light
Since the LED is just blinking in unison with disk activity, your panel can do the same thing.
isikorsky91 wrote: If there is another way to monitor that the hard drive is being used/written to - am way open to suggestions!
A device driver is the only way.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Can you point me to any examples ? I am not clear on what you are referring to here. I have scoured the internet for hooks into windows to program into the code to monitor hard drive activity and come up with nothing ..
|
|
|
|
|
isikorsky91 wrote: Can you point me to any examples ?
See here and here.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Thanks .. but
I don't see how I can use DiskMon in my code since it is a precompiled program. The other option see a little beyond my scope of what I was looking for.. I was just looking for a simpler call to windows to find out if there is hard disk activity...
Guess I am missing what you are pointing out..
Thanks
|
|
|
|
|
isikorsky91 wrote: I don't see how I can use DiskMon in my code since it is a precompiled program.
I never indicated you could. It was merely for you to read on how it was done, and the complexity involved.
isikorsky91 wrote: Guess I am missing what you are pointing out..
Did you read this:
Windows 2000 and Higher Implementation
On Windows 2000 and higher, Diskmon uses kernel event tracing. Event tracing is documented in the Microsoft Platform SDK and the SDK contains source code to TraceDmp, on which Diskmon is based.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|