|
Apologies for the shouting but this is important.
When answering a question please:
- Read the question carefully
- Understand that English isn't everyone's first language so be lenient of bad spelling and grammar
- If a question is poorly phrased then either ask for clarification, ignore it, or mark it down. Insults are not welcome
- If the question is inappropriate then click the 'vote to remove message' button
Insults, slap-downs and sarcasm aren't welcome. Let's work to help developers, not make them feel stupid.
cheers,
Chris Maunder
The Code Project Co-founder
Microsoft C++ MVP
|
|
|
|
|
For those new to message boards please try to follow a few simple rules when posting your question.- Choose the correct forum for your message. Posting a VB.NET question in the C++ forum will end in tears.
- Be specific! Don't ask "can someone send me the code to create an application that does 'X'. Pinpoint exactly what it is you need help with.
- Keep the subject line brief, but descriptive. eg "File Serialization problem"
- Keep the question as brief as possible. If you have to include code, include the smallest snippet of code you can.
- Be careful when including code that you haven't made a typo. Typing mistakes can become the focal point instead of the actual question you asked.
- Do not remove or empty a message if others have replied. Keep the thread intact and available for others to search and read. If your problem was answered then edit your message and add "[Solved]" to the subject line of the original post, and cast an approval vote to the one or several answers that really helped you.
- If you are posting source code with your question, place it inside <pre></pre> tags. We advise you also check the "Encode HTML tags when pasting" checkbox before pasting anything inside the PRE block, and make sure "Ignore HTML tags in this message" check box is unchecked.
- Be courteous and DON'T SHOUT. Everyone here helps because they enjoy helping others, not because it's their job.
- Please do not post links to your question in one forum from another, unrelated forum (such as the lounge). It will be deleted.
- Do not be abusive, offensive, inappropriate or harass anyone on the boards. Doing so will get you kicked off and banned. Play nice.
- If you have a school or university assignment, assume that your teacher or lecturer is also reading these forums.
- No advertising or soliciting.
- We reserve the right to move your posts to a more appropriate forum or to delete anything deemed inappropriate or illegal.
cheers,
Chris Maunder
The Code Project Co-founder
Microsoft C++ MVP
|
|
|
|
|
Hello
I am looking for c++ code to capture all the ip packets. I want to capture the original packet not taking a copy from this packet. In other words I don’t want windows to capture this packet. My program should be the only entity that will read this packet.
|
|
|
|
|
In that case you will need to write a network driver and install it in the kernel. And it is unlikely that anyone here will offer to help you as code such as you describe is exactly the sort of thing that hackers and scammers would use.
|
|
|
|
|
Thank you for your reply. As a mater of fact this would s an academic project next o am trying to do to write a small firewall.
What if rephrase the question to lookf or to capture frames from NIC?
|
|
|
|
|
Well either way this is a research issue. You should google for likely candidates of sample code to help to do what you want. There are already applications available that can capture the internet packets (e.g. Wireshark · Go Deep[^] ), and maybe that would be a good place to start.
|
|
|
|
|
How to get the title of CPropertyPage before create CPropertySheet:
CPropertyPage somePage;
CPropertySheet m_sheet;
TRACE(_T("Adding page '%'\n"), somePage.GetTitle());
m_sheet.AddPage(&somePage);
...
m_sheet.Create(....);
|
|
|
|
|
You cannot get title because you didn't set it.
Use overloaded CPropertyPage ctor that accepts the caption Id parameter.
If the string with this caption Id exists then it will be stored in the
PROPSHEETPAGE m_pPSP structure (in its LPTSTR m_psp.pszTitle member) that is the member of the CPropertyPage class.
Then you could do:
CString title = somePage.GetPSP().pszTitle;
|
|
|
|
|
This doesn't work because this structure will only become valid after the CPropertyPage is created, not before. Before creation pszTitle is empty
|
|
|
|
|
This code works as expected:
CPropertyPage myPage(IDD_PROPPAGE_SMALL, IDS_STRING_CAPTION);
text.Format(_T("Property page title:\t%s"), myPage.GetPSP().pszTitle);
AfxMessageBox(text);
where
IDD_PROPPAGE_SMALL - property page dialog template,
IDS_STRING_CAPTION - string resource with the text "My Property page Title"
Messagebox shows the text "My Property page Title".
|
|
|
|
|
The CPropertyPage object is created during its construction, not when it is added to the sheet. Since you constructed it without a title, a title you cannot retrieve.
"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
|
|
|
|
|
Hi,
How can i build my x86 project in my x86 PC with VS2022 installed for ARM?.
|
|
|
|
|
|
I meant building for ARM from an Intel PC with VS2022.
modified 25-Sep-24 23:04pm.
|
|
|
|
|
I'm exploring Win32's HID API to read/write from/to various devices.
So far, I've been able to read responsive input for two wired devices -- an XBOX 360 Compliant controller and a steering wheel.
This is good, but buffers filled by reading Bluetooth HID devices with ReadFile are not updating with user input. I've been able to test two devices: an Xbox One Wireless Controller(VID=045E,PID=02E0), and an Xbox One S Controller [Bluetooth](VID=045E,PID=02FD).
What could be causing this? Are there any specific things that must be done before/while reading a Bluetooth HID device?
Some notes:
• RawInput does not seem to be usable without a window(i.e., in a pure console program), since it requires WM_INPUT messages to function.
• XInput seems to exclusively support Xbox controllers. May use it for Xbox controllers specifically(especially for trigger separation).
• Have not explored DirectInput for controllers yet. Unsure if it's useable for modern controllers(including bluetooth-based ones).
Here's the current code setup.
Code notes:
• The end goal is to read/write inputs for real-time programs(e.g., games).
• Tangentially, I'm not very experienced with Win32 and its file handling, so there's probably some issues with the general usage.
Code of interest
if(isXOneX){
HANDLE deviceHandle = CreateFile(devicePath,GENERIC_READ|GENERIC_WRITE,FILE_SHARE_READ|FILE_SHARE_WRITE,NULL,OPEN_EXISTING,FILE_FLAG_OVERLAPPED,NULL);
PHIDP_PREPARSED_DATA preparsedData;
HidD_GetPreparsedData(deviceHandle,&preparsedData);
HIDP_CAPS caps;
HidP_GetCaps(preparsedData,&caps);
HIDP_BUTTON_CAPS hidpButtonCaps[caps.NumberInputButtonCaps];
HidP_GetButtonCaps(HIDP_REPORT_TYPE::HidP_Input,&hidpButtonCaps[0],&caps.NumberInputButtonCaps,preparsedData);
DWORD reportId = hidpButtonCaps[0].ReportID;
auto inputReportBufferLength = caps.InputReportByteLength+1; BYTE inputReportBuffer[inputReportBufferLength];
while(true){
OVERLAPPED overlapped;
memset(&overlapped, 0, sizeof(overlapped));
if(ReadFileEx(deviceHandle, &inputReportBuffer[0], inputReportBufferLength, &overlapped, NULL)){
DWORD bytesTransferred;
if(GetOverlappedResult(deviceHandle, &overlapped, &bytesTransferred, FALSE)){
for(auto i=0;i<inputReportBufferLength;i++){
std::cout << std::setfill('0') << std::setw(3) << (INT)inputReportBuffer[i] << " ";
}
std::cout << std::endl;
}
}
else{
CancelIo(deviceHandle);
}
}
HidD_FreePreparsedData(preparsedData);
CloseHandle(deviceHandle);
}
free(deviceInterfaceDetailData);
Full code(without error prints)
#include <iostream>
#include <initguid.h>
#include "windows.h"
#include "setupapi.h"
#include <hidclass.h>
#include <hidsdi.h>
#include <iomanip>
int main(){
auto hDevInfo = SetupDiGetClassDevs(&GUID_DEVINTERFACE_HID,NULL,NULL,DIGCF_PRESENT|DIGCF_DEVICEINTERFACE);
if(hDevInfo != INVALID_HANDLE_VALUE){
auto success = true;
auto i = 0;
while(success){
auto deviceInterfaceData = SP_DEVICE_INTERFACE_DATA();
deviceInterfaceData.cbSize = sizeof(SP_DEVICE_INTERFACE_DATA);
success = SetupDiEnumDeviceInterfaces(hDevInfo,NULL,&GUID_DEVINTERFACE_HID,i,&deviceInterfaceData);
if(success){
SP_DEVICE_INTERFACE_DETAIL_DATA* deviceInterfaceDetailData = NULL;
DWORD requiredSize = 0;
auto detailSizeSuccess = SetupDiGetDeviceInterfaceDetail(hDevInfo,&deviceInterfaceData,NULL,0,&requiredSize,NULL);
deviceInterfaceDetailData = (SP_DEVICE_INTERFACE_DETAIL_DATA*)calloc(requiredSize,sizeof(byte));
deviceInterfaceDetailData->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA);
auto devInfoData = SP_DEVINFO_DATA();
devInfoData.cbSize = sizeof(SP_DEVINFO_DATA);
deviceInterfaceDetailData->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA);
auto detailSuccess = SetupDiGetDeviceInterfaceDetail(hDevInfo,&deviceInterfaceData,deviceInterfaceDetailData,requiredSize,&requiredSize,NULL);
auto devicePath = deviceInterfaceDetailData->DevicePath;
auto isX360 = strstr(devicePath,"vid_045e&pid_028e");
auto isWheel = strstr(devicePath,"vid_044f&pid_b655");
auto isXOneX = strstr(devicePath,"vid_045e&pid_02e0"); auto isXOne = strstr(devicePath,"vid_045e&pid_02d1");
auto isXOneS = strstr(devicePath,"vid_045e&pid_02fd"); if(isXOneX){
HANDLE deviceHandle = CreateFile(devicePath,GENERIC_READ|GENERIC_WRITE,FILE_SHARE_READ|FILE_SHARE_WRITE,NULL,OPEN_EXISTING,FILE_FLAG_OVERLAPPED,NULL);
PHIDP_PREPARSED_DATA preparsedData;
HidD_GetPreparsedData(deviceHandle,&preparsedData);
HIDP_CAPS caps;
HidP_GetCaps(preparsedData,&caps);
HIDP_BUTTON_CAPS hidpButtonCaps[caps.NumberInputButtonCaps];
HidP_GetButtonCaps(HIDP_REPORT_TYPE::HidP_Input,&hidpButtonCaps[0],&caps.NumberInputButtonCaps,preparsedData);
DWORD reportId = hidpButtonCaps[0].ReportID;
auto inputReportBufferLength = caps.InputReportByteLength+1; BYTE inputReportBuffer[inputReportBufferLength];
while(true){
OVERLAPPED overlapped;
memset(&overlapped, 0, sizeof(overlapped));
if(ReadFileEx(deviceHandle, &inputReportBuffer[0], inputReportBufferLength, &overlapped, NULL)){
DWORD bytesTransferred;
if(GetOverlappedResult(deviceHandle, &overlapped, &bytesTransferred, FALSE)){
for(auto i=0;i<inputReportBufferLength;i++){
std::cout << std::setfill('0') << std::setw(3) << (INT)inputReportBuffer[i] << " ";
}
std::cout << std::endl;
}
}
else{
CancelIo(deviceHandle);
}
}
HidD_FreePreparsedData(preparsedData);
CloseHandle(deviceHandle);
}
free(deviceInterfaceDetailData);
i++;
}
std::cout << "No more to enumerate." << std::endl;
}
}
SetupDiDestroyDeviceInfoList(hDevInfo);
return 0;
}
Error couts were omitted due to readability and code size(since this is quite huge already), and the post preview doesn't show a scroll bar. Will post the as-is full code with error prints if needed.
modified 22-Sep-24 10:13am.
|
|
|
|
|
I am facing this odd issue in which GUI freezes randomly on button clicked
So basically This is the sample code:
void dialog::OnButton1Clicked()
{
m_threadCmd = Button1; //Button1 is an enum from commandEnumList
AfxBeginThread(ui_ThreadExecuteCmd, this);
}
UINT dialog::ui_ThreadExecuteCmd()
{
OWaitCursor waitCursor;
switch (this->m_threadCmd)
{
case BUTTON1:
if (!Func1())
{
ShowError();
}
break;
}
this->m_threadCmd = 0;
return 0;
}
bool Func1()
{
//Notify GUI via PostMessage to disable the controls
//Do some processing
//Notify GUI via PostMessage to enable the controls
//return errorcode
}
The weird thing is that sometime it works fine and sometimes the GUI freezes.
I am seeing the UI buttons getting disabled then performing the operation -then ui buttons getting enabled back again. The Gui freeze happens randomly after that and when it freezes the buttons become unclickable and i am not receiving any message in PreTranslateMsg() after the freeze for mouse click or anything else
modified 21-Sep-24 5:10am.
|
|
|
|
|
Is it possible that you're performing a lengthy operation on the user interface thread, and that's why it's freezing?
From the "code" that you posted, it looks like that's exactly what you're doing.
If you do anything non-trivial when the button is clicked, then you should assign the task to a worker thread so that the UI thread is free to process UI inputs.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Oddly, they post different 'code' in QA.
GUI freezes randomly /MFC/C++[^]
"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
|
|
|
|
|
Hi @jeron1 , Thanks for pointing it out. Updated the question there as well .
|
|
|
|
|
Thanks for the reply. It's not a lenghty operation (Hardly takes 1 sec) Also,I am doing that only assigning the task to a worker thread. I have updated the code flow in the question , It will give you the exact idea about how am i doing it.
|
|
|
|
|
You're lucky it works at all. The sample code you posted posts messages to disable the controls, but those message should never get processes because the UI thread is still busy with "Do some logical processing," so it never processes those messages to disable the controls.
The processing of the messages will stay queued up until the UI thread is done with your "Do some logical processing" and returns after posting the messages to re-enable the controls. Once the UI thread is back in the "idle state", meaning your back in the message pump code picking up messages and dispatching them, only then will the messages you posted get processed. So that's where your app is "freezing".
Like Richard said, if you've got long-running processing going on, move that processing to a task or background thread. You'll also have to rewrite your code to wait for the task to complete before posting the messages to re-enable the controls.
The goal is to keep the UI thread available and running in the message pump for as much as possible.
|
|
|
|
|
Zishan Ud787 wrote: case BUTTON1: This case is not ever going to execute because it's all uppercase (and what's getting assigned to m_threadCmd is not). Is that intentional?
"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
|
|
|
|
|
Unicode is 1byte per character, that’s the Latin characters and the other symbols found on a standard keyboard
Multibyte is Latin, Greek, Russian and everything else that exceeds the initial 256 symbols
Is that how it works?
|
|
|
|
|
|
I thought a c++ char has the size of one byte. How can something that is greater that 1 byte (Unicode, Multibyte) fit into a char?
|
|
|
|
|