|
I'm not sure I understand. If the variables you called dl and dr are part of your code, then surely it is in your hands how to define and use them? If any code breaks, it is an indication that code was bad to start with. I'm not surprised though: there must have been a reason for the odd malloc statements, and my suspicion, as stated before, is that someone uses these pointers not as pointer to some struct array, but as a pointer to some meta-struct: see my other posting with a suggestion how to declare such a struct.
If you don't fix that broken code, it won't be clean. And reinterpret_cast does not fix anything. It only makes your code compile, but it doesn't make it work, much less clean.
I do not suggest to fix or change the structs hci_dev_req and hci_dev_list_req themselves, only the code using them. That code defines variables called dl and dr, and the way these are allocated currently indicates that code is broken and needs to be fixed. And that includes any code that uses dl and dr.
If for some reason you can't get std::array to work even though it does not require C++11, you could try std::vector instead: the main difference is that std::vector does not require the size to be known at compile time, and it can be resized dynamically. If HCI_MAX_DEV is a constant, std::array should work just fine; otherwise you need std::vector.
Of course, you can't pass a std::array into ioctl where it requires a hci_dev_list_req - you first need to convert it. That is not unusual for modern C++ code using old C APIs: in such cases you need some helper or wrapper functions that perform these conversions under the hood.
If you want to avoid these conversions, then the task you're asking for is an entirely different one - you should have stated that much from the beginning. Then we could have told you that it's not a good idea to transport a hackish C struct into C++ code and expect the resulting code to be 'clean'.
GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto)
|
|
|
|
|
P.S.: Based on this code segment:
struct hci_dev_list_req *dl;
struct hci_dev_req *dr;
int dev_id = -1;
int i, sk, err = 0;
dl = malloc(HCI_MAX_DEV * sizeof(*dr) + sizeof(*dl));
I suggest the following struct definition:
struct hci_meta {
std::array<hci_dev_req,HCI_MAX_DEV> my_hci_list;
hci_dev_req& operator[](int i) {
return my_hci_list[i];
}
hci_dev_list_req my_hci_req;
};
void foo() {
hci_meta dl; hci_dev_list* dr = dl.my_hci_req;
...
hci_dev_req current_dev_req = dl[i]; ...
}
No need for allocation, deallocation, or typedefs unless you have additional requirements you haven't mentioned yet.
P.S.: since the array in this case is embedded inside a struct, you could use a standard C array instead:
struct hci_meta {
hci_dev_req my_hci_list[HCI_MAX_DEV];
hci_dev_req& operator[](int i) {
return my_hci_list[i];
}
hci_dev_list_req my_hci_req;
};
GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto)
modified 10-Dec-19 2:57am.
|
|
|
|
|
Richard
I knew it had something to do with storage when I looked at cb it was only 4096 bytes 0XFFE
Had a global counter count the number of bytes I uploaded it was 0X16F67A I set LimiText to 0x16f770 and was able to type in the Rich Edit Control
Thanks
|
|
|
|
|
If this is meant as a response to a problem reeported somewhere on this site, please use the appropriate links to post a comment/reply/solution right there, not in some random forum!
GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto)
|
|
|
|
|
It’s the thread immediately below.
|
|
|
|
|
I streamed in text into a rich edit control To make it align I set SetDefaultCharFormat to Courier New the ES_READONLY flag is not in resource definition file for this control is there an way to modify the text
Thanks
|
|
|
|
|
Your post is somewhat unclear. Please explain in more detail what the problem is with modifying the text of an edit control.
|
|
|
|
|
Let me be specific I am writing a debugger and stream in the program listing. On the left hand side I have a one byte area for the user to in put a command like ‘B’ for breakpoint
Thanks
|
|
|
|
|
Very interesting, in a non-specific way. I am sure you do have a specific question, but I have no idea what it is.
|
|
|
|
|
I stream in the program TEXT from the Z/OS Assembler SYSADATA I then did SEL(0,-1) and changes it to RTF Courier New before displaying it, I would like to enter text
for example here is a line "_ 204 00004A LA R4,QDINIT " Where the Hyhpen is I would like to let the user enter a letter "B' but the entire text is protected
I have been doing research and it seems with the setevnetmask with a notification for a change I would get an en_chnage message and the doc says it I return 0 another message gets sent I am wondering if I
process this message would be able get to set the text modify (for example the B) it. Don't know if I am on the right track with this. All I really want to do is let the user enter text in this now RTF
richedit this should be possible after all Word is an RTF editor and you can modify the text even if its Rich Text (formatted with fonts)
Thanks
|
|
|
|
|
No idea what is happening there. I have used RichEdit controls and never had such a problem. Try a straightforward RichEdit control and don’t do anything to modify its settings to see what happens.
|
|
|
|
|
thanks that's all I was looking for from the way you see it I should be able to modify the text, I did a SetWindowText to the Richedit e.g. this is a test message and was able to type in it the rich edit control
thanks for your help if from the way you see it I should be able to modify the text Ill research the problem
|
|
|
|
|
Hi ,
can u please help me to read XLSX file without office automation
i read XLS file using ODBC Driver.
but XLSX file read by this driver not found please help me how can do this.
thanks for any help and guidance in advance
|
|
|
|
|
|
|
thanks for reply
but i want to ask one thing these .Net dll can use in my mfc VC++ application.
|
|
|
|
|
Whoops! Sorry, I thought this was a C# question.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
its ok plz provide me any help for my mfc vc++ application
|
|
|
|
|
In the past for just basic files I have used
GitHub - brechtsanders/xlsxio: XLSX I/O - C library for reading and writing .xlsx files[^]
Note the 3 limitations
1.) assumes the first row contains header names
2.) assumes the next rows contain values in the same columns as where the header names are supplied
3.) only values are processed, anything else is ignored (formulas, layout, graphics, charts, ...)
CSV has easily become the more normal interchange and as its as simple as "save as" in excel it's rare anyone bothers with raw excel file anymore. They can do all there fancy graphs etc in excel itself and just export the data
In vino veritas
|
|
|
|
|
|
Le@rner wrote: ...but XLSX file read by this driver not found What exactly is this supposed to mean?
"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 means what it says
He has a current version of Excel but the XLSX file is from and older version and that earlier driver isn't installed on the machine.
Microsoft ODBC drivers simply call prior version drivers to load older version XLSX files they don't of themselves read older versions.
The message is correct even if a bit humorous
Now ask me the real funny question can you tell what version an xlsx file was created from
Well yeah if you have HexEditor the BIFF in the beginning of file header will have a tag XL9, XL10, XL12 etc.
Find that old Driver, Download that driver, install and you are away .. simple for an end user hey
In vino veritas
|
|
|
|
|
I've been working on this for a few days and I can't seem to get it. I just want to load a bitmap from file, resize it, then attach it to a CImageList obj via the Add() Member function.
I'm using LoadImage() to load the bitmap into memory from disk.
HBITMAP hbmp = (HBITMAP) ::LoadImage(..) ;
I can display the bitmap just fine using pDC->DrawState(…, , hbmp);
I've tried creating a memoryDC and a Compatible Bitmap like this:
HDC hClientDC = GetDC()->m_hDC;
HDC hMemDC = NULL;
HBITMAP hMemBitmap = NULL;
//create compatible memory area
hMemDC = CreateCompatibleDC(hClientDC);
hMemBitmap = CreateCompatibleBitmap(hMemDC, cx, cy);
But, then I can't seem to copy anything into it. I'm a noob, so I'm just lost here.
Can anyone help?
EW.
|
|
|
|
|
|