|
Excuse the intrusion...
sprintf("0x%08X", value);
This will print a hex number with exactly 8 char, prefixed with zeroes. For a decimal number "%08d" should be fine.
Cheers,
Paolo.
|
|
|
|
|
If you want to try to get better performance than what you get using sprintf, it might be faster to:
(1) use _itoa to convert the number into a temporary result, then
(2) use strncpy to copy a string of six zeros to the result, using 6 minus the length of the string in the temporary result for the count
(3) concatenate the temporary result after that
I am not sure if there will be situations where strncpy will not add a terminating null; if there will, then you will need to modify this algorithm accordingly. For example, you could just initialize the result to six zeros always, then copy (strcpy) the temporary result to the appropriate position in the result, depending on the size of the temporary result.
|
|
|
|
|
I did some brief testing using a debug build.
I discovered that the Sprintf() took about 4100 ticks (difference between GetTickCount() calls before and after for loop) to do 1 million iterations.
Using a technique similar to what was described in other replies took about 1500 ticks.
Here is code snippet of faster technique.
// preset to required zero characters
memset(szBuffer, 48, 6);
// convert your number to ascii string
_itoa(iValue, szValue, 10);
// get length of string
iLength = lstrlen(szValue);
// copy value into zero buffered string
// starting at correct offset to leave leading zeroes
lstrcpy(&szBuffer[6 - iLength], szValue);
If you inlined the source for each of the functions, it would be even faster.
|
|
|
|
|
as in unix, we have to in the promiscuous mode first in order to view the packet but there is no way to go to promiscuous mode in window. so, how packet capturing to be done in windows??
|
|
|
|
|
Hi,
I want to pass a struct from class A to class B. In class B, the members of the struct will be modified. Those modified values will be returned to class A.
How can I do that ? Do I have to utilize accessor function ?
Why ?
Thanks,
Claude
|
|
|
|
|
I don't know if I understand the question properly, but here goes anyway :
struct MYSTRUCT
{
int x,y,z;
int avg;
};
class B
{
// pass MYSTRUCT by reference so that
// values will be modified.
void ComputeSomething( MYSTRUCT& s )
{
s.avg = (s.x+s.y+s.z)/3;
}
};
class A
{
MYSTRUCT m_sample;
void DoSomething()
{
B classB;
B.ComputeSomething( m_sample );
};
};
? Is this what you wanted ?
|
|
|
|
|
Can't you just pass a reference from one class/function to the other?
e.g.
struct S {
int i1;
int i2;
};
class A {
public:
func( S& s )
{
s.i1 = somevalue;
s.i2 = someothervalue;
}
};
class B {
public:
func()
{
S s;
A a;
a.func(s);
}
}
|
|
|
|
|
In my ATL DLL projects, I used one of the containers in STL. I also tured on the "Exception Handling" compiler option (-Gx) to suppress the warnings. It's just fine with my DEBUG built. But there is a link error "error LNK2001: unresolved external symbol _main" from my RELEASE build.
Could anyone tell me what I should do to solve the problem?
Thanks,
Tony
|
|
|
|
|
Remove the preprocessor option ATL_MIN_CRT from the release build settings.
|
|
|
|
|
It does work with my "Release MinDependency" build! But it couldn't solve the problem within my "Release MinSize" build. What should I do?
Thanks,
Tony
|
|
|
|
|
Hi,
You MUST remove the preprocessor option ATL_MIN_CRT from ALL release builds, not only from "Release MinDependency".
Regards,
Alex Gorev,
Dundas Software.
|
|
|
|
|
I am using CDaoDatabase and related classes to work with an MS-Access database. I need to do
replication and synchronization with this database. I need to synchronize between this database on a
local machine, and with it on a network drive. For some reason it does not want to work. It tells me
that "the database is not found." It does not tell me which one. I know for a fact that both of them
do exist.
The first thing that needs to be done is make sure that both databases have the "Replicable"
property. If this property does not exist, I need to create it. It is at this point that I already
have problems. Here I get a "Data type conversion error." This what my code looks like:
bool CMyDatabase::CreateDBProperty(CString sProperty)
{
DAOProperty *pdp;
DAOProperties *pdps;
bool bRet = false;
COleVariant vntName( sProperty );
COleVariant vntType(( short )VT_BSTR );
COleVariant vntValue( "T" );
COleVariant vntbDDL(( long )FALSE );
// m_daoDB is a DAODatabase (from CDaoDatabase::m_pDAODatabase)
HRESULT hr = m_daoDB->CreateProperty(
vntName,
vntType,
vntValue,
vntbDDL,
&pdp );
// hr result is 0x800A0D5D (3421)
// "Data type conversion error."
}
Does anyone have any ideas or help?
I would appreciate it!
|
|
|
|
|
If someone can explain the following I would appreciate it.
I have a simple Tree control in which I need to associate data with individual items in the tree. The 32 bit LParam seems like an easy place to place an identifier that I can then use to lookup the assoicated data in a secondary array (or what ever). When I try to directly use this field it appears to always be blank (zero). But when I use the SetItemData function with the item handle returned in from the InsertItem function all works fine.
HTREEITEM pItem = m_ProdTree.InsertItem("My Text",pRoot,NULL);
DWORD MyNum=nnn;
m_ProdTree.SetItemData(pPar,MyNum);
Doesn't the SetItemData/GetItemData use the LParam field??
Thanks Mike
|
|
|
|
|
Maybe you have not set the flags in the TVITEM structure correctly?
Try to debug into the SetItemData() member function and look how MFC does it. Then you can do it the same way.
|
|
|
|
|
|
Just to document: I was not setting the mask correctly. I had just set the mask to TVIF_TEXT and had not added the TVIF_PARAM.
TVINSERTSTRUCT MyInsert;
MyInsert.hParent=NULL;
MyInsert.hInsertAfter=NULL;
MyInsert.item.mask=TVIF_TEXT|TVIF_PARAM; // <<< HERE
// The mask defines what is valid !!
MyInsert.item.pszText=_T("A->Root");
MyInsert.item.lParam=(LPARAM)MyDataValue;
HTREEITEM TVI_MyItem =
m_Tree.InsertItem(&MyInsert);
|
|
|
|
|
First of all excuse my english... (I'm just a begginer)
I've posted a question about serializing Data structures and I have followed the instructions of the scribble sample, but I get an error when loading data from disk.
My data structures are these ones:
struct STRCTxDATA { this struct contains BOOL, int, HANDLE, DCB, CString, COMMTIMEOUTS, UINT... };
struct STRCTxTEXT { This struct contains only CStrings... };
struct WRKSTRCTS // To ensure that the two structures are linked...
{
STRCTxDATA *WRKSTRCTDADES;
STRCTxTEXT *WRKSTRCTDESCRIPCIONS;
};
Now I would like to save/load those structures... (they are used to create a configuration file for the communication devices)
NOTE: those structures are placed in a CArray.
void CGenCFGDoc::Serialize(CArchive& ar)
{
int iItemCounter = 0;
char chSeparator = '\0';
m_bModified = FALSE;
if (ar.IsStoring())
{
ar << ArrayxCFG.GetUpperBound() + 1;
ar << chSeparator;
}
else
{
ar >> iItemCounter;
ar >> chSeparator;
}
ArrayxCFG.Serialize(ar);
TRACE ("\nSERIALIZATION RESULTS:\n----------------------\n# Items: %i\n",iItemCounter);
for (int iCounter = 0; iCounter <= ArrayxCFG.GetUpperBound(); iCounter++)
{
TRACE("%s\n",ArrayxCFG[iCounter].WRKSTRCTDADES->csCadDCB); // <<-- Here I got the error.
}
}
Could you help me?
Thank you in advance...
|
|
|
|
|
I need to display video from a camera in my MDI app. I'll have a menu item 'Video' and when the user selects it, a window will open displaying the incoming video.
Question:
Does anyone know where I can find info on how to do this?
I would like to develop the code so that any Windows compatible capture card would work. Should I use MCI commands or is there something more.. modern?
Thanks for any suggestions.
|
|
|
|
|
No, don't use MCI. You should use DirectShow for this. It is in fact very easy to do what you request, and DShow comes with a sample app which does just that (render relatime capture to an HWND).
DShow is part of the DirectX SDK. I don't think it's available for download anymore. You may have to order the SDK on a CD (for a nominal fee).
Good luck!
|
|
|
|
|
i think that mci was the last modren.see avicap class of VC but it doesn't work in invisible mode.all other thing it is capble of
bobbies_2001@yahoo.com
|
|
|
|
|
First of all excuse my english level, I'm just a begginer...
I must develop a program that can edit files and send them using serial ports.
In order to edit those files I've tought about using CRichEditViews in an MDI App.
Doing this I've found that the RichEdits need the OLE capabilities enabled...
Could I disable them? or there is another way (or control) that let me edit files using "Syntax highlighting" without being able to receive an Excel spreadsheet or another OLE object?
Thank you in advance.
|
|
|
|
|
Why not create a SDI application in which your view class is derived from CFormView. Then you can insert a rich edit control on your form. If you choose this method there are a couple of things that you will need to consider:
1. Add the line
AfxInitRichEdit();
to the InitInstance function of your app class.
2. Remove the line
ResizeParentToFit();
from the OnInitialUpdate function of your view class.
3. In the OnInitialUpdate and OnSize functions of your view class to resize your rich edit window to fit your view class.
|
|
|
|
|
I am currently writing an app that uses multiple document types. When the user creates a new file, I would like the size of the generated child window to depend on the document type. If anyone has any suggestions on how to accomplish this, please let me know.
|
|
|
|
|
We need a bit more information. Are you using CFormView? What criteria do you want to use to determine the size used for each view?
|
|
|
|
|
I figured one way out already, but thanks for replying. The way I am doing it I have a seperate Child Frame class for each document type. Then i just modify the window's size in the Child Frame's PreCreateWindow function. If you know of a better way to accomplish this, though, feel free to let me know! Thanks again!
|
|
|
|