|
I like to bypass some of the Bluetooth "resources" in my C / C++ code by using (direct) system calls.
I can czech for return value, but like to analyze more of the output, in including errors.
Where do I start ?
Contrary to my opinion ( about RTFM ) - can somebody give me link to "RTFM" how to do it ?
system(" hcitool dev");
return to stdout (?)
Devices:
hci1 00:50:B6:80:4D:5D
hci0 00:15:83:15:A2:CB
|
|
|
|
|
Rather than system(), you want to use popen(). The only problem is that popen() doesn't supply a separate FILE for stderr, so you have to use output redirection to capture both e.g.
FILE *cmd = popen("hcitool dev 2>&1", "r");
char *buffer = NULL;
size_t len = 0;
ssize_t readlen;
while ( (readlen = getline(&buffer, len, cmd)) > 0)
{
}
free(buffer);
pclose(cmd);
You could perhaps also use output redirection to capture output separately e.g.
FILE *cmd = popen("hcitool dev 2>/tmp/hcierrs", "r");
FILE *cmd_errs = fopen("/tmp/hcierrs", "r");
unlink("/tmp/hcierrs"); If you're going to do that, you might want to look at creating unique temporary file names, so that you don't clobber output if you happen to have more than one instance of the program running at the same time. mkstemp() can help you here.
For the really advanced, you might look into trying "roll your own" version of popen that uses fork() and one of the exec() functions to separate out stdout and stderr to two separate FILES.
Keep Calm and Carry On
|
|
|
|
|
I am using an outlook bar style property sheet with 3 property pages as the main window of my application.I am unable to change the tab icons displayed on the property sheet.Please suggest any strategy to change the icons.I have gone through all the documentation related to property sheets
and also googled but I couldn't get a solution. I have code which is not working and will post it if required.
Deekonda Ramesh
modified 21-Oct-21 3:19am.
|
|
|
|
|
|
SetIconsList works only once before the call to DoModal() on the property sheet. When It called a second time it asserts in afxpropertysheet.cpp : at line ENSURE(m_Icons.GetSafeHandle()==NULL).
Deekonda Ramesh
|
|
|
|
|
In such a case I'd recommend to subclass the CMFCPropertySheet (derive your own class from it) and overload the SetIconsList method. Or better implement the new method (say, ReplaceIcon) that would directly manipulate (remove/add/replace an image) with the m_Icons imagelist.
|
|
|
|
|
I have derived a class from CMFCPropertySheet and I changed m_Icons member with the new bitmaps.It does not show any change in the displayed icons/bitmaps.
Deekonda Ramesh
modified 22-Oct-21 12:38pm.
|
|
|
|
|
Then investigate the afxpropertysheet.cpp (and probably some more (friend and other classes) source code to see where and how the m_Icons imagelist is involved and try to change it according to your needs!
|
|
|
|
|
CMFCPropertySheet has a member called m_wndPane1. Following approach also did not work. Button images are jumbled up
m_wndPane1.RemoveAllButtons();
m_wndPane1.ClearAll();
retval=m_wndPane1.AddButton(m_bmpimgs[0], "Create a Job", 10050, 0);
retval=m_wndPane1.AddButton(m_bmpimgs[1], "Manage a Job", 10051, 1);
retval=m_wndPane1.AddButton(m_bmpimgs[2], "Restore a Job", 10052, 2);
m_wndPane1.InvalidateButton(0);
m_wndPane1.InvalidateButton(1);
m_wndPane1.InvalidateButton(2);
Deekonda Ramesh
|
|
|
|
|
Got the answer mostly due to Microsoft Q&A This code placed in the derived property sheet works if the bitmap images are all of exactly the same size Thanks also to Victor Nijegorodov for his suggestions:
m_wndPane1.RemoveAllButtons();
retval=m_wndPane1.AddButton(m_bmpimgs[0], "Create a Job", 10050, 0);
retval=m_wndPane1.AddButton(m_bmpimgs[1], "Manage a Job", 10051, 1);
retval=m_wndPane1.AddButton(m_bmpimgs[2], "Restore a Job", 10052, 2);
m_wndPane1.InvalidateButton(0);
m_wndPane1.InvalidateButton(1);
m_wndPane1.InvalidateButton(2);
Deekonda Ramesh
|
|
|
|
|
|
I thought it might be faster getting an answer in the discussions.
Deekonda Ramesh
|
|
|
|
|
No, it just means duplicated effort, please use one place only.
|
|
|
|
|
I am trying to load a bit map its in my res folder in fact I have also copied it folder where my .exe is it fail to load
Here is My rc statement
IDB_BITMAP1 BITMAP "res\\bitmap1.bmp"
and I do a CBitmap.LoadBitmap(IDB_BITMAP1); The return code is 0 The Documentations says Quote: by the ID number in nIDResource from the application's executable file.
does that mean I have to link the application a certain way
thanks
|
|
|
|
|
- Are you sure the bitmap IDB_BITMAP1 is really included in your .exe? (try to load the .exe as a resource in VS and proof it).
- Did you try to use LoadImage instead?
- What does the GetLastError return if the loading fails?
|
|
|
|
|
What do you mean 'included in your .exe' I did try the load image and it failed
I am not really sure what you mean by 'try to load the .exe as a resource' does the bitmap have to be linked into the .exe
|
|
|
|
|
ForNow wrote: I am not really sure what you mean by 'try to load the .exe as a resource' does the bitmap have to be linked into the .exe
Just open your VS, then Menu -> File -> Open -> find in the open file dialog (File Explorer) your .exe file -> open it!
Then you will see the tree with all the embedded resources. Just navigate to the Bitmap hive and ensure that the bitmap with your bitmap ID does exist!
|
|
|
|
|
Yes it see it there are the resource numbers of my bitmaps my questions is then the following
Quote: BREAKPOINT BITMAP "C:\\DriveRichEdit\\DriveRichEdit\\DriveRichEdit\\res\\bullet_red.bmp"
IDR_MAINFRAME BITMAP "res\\Toolbar.bmp"
IDB_BITMAP1 BITMAP "res\\bitmap1.bmp"
I have tried various strings 1) full path name of where the bitmap resides as indicated by my first entry 2) partial as indicated by my second entry "res\\Toolbar.bmp" would you know the correct entry
thanks
|
|
|
|
|
ForNow wrote: would you know the correct entry
According your OP it should be:
ForNow wrote: Here is My rc statement
IDB_BITMAP1 BITMAP "res\\bitmap1.bmp"
|
|
|
|
|
I re-checked the doc and it say I can put in the full path name of the bitmap going to do that I’ll also do a getlasterror if RC _!= 0
Thanks
|
|
|
|
|
You should not need to as the location is only required by the compiler when it builds the executable. Part of the build process is to embed all resources into the final executable. You can check it by getting hold of one of the many free resource editors available online.
|
|
|
|
|
so the bitmap is in the exe I google and see a product Resource tuner maybe i should try it see if it finds the bitap and maybe the problem is I didn't link it in right with the res file
thanks
|
|
|
|
|
I have never encountered a project where the resources did not get included correctly. In fact I just ran a quick test and it worked fine.
|
|
|
|
|
Did a Cimage load the HRESULT was 0 did CBitmap::Attach (there is not documentation on this) but return code was 1 when I looked at the n_hObject in VS debugger it had high order X'FF' the handle was FFFFFFFF88052070 never saw a resource handle with high order X'FF' ITS usually zeros
|
|
|
|
|
- "the HRESULT was 0" (S_OK) means the function completed successfully.
- "(there is not documentation on CBitmap::Attach)". However, there is a documentation on its base class method: CGdiObject Class | Microsoft Docs
|
|
|
|