|
sir,
nw i am able to create a sqlite3 database...but nw i face a problem of storing a variable which is wchar_t...which datatype should i use...plz help me
|
|
|
|
|
I need to send the data to the server in a manner like
00 12 34 00 00 54
when I am doing a strcat of 00 to 1243 or strcat of 1234 to 000054 it's not concatenating 00 to string and the result is 1234 only.
I know strcat treats 00 as a terminating null character that's why it is considering 00 as terminator.I have tried with the memcpy also but then in the server side 00 is coming as 3030.
How can I make my program to treat 00 as the part of the array not as the terminating null character or to treat 00 as it is,not the ascii value as 30.
|
|
|
|
|
If you are sending pure binary data then forget about functions that treat byte sequences as zero terminated strings. Don't use strcat but memcpy should be okay to move bytes here and there if you use it correctly. Along with your binary data you should store the length/size of the data in an int or size_t variable. If you are using C++ you could simply use an std::vector for this job.
class CStorage
{
size_t m_Size;
char m_Bytes[100];
public:
CStorage()
: m_Size(0)
{}
void Append(const char* data, size_t size)
{
memcpy(m_Bytes+m_Size, data, size);
}
};
OR
#include <vector>
#include <iterator>
static const char appendable[] = "abcdefgh";
std::vector<char> bytes;
std::copy(appendable, appendable+sizeof(appendable)/sizeof(appendable[0]), std::back_inserter(bytes));
|
|
|
|
|
You CStorage::Append() should do a m_Size += size; after the memcpy(). 
|
|
|
|
|
Of course. 
|
|
|
|
|
I explained yesterday[^] that you cannot use the string functions for binary data that contains null characters: you must use memcpy() . If the server is receiving 3030 rather than 00 , then it means your sending code is not converting it from characters to binary.
Use the best guess
|
|
|
|
|
Hello,
I need to verify content of my edit control before I let it to loose focus. To do so I wrote my PreTranslateMessage like this:
BOOL CMyFrameWnd::PreTranslateMessage( MSG *pMsg )
{
BOOL bMessageHandled = FALSE;
switch( pMsg->message )
{
case WM_LBUTTONDOWN:
{
if( ::GetFocus == MyEditWnd )
{
if( !IsContentOfMyEditWndOK )
{
ShowMessageBox( "You cannot change value");
}
}
break;
}
}
if( !bMessageHandled )
{
bMessageHandled = CFrameWnd::PreTranslateMessage( pMsg );
}
return bMessageHandled;
}
In order to be able to show modal dialog in PreTranslateMessage and after it forward WM_LBUTTONDOWN I would like to do something like this:
BOOL CMyFrameWnd::PreTranslateMessage( MSG *pMsg )
{
BOOL bMessageHandled = FALSE;
MSG oRememberMsg;
switch( pMsg->message )
{
case WM_LBUTTONDOWN:
{
if( ::GetFocus == MyEditWnd )
{
if( !IsContentOfMyEditWndOK )
{
oRememberMsg = *pMsg;
ShowMessageBox( "You cannot change value");
*pMsg = oRememberMsg;
}
}
break;
}
}
if( !bMessageHandled )
{
bMessageHandled = CFrameWnd::PreTranslateMessage( pMsg );
}
return bMessageHandled;
}
But I am not sure if my code is ok from MFC structural point of view. Can I manipulate with MSG *pMsg parameter as I described above? I tried it and it seems to work, but I don't know... Does it make some side effects? Is something I am missing here? How do you think?
|
|
|
|
|
Couldn't you handle the EN_KILLFOCUS message from the edit control in the parent dialog, check for valid values, and if is isn't OK, call the SetFocus() method for the edit control?
|
|
|
|
|
I cannot let to run OnKillFocus if control has no valid value, because OnKillFocus is too late. It is out of my control.
Let me show you some example:
I have a toolbar also. If somebody presses toolbar button OnCommand is running. Let say it is saving the document. Before saving I have to recalculate it and then save. Recalculating depends on the values in Edit. If Edit is not valid I have wrong calculations. Unfortunately pressing this toolbar buton doesn't cause KillFocus for my Edit. I have to use SetFocus to the edit's parent in order to make KillFocus for my edit to run, before I make recalculation. I don't like this solution.
I have many similar problems with validating data in OnKillFocus, so I need to handle all actions before OnKillFocus and before OnLButtonDown, OnCommand, etc of given buton. I do not want to change all possible handlers in my app so I choose PreTranslateMessage.
Sometime I return TRUE in PreTranslateMessage for example in order to not let the app for saving document, if user is in serious trouble with his already typed data.
|
|
|
|
|
Why make life difficult for yourself? The edit control provides notifications that will let you know when the contents are changing. Take a look at EN_CHANGE [^] and EN_UPDATE [^].
Use the best guess
|
|
|
|
|
Unfortunately I cannot use OnChange. It is to early to disturb user. I have to wait untill user finishes typing. EN_CHANGE is sent after each pressed key and I cannot save data from control to internal buffer during typing. I want to do it, if user decides to leave edit control.
I have also investigated this MSG *pMsg deeper and it occured that: If I let pumping messages (f.e with modal messagebox), I always have to return TRUE in PreTranslateMessage. Saving first message and forwarding it at the end has no sence, because the whole messaging process is disturbed any way.
Here is example of situation, for which my solution with saving *pMSG won't help:
WM_LBUTTONDOWN -> WM_LBUTTONUP pair is very sensitive here.
If I put messagebox between WM_LBUTTONDOWN and WM_LBUTTONUP in PreTranslateMessage it causes WM_LBUTTONUP to run for mouse point from the [OK] button on the messagebox and not for the original coordinates. So code from CFirstClickedArea::OnLButtonUp() will not be run.
So I think, I have to return always TRUE and I have no choice, if I want to use PreTranslateMessage with DoModal.
modified 26-Apr-13 13:22pm.
|
|
|
|
|
I think you are just making your program far more complicated than necessary. Using either EN_CHANGE or EN_UPDATE means that you can trap illegal content at any point. This will not have any effect on the user's typing unless they enter an incorrect character.
Use the best guess
|
|
|
|
|
This program is already complicated Now I am trying to avoid crashes xD
I could use EN_CHANGE, if I could prevent just typing.
But what about pasting with ctrl + v illegal text? Should I delete it in EN_CHANGE automatically?
Other case is, that I have to also read data from editable controls, put it to internal buffer and set "Modified" flag for saving database record later. If data is illegal, I cannot put it to the buffer and set this flag. For simple edits it os ok. But there are also RichEditCtrl controls with OLE and a lot of text. I do not want to copy all text with OLE to the buffer each time EN_CHANGE comes.
|
|
|
|
|
Newbie00 wrote: Should I delete it in EN_CHANGE automatically? Since I don't know what your program is trying to do and how many of these controls you are using I cannot answer that question.
Use the best guess
|
|
|
|
|
Is there a free C++ Model View Controller framework for Linux?
Motif does not provide the high level interface I am used to, and I'd rather not write my own. Qt is good, are there others?
Edit: I've just found wxWidgets, which looks like the bees knees, and is used by my next employer!
modified 25-Apr-13 12:52pm.
|
|
|
|
|
In my opinion there is no simple lightweight and nice MVC gui library for C++ in general, but if you want one Qt is probably the best in terms of design and tooling. What I don't like in Qt that it needs code generation and uses the over-hyped signal-slot mechanism (why don't we just use pure listener interfaces for events?) and Qt is much more than a simple gui library, its a large application framework with lots of libraries. When I used it a few years ago the layout mechanism was more complicated than that of Delphi/.Net (I think simple anchoring does the job in 99% of cases).
|
|
|
|
|
We used in the past Crystal Reports 8.5 with Dev Studio 2003, but because of our customer we must change now to CR 2011 and Dev Studio 2010, but CR 2011 doesn't support the API. We already downloaded the files which a necessary for the Integration from the SAP Homepage and installed it.
But there doesn't exist any example how to use it in C++/MFC. Has anyone already expierience with this and can give us some informations or an example source code?
|
|
|
|
|
I'm creating an application of webcam preview using directshow.
I'm able to see video but there is no audio.
Can someone suggest me how can I add this audio to my application.
Please Suggest me.
|
|
|
|
|
Please post your code graph - all filters you are using and especially source filter.
|
|
|
|
|
Hi,
I want to create 4 dimensional array, in that first three dimenstional are fixed size and the final index will be on 0 to N-numbers.
For eg, double array[500][25][10][NOT FIXED].. So I cant create statically, because the index size are more. Also I have tried 4 dimenstional vector, but its giving 2 problem.
(i) I am storing 4th dimenstion size is more than vector[0][0][0].max_size()
(ii) Storing and Retrieving its more time in vector
So Please let me know, if any other solution to store large array which is 3 index is FIXED and final one is not FIXED?
Looking for answer from anyone..
Thanks.
|
|
|
|
|
|
The memory layout of a C array like char my_array[4][3][2] is the following (where a '0' character is a placeholder for 1 byte):
first dim=0 first dim=1 first dim=2 first dim=3
00 | 00 | 00 # 00 | 00 | 00 # 00 | 00 | 00 # 00 | 00 | 00
▲ ▲ ▲ ▲ ▲ ▲
| | | | | |
| | [0][2][1] | | [2][2][1]
| [0][1][0] | [2][1][0]
[0][0][0] [2][0][0]
Where '#' means a change in the first index and '|' is a change in the second index, while the 3rd index just moves 1 byte. Because of this memory layout you can make only the first dimension resizable if you are using a pointer instead of a fixed size static array. If you wanted to resize some other dimensions then you should insert bytes in many places but resizing the first dimension means just adding memory at the end of you currently allocated memory, or maybe shrinking the current storage. The above char my_array[4][3][2] could be allocated dynamically in the following way:
typedef char ArrayType[3][2];
ArrayType* p = new ArrayType[4];
p[3][2][1] = 0;
ArrayType* q = (ArrayType*)malloc(sizeof(ArrayType)*4);
q = (ArrayType*)realloc(q, sizeof(ArrayType)*5);
q[4][2][1] = 1;
Note that indexing into p and q are very fast like it is in case of static arrays and the occupied memory is 1 big chunk of continuous area. If you need just 1 resizable dimension then you can go with this technique because it really doesn't matter which dimension has this resizable trait. Lets say you make a 2 dimensional array because you want to store additional data to specific X and Y coordinates. If you need resizable 'Y' dimension then you address the array this way: [Y][X] but if you need resizable 'X' dimension then you simple index this way: [X][Y]. The same applies to multiple dimensions, it really doesn't matter which index do you use for different things, the only 2 things it can screw up is the memory layout of items (cache misses) and the readability of the source code - but sometimes you have to sacrifice readability if you are optimizing because this kind of thing is something that smells like optimization.
|
|
|
|
|
double array[500][25][10][<NOT FIXED>].
I am achieving this using vector(vector(vector(vector(double)))) dBuffer(....);
As of now I am using vector[500][25][10][UnknownSize].
UnknownSize will be decided on run time. I cant create the memory for final size. Because the final index value it will come splited way. For eg, one iteration it will come 100 values, after some iteration it will come 150 values.. For that I cant create the pointer to store for 100,150,etc... So i need use some STL..
Pls suggest me which STL is useful... Currently i am using 4D vector. But its execution time is more.
|
|
|
|
|
What do you want to achieve? There is no golden hammer that solves everything.
|
|
|
|
|
If your only problem would be an array with one dynamic dimension, you could try this:
std::vector<double> array[500][25][10];
That will create an array of 125000 double vectors of dynamic size. The statical allocation will not be a problem, and the time required for the dynamic allocation will be proportional to the actual number of elements. The only performance problem will be the deallocation - whenever that array runs out of scope, your program will take a considerable amount of time. With 125000 arrays, expect the deallocation to run for anything between a couple of seconds and a few minutes!
However:jothivel k wrote: (i) I am storing 4th dimenstion size is more than vector[0][0][0].max_size()
If I understand this comment correctly, you are trying to statically store data that exceed the address space of your application! If so, the answer is simple: you can't do that! What you need is a database! Try your luck with MySQL or google for another database library.
|
|
|
|