|
How is that related to your initial question about a message map entry or a virtual function for this message?
What you have quoted describes what the function usually does.
I have never used it but would expect that it is called when required (e.g. every time when reaching the line limit while typing and when "the user presses arrow keys in combination with the CTRL key to move the caret to the next word or previous word").
Have a look at the EditWordBreakProc callback function (Windows)[^]. It describes the actions passed to the callback function which indicate when it is called.
But it does not matter when it is called. You just have to return a value according to the requested action. For the case of word break checks (WB_ISDELIMITER ), the return value is usually TRUE for a space.
|
|
|
|
|
I am getting an Error while compiling `DESolver.cpp`
DESolver.cpp: In member function ‘void DESolver::Setup(double*, double*, int, double, double)’:
DESolver.cpp:57:24: error: cannot convert ‘DESolver::Best1Exp’ from type ‘void (DESolver::)(int)’ to type ‘StrategyFunction {aka void (DESolver::*)(int)}’
calcTrialSolution = Best1Exp;
Detailed Error is shown Here
Complete Code
modified 29-Jan-21 21:01pm.
|
|
|
|
|
This appears to me to be a call taking a pointer to a function - it wants a pointer and didn't getting one. Add an ampersand and see how that works for you. This is a shot in the dark though because I do not see the code in its context or the prototype declaration of the function call in question. In other words, if you had posted more of the code you would likely receive a better answer.
|
|
|
|
|
Probably the ampersand will do the trick.
|
|
|
|
|
Instead of
calcTrialSolution = Best1Exp;
you have to write
calcTrialSolution = &DESolver::Best1Exp;
(so for all case statements, of cause)
|
|
|
|
|
Thanks It worked
modified 29-Jan-21 21:01pm.
|
|
|
|
|
Hi,
I have a server client application using TCP/IP sockets in MFC VS2017. Originally i have written the code in VS2008. Kindly see the below code which sends the data to client. But this same code gives me some problem in MFC VS2017.
In the below code when I assign the value 190.000015f to a local variable, its taking the value whereas when I assign it to the union member variable
UNI.S.fTestValue1
and
UNI.S.fTestValue2
it showing some junk value. Please help me to fix the problem
unsigned char* CSendValue :: SendLiveValues()
{
union USendLive
{
struct SSend
{
float fTestValue1;
float fTestValue2;
char cChr;
}S;
unsigned char Buffer[LIVEUNISIZE];
}UNI;
memset(UNI.Buffer,0,LIVEUNISIZE);
float fLocalValue;
float fTest;
fTest = 190.000015f;
fLocalValue = fTest; UNI.S.cChr = 'c'; UNI.S.fTestValue1 = fTest; UNI.S.fTestValue2 = 190.000015f;
return UNI.Buffer;
}
|
|
|
|
|
|
D.Manivelan wrote: it showing some junk value. Where is it showing, and what value?
|
|
|
|
|
float fLocalValue;
float fTest;
fTest = 190.000015f;
fLocalValue = fTest; UNI.S.cChr = 'c'; UNI.S.fTestValue1 = fTest; UNI.S.fTestValue2 = 190.000015f;
Output
190.000015 - Correct value
'Ô' - Junk value - Wrong
6.360e-39#DEN - Junk value - Wrong
1.401e-45#DEN - Junk value - Wrong
|
|
|
|
|
Most likely you are not converting your values to/from network order when sending and receiving. See htonf function (Windows)[^].
|
|
|
|
|
The same code works fine in VS2008.
And moreover the issue occurs when I try to initialize the union member before actually sending the data to the socket.
My question is why I am not able to assign a float value to the union member which is also a float variable. This same line of code assigns the value in VS2008. Why its not doing it in VS2017
UNI.S.fTestValue1 = fTest;
UNI.S.fTestValue2 = 190.000015f;
|
|
|
|
|
Well since we have no real idea of what your code is doing to produce these bad values, it is difficult to offer any further suggestions.
|
|
|
|
|
This function returns a pointer to a local variable. If you want UNI.Buffer to continue to be accessible outside the function you have to allocate memory for it somehow.
|
|
|
|
|
Just to extend the reply of Graham Breach:
move the
union USendLive
{
struct SSend
{
float fTestValue1;
float fTestValue2;
char cChr;
}S;
unsigned char Buffer[LIVEUNISIZE];
}UNI; to the CSendValue class ctor to make the UNI a class member.
Then your CSendValue :: SendLiveValues() would look like
unsigned char* CSendValue :: SendLiveValues()
{
float fLocalValue;
float fTest;
fTest = 190.000015f;
fLocalValue = fTest;<br />
UNI.S.cChr = 'c';<br />
UNI.S.fTestValue1 = fTest;<br />
UNI.S.fTestValue2 = 190.000015f;
return UNI.Buffer;
}
|
|
|
|
|
I've been familiar with C++ for a few years now but I can't seem to think of a good solution for debugging my code. Can anyone make a suggestion?
|
|
|
|
|
|
I should probably have mentioned. It's a class file, not a full program. I'm using Visual Studio Code and the Debugger wants an executable to run but I haven't even compiled the file.
|
|
|
|
|
Then you have first to compile and link it!
BTW, is this file already a part of some project?
|
|
|
|
|
You cannot test a class file in isolation, it must be part of an executable. And if you have not even compiled it yet, you are quite a way from that step. I would suggest getting a copy of Visual Studio 2017 (free from Microsoft) and using the tools that come bundled with that.
|
|
|
|
|
Of course your code must first compile.
Then you could make a simple executable just for testing it, i.e. stressing the class features by fully using its public interface.
|
|
|
|
|
Between your subject and your post it is not clear what you want to do.
If you want to formally 'test' your code then
1. Research unit test libraries and select one
2. Add the library to your project (not part of production delivery)
3. Use the library and write unit test code to test both happy path, boundaries and failure cases.
4. Run the unit tests.
If you want to information test your code then
1. Create ANOTHER project
2. COPY your class to it
3. Add a second class with a main method
4. Write a number of methods that exercise the code.
5. Build and run it.
6. If you make changes copy it back.
If you already know the class has a problem and you cannot not determine what the problem is
1. Find a way to replicate the problem (see two above examples.)
2. As per the other posts find a debugger and figure out how it works.
3. Step through your code in the debugger to find the problem.
Note that if you have large application and you already know that your class is failing then attempting to debug the entire application just so you get to the class is not very effective.
|
|
|
|
|
Do you think is there any other or rather say faster way to remove the bug from solution! I doubt there is any. I remember when I don't know how to debug the MFC application, I used to put MessageBox to identify the pain areas. You think how many time have to run application just to point the pain location, if I know how F9,F5 and F10 work at that time, my time would be reduced by 99% in my case.
|
|
|
|
|
The good news is that this isn't a homework question or comment - I'm tossing this out to C++ veterans for some direction. I'd ask in S.O. but ugh, I'm sure I'd get shamed or start a flame war on why this is a redundant question.
I cut my development teeth on C and happily moved on to C++. I have also worked in a mixed development shop for what seems like forever. Most of the UI development is in C++ of some flavor - some variant of MS depending on what tool we need to use, other tools from other vendors. However, we're always talking to embedded systems, and most of the guys are almost always pure C developers - even if the do run it through a C++ compiler .
For the C++ code, I would love to be pure C++, especially when it comes to string handling. Current development for one side is in VS2008, and we have a mix of C++ std::wstring and CStrings (mfc). On the embedded side, usually std::wstring but mostly char bufs. I really don't care that much about the embedded side (actually I do), but I would surely love to come up with a general approach on my side.
Which leads me to the question - why is it so elephanting difficult to format a string into a buffer in standard C++? I know I can add on other libraries, but for the sake of discussion, let's say I'm not allowed to use boost, mfc, etc.
Sure, I've done my google, but it seems to me that C++ has taken purity to the level of uselessness. I'm sure I'll be burned at the stake for that, or maybe I've not found my "aha!" moment.
Charlie Gilley
<italic>Stuck in a dysfunctional matrix from which I must escape...
"Where liberty dwells, there is my country." B. Franklin, 1783
“They who can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety.” BF, 1759
|
|
|
|
|
Quote: For the C++ code, I would love to be pure C++, especially when it comes to string handling. Why would you want to avoid C library functions?
If you have a look at some STL implementations for string types, you will notice that those use C library functions like memcpy , memmove , memset , and memchr .
But you are right. I don't like the C++ string formatting too. Therefore, I never use them (besides sometimes with console output). When using other libraries like MFC, Boost, or Qt is not an option I still use [s|f][n][w]printf or the corresponding *_s versions with VS.
|
|
|
|