|
In my current project I will be receiving fixed type packets. I need to validate the checksum on those fixed packets..once the validation is successful. I need to strip off the header and buffer the remaining content. And I need to keep doing this in sequential order as the packets I receive. PAckets coming are infinite. So I am having difficutly in how do I handle this entire scenario in C++ programming. I am new bee in Object Oriented Programming... Any help would be great.
THANKS!
|
|
|
|
|
You could create a vector<byte> and keep appending the contents into this vector using vector<byte>::insert at the location vector<byte>::end.
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
resolvequestion wrote: I am new bee in Object Oriented Programming
What kind of new bee are you, honeybee or bumblebee?
|
|
|
|
|
How are the packets going to be processed? You say "PAckets coming are infinite" which implies you must use and discard data, otherwise your machine's memory would fill up.
If you want to process packets in the order that they arrive, I'd probably use a deque rather than the vector that superman mentioned, because a deque has good "delete from front" characteristics when compared with a vector.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Thanks Stuart Dootson & Superman !
I will be receiving certain amount of packets but I am not sure exactly how much. There will no memory problem as certainly its being taken under consideration that the received packets will be at certain limit it will not exceed.
whats the difference between using vector versus dequeue or queue technique.
I am explaining my scenario . I have reader thread that will do blocking read and once it receives the first packet which will be of 20W with 1W header with it.. I need to calculate checksum of the 20W packet received. Than I need to read certain fields and need to decide where it needs to be buffered. Before buffering these packets I need to strip off the 1W header. Once the buffering is complete say I might receieve 500 packets of size 20Word. After I stop receving the packets. I need to analyze the packets that being buffered. And these packets are of 2 types theere might be 2W packet and 260W packet or partial packet and each of these packet will have header so. first I need to read the packet header of the first received packet inthe buffer and base don that I need to dispatch those packets to its destined location or hand over to the designated handler.
So confusion is whats the best efficient technique I should use. Using simple array is not best option so thought of asking here. Also how do Istrip off the header from the packet.
Any help woul dbe appreciated. I have just started coding but have not really much coded in C++ .. I am learning by dng google or reading previos discussion here on forum
THANKS!!!!
|
|
|
|
|
How to read and display the height map in STL File?
i want to read the height map from STL file and display it in the picture control(MFC).
Any suggestion? am i need to using the openGL?
i am totally new in this 3D area...
|
|
|
|
|
anyone can help me?please
|
|
|
|
|
You may have a look at GLC_player [^] sources, or refer to the STL format specifications [^].
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
i read the STL format article already but still no ideal how to take the heightmap value and put it into matrix..zzz
the value from STL is like this
facet normal -0.1121196661 -0.0743282699 0.9909109389
outer loop
vertex 58.7546923638 62.1518674227 -611.4251952748
vertex 58.7132072061 61.7884042612 -611.4571526271
vertex 59.0884428989 61.5937838377 -611.4292939164
endloop
endfacet
the heightmap value == y?
p/s: what i know from the article above is -611.42xxxx all is a y value.
|
|
|
|
|
I'm fairly new to windows programming and use the MessageBox function a lot to see what going on with code. The problem I have is when using API functions that return various types. I want to see the values returned. Anyone know how to do conversion on these returned values so they can be displayed in a MessageBox?
|
|
|
|
|
you can use _sntprintf (TCHAR, char-counted, sprintf) to build a string:
int iVal = 100;
TCHAR buf[100];
_sntprintf(buf, "this is my integer: %d", iVal);
MessageBox(buf);
|
|
|
|
|
egerving wrote: use the MessageBox function a lot to see what going on with code
Why are you not using a debugger?
egerving wrote: API functions that return various types
Example? Again, if you use the debugger you'll see the return values.
|
|
|
|
|
As a backup to Michael's suggestion, you could use TRACE() (with MFC) or OutputDebugString() to see those values.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"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
|
|
|
|
|
Hi all, Im having a bit of trouble compiling a simple program (just a messagebox) in visual c++ (the full version, not express). I'm guessing there must be something I need to do or setup to get it working. The same code compiles just fine in codeblocks and visual c++ express. I wanna use visual c++ for the resource editor. Anyone has any idea why this is?
Here's the full code. Thanks.
#include <windows.h>
INT WINAPI wWinMain(HINSTANCE hInst,
HINSTANCE hPrevInst,
LPWSTR lpCmdLine,
INT nShowCmd)
{
int nResult=MessageBox(NULL,
"An example of Cancel,Retry,Continue",
"Hello Message Box!",
MB_ICONERROR|MB_ABORTRETRYIGNORE);
switch(nResult)
{
case IDABORT:
break;
case IDRETRY:
break;
case IDIGNORE:
break;
}
return 0;
}
|
|
|
|
|
Adassus wrote: Im having a bit of trouble compiling a simple program
And what did you say the the compiler error message was?
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
wWinMain uses wide-characters so you need to use wide strings.
int nResult=MessageBox(NULL,L"An example of Cancel,Retry,Continue",L"Hello MessageBox!",MB_ICONERROR|MB_ABORTRETRYIGNORE);
Conversely you could also change the entry point to WinMain[^] and change the character set in the General section to 'Not Set'
Best Wishes,
-David Delaune
|
|
|
|
|
without knowing the error :
Unicode vs. MBSC ?
This signature was proudly tested on animals.
|
|
|
|
|
this is a copy paste I got from an online tutorial. It compiles fine in codeblocks but gives me an error when I try to compile in visual c++.
The error is:
1>c:\documents and settings\john\my documents\visual studio 2008\projects\test\test\main.cpp(18) : error C2440: '=' : cannot convert from 'const char [13]' to 'LPCWSTR'
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>c:\documents and settings\john\my documents\visual studio 2008\projects\test\test\main.cpp(28) : error C2664: 'MessageBoxW' : cannot convert parameter 2 from 'const char [29]' to 'LPCWSTR'
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>c:\documents and settings\john\my documents\visual studio 2008\projects\test\test\main.cpp(42) : error C2664: 'CreateWindowExW' : cannot convert parameter 2 from 'const char [13]' to 'LPCWSTR'
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>c:\documents and settings\john\my documents\visual studio 2008\projects\test\test\main.cpp(51) : error C2664: 'MessageBoxW' : cannot convert parameter 2 from 'const char [23]' to 'LPCWSTR'
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>Build log was saved at "file://c:\Documents and Settings\john\My Documents\Visual Studio 2008\Projects\test\test\Debug\BuildLog.htm"
1>test - 4 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
#include <windows.h>
LRESULT CALLBACK WinProc(HWND hWnd,UINT message,WPARAM wParam,LPARAM lParam);
int WINAPI WinMain(HINSTANCE hInst,HINSTANCE hPrevInst,LPSTR lpCmdLine,int nShowCmd)
{
WNDCLASSEX wClass;
ZeroMemory(&wClass,sizeof(WNDCLASSEX));
wClass.cbClsExtra=NULL;
wClass.cbSize=sizeof(WNDCLASSEX);
wClass.cbWndExtra=NULL;
wClass.hbrBackground=(HBRUSH)COLOR_WINDOW;
wClass.hCursor=LoadCursor(NULL,IDC_ARROW);
wClass.hIcon=NULL;
wClass.hIconSm=NULL;
wClass.hInstance=hInst;
wClass.lpfnWndProc=(WNDPROC)WinProc;
wClass.lpszClassName="Window Class";
wClass.lpszMenuName=NULL;
wClass.style=CS_HREDRAW|CS_VREDRAW;
if(!RegisterClassEx(&wClass))
{
int nResult=GetLastError();
MessageBox(NULL,
"Window class creation failed",
"Window Class Failed",
MB_ICONERROR);
}
HWND hWnd=CreateWindowEx(NULL,
"Window Class",
"Windows application",
WS_OVERLAPPEDWINDOW,
200,
200,
640,
480,
NULL,
NULL,
hInst,
NULL);
if(!hWnd)
{
int nResult=GetLastError();
MessageBox(NULL,
"Window creation failed",
"Window Creation Failed",
MB_ICONERROR);
}
ShowWindow(hWnd,nShowCmd);
MSG msg;
ZeroMemory(&msg,sizeof(MSG));
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
LRESULT CALLBACK WinProc(HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam)
{
switch(msg)
{
case WM_DESTROY:
{
PostQuitMessage(0);
return 0;
}
break;
}
return DefWindowProc(hWnd,msg,wParam,lParam);
}
|
|
|
|
|
Same problem, same solution.
Your project is configured for Unicode strings and your string literals are ANSI. To avoid asking the same question again you should make an attempt to learn the difference between Unicode strings and ANSI strings. I recommend the following:
1.) Right click on your project in the solution explorer.
2.) Choose the properties from the popup menu.
3.) Choose 'General' from the left treeview.
4.) In the 'Project Defaults' section view that the 'Character set' is set to Unicode.
This means your project is using Unicode strings. More information below:
About ANSI & Unicode[^]
C++ String Literals[^]
Unicode Programming Summary [^]
Some solutions:
1.) You could change your Character set to 'Not Set' or 'MultiByte character set' and the code above will compile.
2.) You could add an L prefix to the string literals to denote they are wide strings.
3.) You could encapsulate the string using the _T macro so the project will compile in both ANSI and Unicode settings.
Best Wishes,
-David Delaune
|
|
|
|
|
thx alot, i did work! I appreciate the answer!
|
|
|
|
|
Hi,
I'm developing a driver for a usb device.
I have already a driver sample that allows me to get data from my device.
And the sample code to interact with the device is a console application.
I need to get that data into a C# program and now I don't know what to do.
I can think in some options like:
- Do this directly in the driver layer (which is a big puzzle)
- Wrap the code of the sample app in a C++ dll which I can then use in the C# side (don't know which kind of project that belongs to)
So, I was looking for some lights in order to see where I should focus my development efforts.
Any help would be appreciatted.
With my best regards,
Nuno
|
|
|
|
|
I suggest you write a DLL that exposes the functionality of your device in the API.
This is the most common way and you'll be able to use the DLL from whatever programming language.
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
Hi sinosoidal,
The DeviceIoControl Function[^] can be called directly from your C# application. There is no need to create a C++ DLL when you can pass information to and from a device driver with the C# language.
Take a look in your USB driver code and look for the IRP_MJ_DEVICE_CONTROL entry point. Should be something like:
DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = SomeFunction
This defines the function which processes IOCTL codes. All you need to do is define a new IOCTL code. You simply pass a pointer in the DeviceIoControl lpOutBuffer parameter and the device driver can write data into the buffer at this address. Its extremely simple.
I would recommend spending a few hours playing with the sample project at:
WinDDK\6001.18002\src\general\ioctl\
This will give you an idea about how simple communication with a device driver is.
If the data arriving on the USB device needs to fire an event to notify your usermode application you can view the sample located at:
WinDDK\6001.18002\src\general\event
I highly recommend investing a few hours experimenting with these samples. The C# language is full featured and there is no reason to write a native DLL if the parent application is managed. You can communicate with the device driver directly from your C# application.
Best Wishes,
-David Delaune
|
|
|
|
|
Hi,
Thanks for the replies. That was good news for me. I'm trying to explorer the direct connection to the USB device from C# using DeviceIOControl.
I found an example with code from an article here in codeproject.
The example, basicly interacts with an pci card, but i have seen another example of interaction, but this time with an usb device and they both start with CreateFile passing the device GUID.
However, i cant have a valid handle. I think i'm passing the right guid of the device, because i'm getting it from the driver it self.
hFileHandle = INVALID_HANDLE_VALUE;
hFileHandle = CreateFile("{00873fdf-61a8-11d1-aa5e-00c04fb1728b}",
GENERIC_READ |
GENERIC_WRITE,
0,
(IntPtr)0,
OPEN_EXISTING,
0,
NULL);
if (hFileHandle == INVALID_HANDLE_VALUE)
{
Console.WriteLine("Cannot open driver handle");
return;
}
Any tips?
Thanks,
Nuno
|
|
|
|
|