|
I added this line of code after the difference calculation:
AdjustWindowRectEx(&rect, m_wndToolBar.GetStyle(), FALSE, m_wndToolBar.GetExStyle());
It zeroed out the values but the same ghost blocks still remain. I can't find direct access to that variable you mentioned, any code example/tips you could point me to?
Thanks,
Chris
|
|
|
|
|
|
I found that via the class I was looking at and reading the class methods when we were looking at the rectangle offsets. I read it as it would recalc the rectangles of the toolbar and plant it, clearly I was incorrect as my result are as you mentioned...not working.
I will look at the code samples you linked to.
Thank you,
Chris
|
|
|
|
|
To check given string is Palindrome or not in Mfc c++
|
|
|
|
|
I see your randomness and raise you, "The golf course maintains a luxury garden or not."
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
It isn't really specific of MFC .
Let's say you have a string s with length L , then you just need to check if (s[i] == s[L-1-i]) evaluates true for every i in the 0, .., (L/2) range.
"In testa che avete, Signor di Ceprano?"
-- Rigoletto
|
|
|
|
|
|
|
No.
"the debugger doesn't tell me anything because this code compiles just fine" - random QA comment
"Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst
"I don't drink any more... then again, I don't drink any less." - Mike Mullikins uncle
|
|
|
|
|
First, the assignment is incomplete as you tried to post the entire thing in the subject line instead of the body of the post.
Second, no, we're not here to do your work for you. Asking for such is insulting.
If you've got questions about your your own code, fine, we can help with that, but you have to ask the questions with proper detail to answer them.
|
|
|
|
|
Does it even matter?
I suppose if you need something uniquely implemented in the new SDK, you're want to build/link against it. But if you have a basic app, why worry about it?
As a rule, do you just keep your SDK on your machine current to the latest from Microsoft?
thx
Charlie Gilley
“They who can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety.” BF, 1759
Has never been more appropriate.
|
|
|
|
|
Whatever gets installed along with Visual Studio and the compilers works for me.
|
|
|
|
|
My perception as well.
Context: so I typically have one development machine for about 4 years. The one I'm typing on is 5+ years old (dang, I need to replace). So what happens over that period of time is that I collect SDKs. I don't pay attention. But I'm trying to position code I need in a "highly secure environment" - which means its elephanting impossible to get any work done, but the IT guy promises to install what I request.
Charlie Gilley
“They who can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety.” BF, 1759
Has never been more appropriate.
|
|
|
|
|
turns out cleaning up after using a linked list isn`t as simple as I thought.
I know this is wrong but it`s the best code I was able to come up with. Any help for setting me on the correct path is appreciated.
void CleanUp(SomeNode * FrontTip)
{
SomeNode * Temp;
Temp = (SomeNode*)malloc(sizeof(SomeNode));
while(FrontTip->next != NULL)
{
Temp = FrontTip;
FrontTip = Temp->next;
free(Temp);
}
}
|
|
|
|
|
You don't need to malloc Temp : it's just a pointer. You also forgot to free it. You also didn't free the FrontTip argument if it's the only thing allocated (i.e. if its next is NULL ). I would write
while(FrontTip != NULL)
{
SomeNode* Temp = FrontTip->next;
free(FrontTip);
FrontTip = Temp;
}
|
|
|
|
|
Quote: You don't need to malloc Temp: it's just a pointer.
I couldn`t explain that bit myself either, it was probably serving for a different purpose in the article I was learning from.
Thanks for your version and your help.
modified 22-Mar-22 18:39pm.
|
|
|
|
|
To be specific about what @k5054 wrote, use std::unique_ptr [^] whenever possible. There's also shared_ptr and weak_ptr for a pointer with multiple owners (shared) or users (weak).
|
|
|
|
|
Hey Greg, there`s more than one issue in the function I posted. Like how do you go about managing a pointer that has been passed to the function.
I`ve seen this code in a codeproject article:
void NukeA(A* p)
{
p->DoThis();
p->DoThat();
delete p;
p = nullptr;
}
My thought is that this is wrong because the original pointer (the pointer being passed) remains at the gates of the function unaffected by the changes inside NukeA();
void NukeSafelyA(A** p)
{
(*p)->DoThis();
(*p)->DoThat();
delete *p;
*p = nullptr;
}
My question is how do you go about assigning a pointer to the pointer being passed or assign the pointer being passed to a new pointer that is stated/declared in the body of the function;
void NukeSafelyA(A** p)
{
(*p)->DoThis();
(*p)->DoThat();
A * Temp1;
A * Temp2;
(*p) = Temp1;
Temp2 = (*p);
delete *p;
*p = nullptr;
}
modified 24-Mar-22 12:13pm.
|
|
|
|
|
Setting a pointer to nullptr after invoking delete on it is definitely recommended. Or in C, setting it to NULL after invoking free . To do it, pass the pointer by reference:
void NukeSafelyA(A*& p)
{
p->DoThis();
p->DoThat();
delete p;
p = nullptr;
}
|
|
|
|
|
Us old-school C programmers tend to forget about the existence of references. Well done, Greg. That's far cleaner than the pointer-to-pointer version the OP presented, but does exactly the same thing.
To the OP:
On the whole though, except as a learning exercise, and some really rare, odd cases, the STL should be the way to go. It's likely to be safer, perhaps faster, and certainly far better tested than your own implementation. The STL should be part of your basic tool kit for C++ programming.
Keep Calm and Carry On
|
|
|
|
|
Thanks guys. As you lean stuff, you begin to understand things that you previously heard about but never really understood. I`m taking the std pointers as a new horizon, at this point I feel that they are remote from where I am. I`ll be using the default c++ approach.
|
|
|
|
|
I am using a property sheet for my app to adjust the options and GUI elements. When the file opens, the app has two tabs created via Addview and all of that is working. OnInitialUpdate sets the styles because it uses the registry settings when it starts. What I'm trying to do is have the styles adjust on an OnApply when the user selects the style they want. I have the OutputPane working correctly which is shown in the code below. What I can't get to work is to have the document tabs change on a Recalc/Redraw .
BOOL CSettingsUserTabs::OnApply()
{
BOOL bResult = CMFCPropertyPage::OnApply();
if (bResult)
{
AfxGetApp()->WriteProfileInt(_T("Settings"), _T("UserTabStyle"), m_style_tabs);
((CMainFrame*)AfxGetMainWnd())->m_wndOutput.m_wndTabs.ModifyTabStyle((CMFCTabCtrl::Style)m_style_tabs);
((CMainFrame*)AfxGetMainWnd())->m_wndOutput.m_wndTabs.RecalcLayout();
CMFCTabCtrl& MDI_STYLES = ((CMainFrame*)AfxGetMainWnd())->GetMDITabs();
MDI_STYLES.ModifyTabStyle((CMFCTabCtrl::Style)m_style_tabs);
MDI_STYLES.RecalcLayout();
CMDIFrameWndEx* pMainFrame = DYNAMIC_DOWNCAST(CMDIFrameWndEx, GetTopLevelFrame());
pMainFrame->SetFocus();
pMainFrame->RecalcLayout();
}
return bResult;
}
Any ideas what I can do solve this problem? I've scoured the net for examples on how to solve this issue and yet to get it to work. There is a TabControl solution in the Microsoft master repository to show how it works, but since I'm using a propertysheet to control it, the example does work but the example doesn't use the AddView so I can't use it as a good example.
Here is the code that loads the RUNTIME_CLASSES where the tabs are created:
void CMovieView::OnInitialUpdate()
{
AddView(RUNTIME_CLASS(CTabView1), AfxStringID(IDS_TAB1));
AddView(RUNTIME_CLASS(CTabView2), AfxStringID(IDS_TAB2));
GetTabControl().EnableTabSwap(TRUE);
GetTabControl().SetLocation(CMFCBaseTabCtrl::Location::LOCATION_TOP);
GetTabControl().EnableAutoColor(TRUE);
int UserTabStyle = AfxGetApp()->GetProfileInt(_T("Settings"), _T("UserTabStyle"), 0);
if (UserTabStyle != FALSE && UserTabStyle <= 8) {
int EnumUserTabStyle = UserTabStyle - 1;
GetTabControl().ModifyTabStyle(static_cast<CMFCTabCtrl::Style>(EnumUserTabStyle));
}
else {
GetTabControl().ModifyTabStyle(CMFCTabCtrl::STYLE_FLAT);
}
CTabView::OnInitialUpdate();
}
This works on creation, I can't get it to work when the OnApply() is used because you can't recall OnInitialUpdate for something already created. I can't seem to get GetTabControl() to work after on create as a separate function....so I'm unclear on how to solve this problem. Does anyone have any ideas on how I can modify my code to get it working?
Thanks,
Chris
|
|
|
|
|
I hope it is ok to put LAST action first -
0 attempt to bypass what has been done /said so far .
This is a result of all discussions so far .
I have modified the call by adding "std:bind" . That bypasses the limits of passing five parameters to the QtConcurrent.
The suspected issue of passing the pointers now generate several errors.
I am trying to analyze one of them , posted here.
Could use some help doing that.
// hci_inquiry as extern function with arguments
//hci_inquiry(int dev_id, int len, int num_rsp,
//const uint8_t *lap, inquiry_info **ii, long flags);
QFuture<int> future_hci = QtConcurrent::run(
std::bind(
hci_inquiry,
dev_id,
len,
num_rsp,
lap,
ii,
flags));
This error reports the result of wrong "type" , however I do not see which of the passed parameters is syntactically wrong - hence wrong " type ".
This is the first error in compiler output - there are 10 of them all saying wrong "type " is passed in .
/usr/include/c++/11/functional:464: error: no type named ‘type’ in ‘struct std::result_of<int (*&(int&,="" int&,="" const="" unsigned="" char*&,="" inquiry_info*&,="" int&))(int,="" int,="" char*,="" inquiry_info**,="" long="" int)="">’
/usr/include/c++/11/functional:498:9: required from ‘void QtConcurrent::StoredFunctorCall0<t, functionpointer="">::runFunctor() [with T = int; FunctionPointer = std::_Bind<int (*(int,="" int,="" const="" unsigned="" char*,="" inquiry_info*,="" int))(int,="" inquiry_info**,="" long="" int)="">]’
../../../QT/15/5.15.2/gcc_64/include/QtConcurrent/qtconcurrentstoredfunctioncall.h:60:10: required from here
/usr/include/c++/11/functional:464:15: error: no type named ‘type’ in ‘struct std::result_of<int (*&(int&,="" int&,="" const="" unsigned="" char*&,="" inquiry_info*&,="" int&))(int,="" int,="" char*,="" inquiry_info**,="" long="" int)="">’
464 | using _Res_type_impl
| ^~~~~~~~~~~~~~
..and this is the last error
/usr/include/c++/11/functional:464: error: no type named ‘type’ in ‘struct std::result_of<int (*="" const="" volatile&(const="" volatile="" int&,="" unsigned="" char*="" volatile&,="" inquiry_info*="" int&))(int,="" int,="" char*,="" inquiry_info**,="" long="" int)="">’
/usr/include/c++/11/functional:540:9: required from ‘void QtConcurrent::StoredFunctorCall0<t, functionpointer="">::runFunctor() [with T = int; FunctionPointer = std::_Bind<int (*(int,="" int,="" const="" unsigned="" char*,="" inquiry_info*,="" int))(int,="" inquiry_info**,="" long="" int)="">]’
../../../QT/15/5.15.2/gcc_64/include/QtConcurrent/qtconcurrentstoredfunctioncall.h:60:10: required from here
/usr/include/c++/11/functional:464:15: error: no type named ‘type’ in ‘struct std::result_of<int (*="" const="" volatile&(const="" volatile="" int&,="" unsigned="" char*="" volatile&,="" inquiry_info*="" int&))(int,="" int,="" char*,="" inquiry_info**,="" long="" int)="">’
464 | using _Res_type_impl
| ^~~~~~~~~~~~~~
ORIGINAL POST
I hope I can describe the problem.
This is a variation on "time consuming process".
The tool (object) I am using can initialize and run another thread to process
such time consuming task.
The function running the task is "extern" and its name and parameters are passed to the object.
That works fine when such extern function is declared / defined locally.
(when the function is defined locally and the parameter passed have no defined value - compiler complains...good)
The function I like to use is part of compiled library,
hence no (local /extern) source code.
Can I do this - without the source code ?
modified 22-Mar-22 10:01am.
|
|
|
|
|
I'm net entirely clear on what you're trying to do.
Normally, a library that is expected to be used by a developer is supplied with a header file that describes the contents of the library, that is #includ ed in the source file of user created software. That's what stdio.h or iostream do for you. If at all possible, you should look for the developer tools for your library and use the supplied headier.
Alternatively - and this is only as a last resort for the well-informed and foolhardy, there's no reason you can't declare the function in your own source code. But, you really have to know what the function signature is. If you have a mismatch, then you're almost certainly going to invoke Undefined Behavior, and then all bets about the validity of anything your program produces is suspect.
So for example, we know that the signature for a cosine function in the c standard library is double cos(double x; . Now normally we would write
#include <math.h>
double val = cos(2.5);
But it's perfectly valid to write
double cos(double x);
double val = cos(2.5);
But as I state above, you need to be sure that you've got the right signature for your function. If for example we were to write
double cos(int x); double val = cos(2.5)
/ ... Then the compiler will convert the 2.5 to an integer (e.g. a 4 byte value containing the value 0x02), and then pass that to the math library cos() function. On the library side, the code is expecting a double (e.g an 8 byte value in IEEE floating point format), so it will dutifully use the top 8 bytes of the stack for the value to calculate the cosine for. As you can see, we've only put 4 bytes on the stack in our call, and so half the data its using to calculate is, in essence, random data. Clearly, in this case we can't rely on what value cos() returns to us.
This is not the same as passing an int to cos() that has been properly declared. In that case, the compiler knows that the cos() function is expecting a double as its argument, so it provides a conversion from int to double at compile time.
Keep Calm and Carry On
|
|
|
|
|
I was afraid my description will be poor..,.,
So here is a code snippet.
I am posting it for info only - I had to move stuff around to get a single shot - so it will probably not compile.
The primary task of my test QtConcurrent (cFunction) is to build a new thread and run it
QFuture<int> future_c = QtConcurrent::run(cFunction, param);
QtConcurrent::run does build a new thread and runs cFunction with passed param and returns such param. Works as expected.
Now I want to do same for hci_inquiry function.
That is where I am stuck.
1. do I have to do this ?
extern int hci_inquiry(int dev_id, int len, int num_rsp, const uint8_t *lap, inquiry_info **ii, long flags);
2. do I have to "define " hci_inguiy at all ?
I can execute hci_inquiry as "plain" function - but it takes up to 30 seconds to complete and QT does not like that - in my view it gets stuck in some "event loop " - no good.
3. if I "declare "
extern int hci_inquiry(int dev_id, int len, int num_rsp, const uint8_t *lap, inquiry_info **ii, long flags);
it sort of passes compiler but I get error saying that "run" does not exists.
This is where my statement about "ducks" came from
I do not know if I am not writing the parameters correctly or the "declaration" of the function is wrong.
4. Compiler will not compile if passed parameters have not been defined , hence have no values assigned to them. I do not get that error with hci_inquiry, but the missing "RUN" may mask that - again are the ducks all there ?
Again - this is test code - not intended to compile and run.
I am NOT asking about QT - I just do not get why the "run" won't process hci_inquiry function.
int cFunction(int param )
{
qDebug() <<" TEST QtConcurrent c Function ";
return 10*param;
};
int param = 5;
extern int cFunction(int param);
QFuture<int> future_c = QtConcurrent::run(cFunction, param);
int TESTResult = future_c.result();
qDebug() <<" END RUN TEST QtConcurrent a Function ";
QFuture<int> future_hci = QtConcurrent::run(
hci_inquiry,
dev_id,
len,
num_rsp,
lap,
ii,
flags);
aDDENDUM
NO MATCHING FUNCTION FOR CALL TO 'RUN"
IS THE actual error message
MORE ADDEEDUM
This is QT QConcurrent run example I am copying
extern void aFunctionWithArguments(int arg1, double arg2, const QString &string);
int integer = ...;
double floatingPoint = ...;
QString string = ...;
QFuture<void> future = QtConcurrent::run(aFunctionWithArguments, integer, floatingPoint, string);
My parameters are definitely wrong , I am not sure how to "code / syntax " the single and double pointers.
modified 21-Mar-22 23:02pm.
|
|
|
|
|