|
Blake,
Thanks for the reply. I actually started looking into the possibility of ADORecordsets yesterday, so this confirms it would be a wise move, thanks.
I assume I can use these classes in VC++ (as opposed to having to move to .NET) in place of my CRecordsets (obviously with a bit of tweaking throught the code), but in a similar way?
|
|
|
|
|
|
http://img194.imageshack.us/img194/1737/hwnd8ry.jpg
i am trying to post a message to my windowless app
i tried
<br />
PostMessage( theApp.GetMainWnd()->m_hWnd , WM_MAKE_TIME_STOP_DLG, (WPARAM)broken_msg_obj.parm2, 0);<br />
<br />
PostMessage( theApp.m_hThread , WM_MAKE_TIME_STOP_DLG, (WPARAM)broken_msg_obj.parm2, 0);<br />
<br />
PostMessage( hwnd , WM_MAKE_TIME_STOP_DLG, (WPARAM)broken_msg_obj.parm2, 0);<br />
<br />
PostMessage( m_pMainWnd->GetSafeHwnd() , WM_MAKE_TIME_STOP_DLG, (WPARAM)broken_msg_obj.parm2, 0);<br />
<br />
PostMessage( GetParent(0) , WM_MAKE_TIME_STOP_DLG, (WPARAM)broken_msg_obj.parm2, 0);<br />
<br />
PostMessage(this->m_pMainWnd->m_hWnd, WM_MAKE_TIME_STOP_DLG, (WPARAM)broken_msg_obj.parm2, 0);[/CODE]<br />
<br />
but they all either give compile error or dont work<br />
<br />
<br />
my initinstance of the app<br />
[CODE]<br />
BOOL CAsevApp::InitInstance()<br />
{<br />
CDialog dlg;<br />
m_pMainWnd = &dlg;<br />
return TRUE;<br />
}
please asssist :wave:
|
|
|
|
|
awah wrote:
CDialog dlg;
m_pMainWnd = &dlg;
I guess the window is not even being created yet.
You are posting messages to the window which does not exist.
You need to call at least DoModal() or call the dialog's Create() function.
this is this.
|
|
|
|
|
strtok,strcpy,crashes when garbage strings are handled
this is especially so in winsock applications
in my application, i expect " value1^value2^value^&############"
and use strtok to extract value 1,2 and 3
and "&" indicates that there are no more values to be collected
where #### = garbaage
others can send a garbage long string like
"##################################"
and my application would crash
is there anyway to tell strtok/strcpy to handle this?
will a check on strlen help?
more info on my function
struct broken_msg<br />
{<br />
void break_msg(char* full_msg)<br />
{<br />
char seps[] = "^";<br />
char *token;<br />
token = strtok( full_msg, seps ); <== CRASHES HERE<br />
if(strlen(token) < 150)<br />
{<br />
strcpy(parm0,token);<br />
}<br />
<br />
if( stricmp("&" ,token ) )<br />
{<br />
token = strtok( NULL, seps );<br />
if(strlen(token) < 150)<br />
{<br />
strcpy(parm1,token);<br />
}<br />
}<br />
if( stricmp("&" ,token ) )<br />
{<br />
token = strtok( NULL, seps );<br />
if(strlen(token) < 150)<br />
{<br />
strcpy(parm2,token);<br />
}<br />
<br />
}<br />
if( stricmp("&" ,token ) )<br />
{<br />
token = strtok( NULL, seps ); <br />
if(strlen(token) < 150)<br />
{<br />
strcpy(parm3,token);<br />
}<br />
<br />
}<br />
}<br />
<br />
<br />
char parm0[150];<br />
char parm1[150];<br />
char parm2[150];<br />
char parm3[150];<br />
};
|
|
|
|
|
You can set a maximum length for the received string like:
char* full_msg;
full_msg[200] = 0; // set the limit to 200 chars.
I hope it will do the thing.
this is this.
|
|
|
|
|
awah wrote:
where #### = garbaage
others can send a garbage long string like
"##################################"
and my application would crash
Search the incoming string for & before attempting to parse it. Or copy the string up to & into another string and parse it instead.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
1) Make sure token is not NULL after each call to strtok(), or you'll get a runtime error or garbage. While it is generating garbage, it is also corrupting data; which should make the system scream (runtime error), but some times it doesn't.
2) Simplify a little bit by using if( '&' == *token ), that will produce faster code and makes more since.
INTP
"The more help VB provides VB programmers, the more miserable your life as a C++ programmer becomes."
Andrew W. Troelsen
|
|
|
|
|
Here is code sample for 2 same sized arrays A and B correlation in mmx:
float f_x2temp[4],f_y2temp[4],f_valtemp[4];
float m_zero=0.0f;
float f_x,f_y, f_x2=0.0f,f_y2=0.0f, f_val=0.0f;
__m128 *mA, *mB;
__m128 meanA,meanB, m_x,m_y, m_x2,m_y2, m_val;
m_val = _mm_load_ss(&m_zero);
m_x2 = _mm_load_ss(&m_zero);
m_y2 = _mm_load_ss(&m_zero);
meanA = _mm_load_ps1(&A->m_mean);
meanB = _mm_load_ps1(&B->m_mean);
for(int j=0; j<a->m_height; j++)
{
mA = (__m128 *)&A->m_rdata[j][0];
mB = (__m128 *)&B->m_rdata[j][0];
for(int i=0; i<a->m_width/4; i++)
{
m_x = _mm_sub_ps(*mA++,meanA);
m_y = _mm_sub_ps(*mB++,meanB);
m_val = _mm_add_ps(m_val, _mm_mul_ps(m_x,m_y));
m_x2 = _mm_add_ps(m_x2, _mm_mul_ps(m_x,m_x));
m_y2 = _mm_add_ps(m_y2, _mm_mul_ps(m_y,m_y));
}
}
but after first iteration of this instruction "m_x = _mm_sub_ps(*mA++,meanA);"
I get "Unhandled exception at 0x0041ff76 in myapp.exe: 0xC0000096: Privileged instruction." in "m_y = _mm_sub_ps(*mB++,meanB);" instruction what's wrong? Its not a memory failure access exception everything ok with A and B data buffers
9ine
|
|
|
|
|
interesting it works well with this mod.
for(int j=0; j<a->m_height; j++)
{
for(int i=0; i<a->m_width/4; i++)
{
m_x = _mm_sub_ps(_mm_loadu_ps(&A->m_rdata[j][i*4]), meanA);
m_y = _mm_sub_ps(_mm_loadu_ps(&B->m_rdata[j][i*4]), meanB);
m_val = _mm_add_ps(m_val, _mm_mul_ps(m_x,m_y));
m_x2 = _mm_add_ps(m_x2, _mm_mul_ps(m_x,m_x));
m_y2 = _mm_add_ps(m_y2, _mm_mul_ps(m_y,m_y));
}
}
9ine
|
|
|
|
|
Is it possible to replace tab buttons in the tab control by a bitmap?
|
|
|
|
|
Asha Udupa wrote:
Is it possible to replace tab buttons in the tab control by a bitmap?
Yeap, Use Owner Draw TabCtrl
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
|
|
|
|
|
hello everyone,
i want to use the Drag feature in my TreeCtrl,but is not normal drag in the tree,i just want to drag a leaf node of a tree to another controls,such as a edit box,just show the data of the leaf in the edit box,i have no idea about how to implement this,who can help me?
thanks
best regards
|
|
|
|
|
This[^] article might help you get some idea about the way you should start.
<bold>- Nilesh
<italics>"Reading made Don Quixote a gentleman. Believing what he read made him mad" -George Bernard Shaw
|
|
|
|
|
Interesting: How do you determine if a character type is char or wchar_t at compile time without using #ifdef UNICODE (or _UNICODE)?
Examples (THAT WILL NOT WORK):
#if char_type == wchar_t
// character type is wchar_t
#else
// character type is char
#endif
#if sizeof(char_type) == sizeof(wchar_t)
// character type is wchar_t
#else
// character type is char
#endif
Is something like this even possible?
Essentialy, I am dealing with a template class that takes the character type as an argument. Therefore, I need to know character type it is.
Example:
#ifdef UNICODE
std::wout << L"some string";
#else
std::out << "some string";
#endif
The above looks reasonable, but it assumes the character type. Since it is a template and it can take any character type, whether UNICODE is defined or not, it well not work.
What I need is compiler independent text feed back from the template at runtime, regardless of the character type passed as an argument to the template. The user knows what type they passed so they already know what type of text to expect as feedback.
INTP
"The more help VB provides VB programmers, the more miserable your life as a C++ programmer becomes."
Andrew W. Troelsen
|
|
|
|
|
John R. Shaw wrote:
Interesting: How do you determine if a character type is char or wchar_t at compile time without using #ifdef UNICODE (or _UNICODE)?
Can't you solve it by providing explicit specializations for both char and wchar_t?
Example:
template<class char_type>
void OutString(const char_type* string)
{
ASSERT(FALSE);
}
template<> void OutString<char>(const char* string)
{
std::out << string;
}
template<> void OutString<wchar_t>(const wchar_t* string)
{
std::wout << string;
}
--
jlr
http://jlamas.blogspot.com/[^]
|
|
|
|
|
Doh!
Now why didn't I think of that? Apparently I was being a tad bit to strict on my requirements.
:-DThanks Jose.
MODIFIED:
Whoops!
I spoke to soon! That is not the problem. The problem is, how does the template know what format to use for strings that it generates internaly, with out using compiler specific defines?
Example:
template<class T>
void mytemp<T>::show_info(char_type c1, char_type c2)
{
stringstream<char_type> os;
os << "some text: '" << c2 << "' following '" << c1 << "'";
show_string(os.str());
}
The above would work fine for ANSI, but poduces garbage if the char_type is wchar_t. Since the hard coded strings are ANSI and not UNICODE.
INTP
|
|
|
|
|
John R. Shaw wrote:
Example:
template<class t="">
void mytemp<t>::show_info(char_type c1, char_type c2)
{
stringstream os;
os << "some text: '" << c2 << "' following '" << c1 << "'";
show_string(os.str());
}
The above would work fine for ANSI, but poduces garbage if the char_type is wchar_t. Since the hard coded strings are ANSI and not UNICODE.
INTP
How about using overloaded member functions and letting the compiler choose?
template<class T>
void mytemp<T>::show_info(const char_type* c1, const char_type* c2)
{
basic_stringstream<char_type, char_traits<char_type>, allocator<char_type> > os;
LoadCharStream(os, c1, c2);
show_string(os.str());
}
template<class T>
void mytemp<T>::LoadCharStream(wstringstream& os, const wchar_t* c1, const wchar_t* c2)
{
os << L"some text: '" << c2 << L"' following '" << c1 << L"'";
}
template<class T>
void mytemp<T>::LoadCharStream(stringstream& os, const char* c1, const char* c2)
{
os << "some text: '" << c2 << "' following '" << c1 << "'";
}
--
jlr
http://jlamas.blogspot.com/[^]
|
|
|
|
|
Thanks! That will work!
I was trying to avoid any thing that required exact knowledge of the character type. So I would not have to write multiple overloaded functions to display each piece of data. But I see now that I was off in dream land some where, because what I was conceiving is not possible (in this case).
I consider the feedback mechanism necessary for debugging and a requirement, if it is going to be used for teaching. Eventually I will create a version with out the feedback mechanism, at the moment it is only turned on by a define statement.
Thanks again, for your valuable feedback.
INTP
"The more help VB provides VB programmers, the more miserable your life as a C++ programmer becomes."
Andrew W. Troelsen
|
|
|
|
|
John R. Shaw wrote:
#ifdef UNICODE
std::wout << L"some string";
#else
std::out << "some string";
#endif
The above looks reasonable, but it assumes the character type. Since it is a template and it can take any character type, whether UNICODE is defined or not, it well not work.
sure. did you look into the source files provided when you install Visual Studio ??
there are plenty of functions in the libraries written just this way !
if you want to know such an information at compile time, #ifdef or #if defined() remain the best way...
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
Plenty of MS Specific files, but not one standard file. The template is designed using standard C++, only.
INTP
"The more help VB provides VB programmers, the more miserable your life as a C++ programmer becomes."
Andrew W. Troelsen
|
|
|
|
|
John R. Shaw wrote:
Essentialy, I am dealing with a template class that takes the character type as an argument. Therefore, I need to know character type it is.
So basically you have a class that looks like this:
template <typename CharacterType >
class Foo
{
public:
void DoFoo(CharacterType Char);
};
template <typename CharacterType>
void Foo<CharacterType>::DoFoo(CharacterType Char)
{
}
If i'm correct in my assumption, read on. If not you can ignore the rest of this post.
John R. Shaw wrote:
What I need is compiler independent text feed back from the template at runtime,
What feedback do you want? Why do you want this? More important, what is it that you don't know at compile time that you need to know at runtime? If you want to know this sort of stuff (which you really don't), look here[^].
John R. Shaw wrote:
Example:
#ifdef UNICODE
std::wout << L"some string";
#else
std::out << "some string";
#endif
The above looks reasonable, but it assumes the character type. Since it is a template and it can take any character type, whether UNICODE is defined or not, it well not work.
Templates can solve this exactly. You don't want to resolve this at runtime, but at compile time. The reason for this is that you can fix your problems faster and your compiler shouts tons of errors at you when you are about to make a big mistake in your program! You don't want to go into debugging trouble for type dependant stuff.
Consider the following:
>
template <typename CharacterType >
class CharacterDependantClass
{
public:
void DoFoo(CharacterType Char);
};
template <typename CharacterType>
void CharacterDependantClass<CharacterType>::DoFoo(CharacterType Char)
{
}
#ifdef UNICODE
typedef CharacterDependantClass<wchar_t> ClassType;
#else
typedef CharacterDependantClass<char> ClassType;
#endif
If you use an wchar_t string when UNICODE is not defined, you get compiler errors, which is exactly what you want.
Behind every great black man...
... is the police. - Conspiracy brother
Blog[^]
|
|
|
|
|
Keep in mind that a requirement of this project (my own), is to use standard C++ only. That is it must be totally compiler independent, it needs to be usable in any C++ environment, be it Windows, Unix, etc... .
Bob Stanneveld wrote:
What feedback do you want?
The templates use various algorithms to process text and I want it to be able to to show the steps it takes in processing, as visual feedback to user (this feature can be turned on at compile time.
Bob Stanneveld wrote:
Why do you want this?
This feature is not just for testing, but also for teaching. It is not needed for the templates to do there job, but it is if you want to see how they do it (consider it a type of compiler feedback).
Bob Stanneveld wrote:
More important, what is it that you don't know at compile time that you need to know at runtime?
What the input is, and precisely how it processed that input.
Does a compiler know precisely what the input is going to be at runtime? If it did then it would not need to give any feedback (warning,errors,etc..).
Bob Stanneveld wrote:
You don't want to resolve this at runtime, but at compile time.
Which is what I am trying to do, in a compiler independent way. The feedback is in the form of text strings that must be formated based on the character type passed to the template.
Bob Stanneveld wrote:
If you use an wchar_t string when UNICODE is not defined, you get compiler errors, which is exactly what you want
That is only true if you're trying to pass those wchar_t strings to functions that require char strings. You can process wchar_t all you want in a non-UNICODE program, but you would need to convert them to a displayable form if you wish to display them. How they are converted for actual display is up to the user and is of no concern of the template, it assumes that the input character type is the type required for feedback. I would not (normally) mix char and wchar_t strings in this way, and do not expect users of this template to do so either, but if they did, a template does and should not care.
P.S. This reply would have been shorter, but CP went down for updating while I was writing it.
INTP
"The more help VB provides VB programmers, the more miserable your life as a C++ programmer becomes."
Andrew W. Troelsen
|
|
|
|
|
John R. Shaw wrote:
Keep in mind that a requirement of this project (my own), is to use standard C++ only. That is it must be totally compiler independent, it needs to be usable in any C++ environment, be it Windows, Unix, etc... .
That'll be hard to accomplish since not all compilers support the standard. It will be especially hard if you compile under visual studio 6.0, since the standard support is really terrible.
John R. Shaw wrote:
The templates use various algorithms to process text and I want it to be able to to show the steps it takes in processing, as visual feedback to user (this feature can be turned on at compile time.
I don't know how you implement this, but you can implement it as a policy. Read here[^] about policy based design.
This technique is supported by the standard, but I've had some troubles with partitial template specialization on VC6.0.
If you don't want this, you can always use an observer / observable[^] pattern. I think that using this pattern is the way to go, since you completely separate display of data from the core class. This also reduces the places where you use the preprocessor to disable the view of the data. Besides that, if you need to use a different UI to display the data, you don't have to change to core class, but you just write another observer.
John R. Shaw wrote:
Which is what I am trying to do, in a compiler independent way. The feedback is in the form of text strings that must be formated based on the character type passed to the template.
Overloading here is the way to go (if you use templates), since a compiler only compiles code that you use. So the overloaded functions that are not used (the wchar_t or the char overloads for example). If you use overloading without the templates, you have to rely on the optimizer and the linker to omit the dead functions.
John R. Shaw wrote:
That is only true if you're trying to pass those wchar_t strings to functions that require char strings. You can process wchar_t all you want in a non-UNICODE program, but you would need to convert them to a displayable form if you wish to display them. How they are converted for actual display is up to the user and is of no concern of the template, it assumes that the input character type is the type required for feedback. I would not (normally) mix char and wchar_t strings in this way, and do not expect users of this template to do so either, but if they did, a template does and should not care.
Overloading should be the key here. You can use protected or private overloads for displaying the data and call thos in your template. The compiler will automatically choose the right overload. You definitly don't wan't to do some heavy compiler magic here, since this is an easy way to accomplis this.
See this code example:
template <typename CharType,
class ObserverPolicy
>
class YourAlgorithmClass
{
public:
void AddObserver( Observer* pObs );
protected:
void SendMessageToObservers(char* pszMessage);
void SendMessageToObservers(wchar_t* pszMessage);
private:
std::vector<Observer*> m_Observers;
};
template <typename CharType, class ObserverPolicy>
void YourAlgorithmClass<CharType, ObserverPolicy>::SendMessageToObservers(char* pszMessage)
{
if( !ObserverPolicy::UseObservers() )
return;
}
class UseObservers
{
public:
static bool UseObservers() { return true; }
}
class DontUseObservers
{
public:
static bool UseObservers() { return false; }
}
I hope this enlightens you and helps you with your problem.
Behind every great black man...
... is the police. - Conspiracy brother
Blog[^]
|
|
|
|
|
how to get r, g or b value from class CColorDialog, that enter that value to glColor3f( x, y, z)??? (i want to change my opengl color object from mfc)
|
|
|
|
|