|
Basically strip off the other bytes with a mask, then shift the value to fit into a BYTE.
int value;
BYTE b1 = (value & 0x000000FF);
BYTE b2 = (value & 0x0000FF00) >> 8;
BYTE b3 = (value & 0x00FF0000) >> 16;
BYTE b4 = (value & 0xFF000000) >> 24;
Build a man a fire, and he will be warm for a day Light a man on fire, and he will be warm for the rest of his life!
|
|
|
|
|
Here is yet another method :
int tempint = 42;
char intbytes[sizeof(int)];
memcpy( intbytes, &tempint, sizeof( int ) );
for( int x=0; x < sizeof( int ); x += 1 )
printf( "byte %d is %02X\n", x, intbytes[x] );
The Ten Commandments For C Programmers
|
|
|
|
|
Perhaps the standard macros HIWORD , LOWORD , HIBYTE and LOBYTE , so you do not reinvent the wheel?
Peace!
-=- James (Sonork:100.21837)
"There is nothing worse than being oblivious to the fact that you do not know what you are doing."
[Get Check Favorites 1.5 Now!]
|
|
|
|
|
Using ado record binding i can extract dbtimestamp info from sql server, however i can't seem to update the timestamp field, all other bound variables work fine with the update
help can dbtimestamp be updated? or is this read only of something
|
|
|
|
|
It is not updatable I think.Its for unique id I guess.
Mazy
"And the carpet needs a haircut, and the spotlight looks like a prison break
And the telephone's out of cigarettes, and the balcony is on the make
And the piano has been drinking, the piano has been drinking...not me...not me-Tom Waits
|
|
|
|
|
Yes, DBTIMESTAMP (Date/Time SQL Columns) can be updated, I am doing it in my current project (although I am using OleDB directly), as a "last modified" field for a record.
I have had some problems because the way the values are stored are a little different than you may expect. For example, the year field is a 4-digit year, not a 2- or 3(!)- digit one, and the month and day columns start at 1 , while the rest of them start at 0 .
For example, this is not the correct way to format a DBTIMESTAMP :
<br />
DBTIMESTAMP dbtsDateTime;<br />
<br />
dbtsDateTime.year = 99;
dbtsDateTime.month = 2;<br />
dbtsDateTime.day = 31;
dbtsDateTime.hour = 24;
dbtsDateTime.minute = 0;<br />
dbtsDateTime.second = 0;<br />
dbtsDateTime.fraction = 0;<br />
While this is:
<br />
DBTIMESTAMP dbtsDateTime;<br />
<br />
dbtsDateTime.year = 1999;<br />
dbtsDateTime.month = 2;<br />
dbtsDateTime.day = 28;<br />
dbtsDateTime.hour = 23;<br />
dbtsDateTime.minute = 0;<br />
dbtsDateTime.second = 0;<br />
dbtsDateTime.fraction = 0;<br />
Peace!
-=- James (Sonork:100.21837)
"There is nothing worse than being oblivious to the fact that you do not know what you are doing."
[Get Check Favorites 1.5 Now!]
|
|
|
|
|
My UI consists of CWnd inside CWnd that contains some UI, a simple UI layout, in short, some controls inside a controlbar.
I'm using the WindowFromPoint(CPoint) to find the window under the cursor. is there a way to go directly to access the controlBar ?
now, I do this :
CWnd* pWnd = WindowFromPoint( point);
pWnd = pWnd->GetOwner();
MyControlBarThing* pControlBarThing = dynamic_cast<MyControlBarThing*>( pWnd );
while ( pWnd && (pControlBarThing == NULL) )
{
pWnd = pWnd->GetOwner();
pControlBarThing = dynamic_cast<MyControlBarThing*>( pWnd );
}
is this kind of programming safe ? or should I use:
pWnd ->IsKindOf( RUNTIME_CLASS( MyControlBarThing) )
instead of the dynamic_cast ?
Thanks for any tips
Max.
|
|
|
|
|
AFAIK, dynamic_cast requires RTTI enabled in your app*. However the kind of objects you're dealing with are all MFC CObject derived ones, thus you should be fine using IsKindOf(**) only.
// Fazlul
* BTW, if you plan to use dynamic_cast, here is the right syntax:
class B { ... };<br />
class C : public B { ... };<br />
class D : public C { ... };<br />
<br />
void f(D* pd)<br />
{<br />
C* pc = dynamic_cast < C* >(pd);
B* pb = dynamic_cast< B* >(pd);
...<br />
}
|
|
|
|
|
if I have a class "Something" which is derived from a class declared with DECLARE_DYNAMIC, but not the derived one, does this still work ?
the IsKindOf with RUNTIME_CLASS works well to find the CWnd, but now, I have a CWnd, that I know is of class "Something", but I need to cast it to "Something" ?
Max.
|
|
|
|
|
Maximilien wrote:
if I have a class "Something" which is derived from a class declared with DECLARE_DYNAMIC, but not the derived one, does this still work ?
IsKindOf works on all MFC classes derived from CObject with DECLARE_DYNAMIC declared inside the class and IMPLEMENT_DYNAMIC implemented elsewhere. If the class is not derived, then IsKindOf will return FALSE.
|
|
|
|
|
I would like to iterate over an const array, call a function, and populate a struct, but how can I make this a variable to be dereferenced before it is called so it can set the right struct property?
const char *attrTypes[7] = {"one",
"two",
"three"}
typedef struct COMP_STRUCT {
char first[128];
int count;
char test[128];
} COMP_STRUCT;
int Function() {
char *buf
int i;
COMP_STRUCT * p_comp;
for (i=0;i<7;i++) {
SomeFunction((char*)attrTypes[i],buf,exists);
if (exists==TRUE) {
strcpy(p_comp-> ,buf);
}
}
|
|
|
|
|
You need to create a second pointer, set it to equal attTypes[0], then add strlen(attTypes) to it every time you copy.
Christian
No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002
Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002
Again, you can screw up a C/C++ program just as easily as a VB program. OK, maybe not as easily, but it's certainly doable. - Jamie Nordmeyer - 15-Nov-2002
|
|
|
|
|
I wrote an MDI application using MFC. It is an application to build proprietary (in-house format) documents using a form. This application also has a feature to taking such a document and transform it to another format understood by a third-party application.
I would like this feature to be able to run on the command line, for example:
c:> MyMIDApp /i:infilename.xxx /o:outfilename.yyy
The advantage of this is being able to automate the task of transforming the document from a script. We could really use such a feature.
Is there a simple way to do this?
tx
Michel
It is a lovely language, but it takes a very long time to say anything in it, because we do not say anything in it, unless it is worth taking a very long time to say, and to listen to.
- TreeBeard
|
|
|
|
|
|
So if the application realizes that the parameters tell it to run from the command line, do I simply exit before the call pMainFrame->ShowWindow(m_nCmdShow); or do I return FALSE before the above line of code?
Michel
It is a lovely language, but it takes a very long time to say anything in it, because we do not say anything in it, unless it is worth taking a very long time to say, and to listen to.
- TreeBeard
|
|
|
|
|
You can move the command line checking even before the MDIDocTemplate is created and return without creating it, if you do not want the windows. When you run the line that creates the DocTemplate, that is when the MainFrame, Doc and Views are created and linked together.
<code>
if (ProcessCommandLine())
{
m_pMainWnd = NULL;
return TRUE;
}
CMultiDocTemplate* pDocTemplate;
pDocTemplate = new CMultiDocTemplate(
IDR_MDITYPE,
RUNTIME_CLASS(CMdiDoc),
RUNTIME_CLASS(CChildFrame),
RUNTIME_CLASS(CMdiView));
AddDocTemplate(pDocTemplate);
CMainFrame* pMainFrame = new CMainFrame;
if (!pMainFrame->LoadFrame(IDR_MAINFRAME))
return FALSE;
m_pMainWnd = pMainFrame;
pMainFrame->ShowWindow(m_nCmdShow);
pMainFrame->UpdateWindow();
return TRUE;
</code>
My article on a reference-counted smart pointer that supports polymorphic objects and raw pointers
modified 29-Aug-18 21:01pm.
|
|
|
|
|
|
In the InitInstance of your application, you have access to the CCommandLineInfo, so derive a new class from it, and override the ParseParam method to handle the parameters on your command line.
Max.
|
|
|
|
|
What is the easiest way to update a pane in a status bar from within a view? I would really just like to access the main window's or CMainFrame m_wndStatusBar member from within my view and call the SetPaneText method as opposed to using any update command handlers. If anyone knows how I could do this I would appreciate it.
|
|
|
|
|
I usually create a public function in CMainFrame to do the updates.. Then call that function from the view or doc... Not sure if this is the best solution but it works for me.
Rob
|
|
|
|
|
Hi,
i have following problem, i have application which is linked with
ddao35.lib (ddao35.dll) (change table properties, like validation rule)this was org. built for a access 97 database.
now i like to update my application for usage access 2000 together with access 97
so with SP 5 for visual studio 6.0 a project (ddao.cpp) was shipped, new dll ddao36.lib (ddao36.dll) could be built
now i linked my application with ddao36.lib and everything goes well for a
access 2000 database, but for access97 database is code still running but
after opening the database in access97 i see that some modifications are not done
a function like this, won't work for access 97 (running without errors)
void ChangeTableValidation(CString strDBFileName, CString strTableName, CString strFieldName, CString strValidation)
{
CdbDBEngine dbEngine;
CdbDatabase dbDatabase = dbEngine.OpenDatabase(strDBFileName, FALSE);
CdbTableDef dbTableDef = dbDatabase[strTableName];
CdbField dbField = dbTableDef[strFieldName];
dbField.SetValidationRule(strValidation);
}
perhaps has somebody any idea about this,
Dan O
|
|
|
|
|
Hello all,
I've a large Access database !
What's the best algorithm for opening the database ?
How Microsoft Access open the .mdb very fast ?
(i'm using DAO)
My month article: Game programming by DirectX by Lan Mader.
Please visit in: www.geocities.com/hadi_rezaie/index.html
Hadi Rezaie
|
|
|
|
|
hi,
it depends what you want, (do you need all records)
do you use requery (views) or access direct to your tables
if you use tables normally you could go for something like
CTableNumbers tableNumbers
tableNumbers.Open()
or
CString strSQL;
strSQL = "SELECT * FROM [Numbers] WHERE Number > 10000 ORDER BY Number ASC";
TRY
{
tableNumbers.Open(AFX_DAO_USE_DEFAULT_TYPE, strSQL)
//do something
tableNumbers.Close()
}
CATCH( CDaoException, error )
{
//do handle your error
}
END_CATCH
but access is slow anyway,
you could think about opening the database tables at startup of your programm and of course at the closing your app close the database also
hope it helps,
|
|
|
|
|
Thanks for reply
In fact my problem is the program speed at start up
When i open the database at start up it's like interupt
And yes i need all data in the table.
Regards,
My month article: Game programming by DirectX by Lan Mader.
Please visit in: www.geocities.com/hadi_rezaie/index.html
Hadi Rezaie
|
|
|
|
|
Hadi_Rezaie wrote:
And yes i need all data in the table.
If there's lots of data there and you need it all, then you just have to wait for it. One option you could use, which I used in a similar situation, is to use a worker thread to get the data, and distract the user with something while it happens ( I used a login screen, which was appropriate for my app, and while you logged in, it was already reading the data. The other option is a progress bar, but that would slow down things more, because you'd have to do lots of queries instead of just one, so you could increment it.
Christian
No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002
Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002
Again, you can screw up a C/C++ program just as easily as a VB program. OK, maybe not as easily, but it's certainly doable. - Jamie Nordmeyer - 15-Nov-2002
|
|
|
|
|