|
I'm trying to determine a way to write raw bytes of data to an ethernet cable (but more importantly, to the device to which it is attached), EXACTLY as described here for parallel cables:
I/O Uncesored 1 - Controlling LEDs (Light Emitting Diodes with Parallel Port
Looking into Inpout32.dll, which the article makes use of, it seems that it was developed specifically for parallel ports.
Then I looked into Physical "I/O Range" of the Network Adapter card itself: 0x9C00-0x9CFF .
It appears that there is a 256 bit range in which data can be written to/read from. However, when trying to initialize a pointer (dereferenced with the & sign), I get a segfault. Not that I ever really expected that to work anyway. If it's important, I'm running under a user w/ admin priveledges.
It couldn't be as simple as using the MFC CAsyncConnection stream classes and overloaded << and >> operators, could it?
How should I go about doing this? Is the solution going to be as complicated as writing my own kernel-mode driver?
Thanks,
-Adam
|
|
|
|
|
Hey, i don't know if this could help you or not but maybe take a peek at raw sockets[^], althorough i believe these don't go deep enough for you...
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Life: great graphics, but the gameplay sux. <
|
|
|
|
|
Hi,
The parallel port example you mention does not easily (if at all) translate to being applied to a network cable (which is more comparable to serial that parallel).
I did once build myself an ISA card to do some fast I/O work and wrote a driver to interface it to windows so based on the amount of work that required, I recommend looking into an API or streams etc.
To communicate with a networked device use of a network comms API or stream would seem to be the way to go - I've not done this but I'm sure there are articles on it.
|
|
|
|
|
thanks for the suggestions - I'm currently looking into both topics. I'm sure I'll find more information.
|
|
|
|
|
The definition of library function strspn is:
size_t strspn(const char *str, const char *chars)
e.g. if ‘str’ is “fecxdy” and ‘chars’ is “abcdef” then the function would return 3, since ‘f’, ’e’ and ‘c’ all appear somewhere in ‘chars’, giving 3 leading characters of ‘str’, and ‘x’ is the first character of ‘str’ which is not a member of ‘chars’.
Could someone help me write an implementation of strspn in ‘C’. The only library function I am allowed to call from the implementation is strlen.
|
|
|
|
|
kaku_lala wrote: Could someone help me write an implementation of strspn in ‘C’.
Can't you just look in the crt\src folder for the strspn.c file?
"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
|
|
|
|
|
Here's some pseudo-code describing the algorithm - it really doesn't tell you any more than the comment with the strspn signature, but the restatement may help you grasp how the function works:
size_t strspn(const char *str, const char *chars)
begin
result := 0
for each c in str
begin
if c is in chars then
increment result
else
return result
end if
end
return result
end
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Folks, here is an implementation of memset(), however I have been told that there is one logical mistake in the code. Could you help me find it.
I feel that a double pointer for the target string should be passed to this function, which will be like passing the address of the pointer variable and not the pointer itself.
I am getting an "access violation" when I execute the code in MS VC++ IDE.
The definition of the ‘C’ Library function memset is
void *memset(char *s, char c, size_t n)
Copy c to the first n characters of s. Return s.
void *memset(char *s, char c, size_t n)
{
size_t i;
for (i = 0; i < n; i++, s++)
{
*s = c;
}
return s;
}
|
|
|
|
|
How are you using the function? It looks OK to me and works fine when used as per its signature, like so:
#include <iostream>
void *memset(char *s, char c, size_t n)
{
size_t i;
for (i = 0; i < n; i++, s++)
{
*s = c;
}
return s;
}
int main(int, char**)
{
char p[100] = {0};
memset(p, 'd', 10);
std::cout << p << std::endl;
}
Compiles, links and runs OK (as I would expect) with gcc 4.0.1.
[edit]
kaku_lala wrote: Return s.
That's the bit that your program probably doesn't do according to the spec (although the spec as given is ambiguous, to be honest).
[/edit]
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
kaku_lala wrote: I am getting an "access violation" when I execute the code in MS VC++ IDE.
So use the debugger to step through it until the violation happens.
How are you calling your function?
"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
|
|
|
|
|
The return value is supposed to be the original buffer pointer. s is incremented so it ends up pointing past the end of the buffer.
Technically, the first parameter should be a void*.
void* memset1(void* s, char c, size_t n)
{
char* p = (char*) s;
for (size_t i = 0; i < n; i++)
{
p[i] = c;
}
return s;
}
(Funny thing is that in VS 2008, as written it figures out that you're doing a memset, and replaces the contents of memset1 with a call to the CRT's memset.)
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
|
|
|
|
|
I am currently writing at some kind of logging class and want to improve the usability by overloading the streaming operator. The idea is that i can use the class LogClass in the following two ways:
LogClass test;
std::string blub("blub");
test << "bla " << blub;
std::cout << test << "bla " << blub;
In both cases the content of the objects which are located on right should be logged inside the test object. In the second case the content should also be forwarded to cout.
I was already able to handle some simple cases like the following:
LogClass test;
std::string blub("blub");
test << "bla ";
std::cout << test << blub;
Therefore i overloaded the operator twice like this:
friend std::ostream& operator<<(std::ostream &os, const LogClass &logClass);
void operator<<(const std::string &os);
But this isn't working for more complex scenarios.
I would be really grateful when anyone could give me a hint how this is done probably.
Regards squall23
|
|
|
|
|
Your best bet would probably be to derive LogClass from std::ostream - that way you can make use of all the operator<< definitions in the std namespace. Look at how std::ostringstream works - it derives from ostream and passes a string buffer (as opposed to the file buffer that std::cout would pass) into the ostream base class when constructed.
To summarise, you'd have something like this:
template<class Elem, class Traits = std::char_traits<Elem> >
class basic_log_buffer : public std::basic_streambuf<Elem, Traits>
{
};
template<class Elem, class Traits = std::char_traits<Elem> >
class basic_log_stream : public std::basic_ostream<Elem, Traits>
{
public:
LogStream() : basic_ostream(&my_buffer), my_buffer(whatever) {}
private:
basic_log_buffer<Elem, Traits> my_buffer;
};
This page[^] has an example of deriving new buffer and stream classes. This link[^], to page 209 of Angelika Krafter and Klaus Kreft's book about C++ streams is also of interest - in fact, their book tells you all you want to know about C++ streams and more besides - it's very good. Unfortunately, the Google Book Search link is to a preview of the book - pages are left out every so often, usually the important ones.
To output your log object, you then just need to provide an implementation of operator<< taking your log class.
Here's an operator<< I just wrote for std::ostringstream:
namespace std
{
ostream& operator<<(ostream& os, ostringstream& oss)
{
os << oss.str();
oss.str("");
return os;
}
}
This will write the ostringstream 's contents to the specified ostream when used like so:
std::ostringstream oss;
oss << "Hello";
std::cout << oss << std::endl;
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Thank you for the good explanation and the links!
I am now pretty sure that i can resolve my issues with the information you provided.
Regards, squall23
|
|
|
|
|
I know the title's inflammatory, but what I'm asking is, are there any tools out there that let me figure out more closely wtf is crashing in a release build, other than
MFC42.DLL exception 0xC00000191
000191: ???
000192: ???
000193: ??? Something like windows message monitor?? It's an MFC app, interfaces with some multithreaded COM dlls.
ty
|
|
|
|
|
If you create a Program DataBase (PDB) file with Debug-information, then you can debug Release builds.
Set the C++/C compiler option "Debug Information Format" to "Program Database" and set the Linker option "Generate Debug Info" to "YES /DEBUG".
If you also want to use watches etc. while debugging the release build, then you can set the C++/C compiler option "Optimisation" to "Disabled".
|
|
|
|
|
How would I mimic a break point, or should I just break it manually & "run to cursor"
|
|
|
|
|
You don't have to 'mimic' a breakpoint when you have enabled debug information in the Release build - just put one in as with a Debug build. The only problem is that as optimisations are turned on, you'll find the following problems:
- Some, or possibly all, local data items won't be accessible - hte compiler may have optimised away all need for them
- Some lines of code won't take a breakpoint. This is because they've been optimised away.
- The assembly language can be more difficult to trace to the source than when optimisations are turned off
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
I am currently writing an application using C++ and MFC. I need to put out about 100 words of text that are instructions to the user. I am doing this by using the method CDC::TextOut in my OnPaint routine. However, something about doing it this way does not seem right to me. I am also concerned that there maybe formatting issues. That is, the text does not look particular nice. I am hoping there is a better way to put this text out. Any ideas?
Thanks
Bob
|
|
|
|
|
BobInNJ wrote: I am doing this by using the method CDC::TextOut in my OnPaint routine.
Does this mean you have an SDI or MDI application? If so, and the view based on CFormView , you could add a static control to the top of it and write the instructions there.
Another option would be a modeless dialog. It could contain the instructions while still allowing you to interact with the parent window.
"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
|
|
|
|
|
Thanks for the response. I am not using the document view architecture. Therefore, I conclude that
my application is not SDI or MDI.
Bob
|
|
|
|
|
Ok, you either use a separate, modeless dialog for the instructions, or put a static control on your dialog for them.
"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
|
|
|
|
|
(without much context, I cannot offer more help )
Why not simply creating a dialog (modal or modeless) and display the text in a simple multi-line edit box ?
This signature was proudly tested on animals.
|
|
|
|
|
|
Thanks for all the responses. After looking at the alternatives, I came to the conclusion that just putting out plain text using TextOut was the way to go.
Bob
|
|
|
|