|
Is it possible by hooking GetProcAddress() function?
Hook GetProcAddress with my myGetProcAddress(). Now myGetProcAddress will be notified on calling GetProcAddress. You can return the address of MyDllThreeFunction on receiving a getprocaddress() for DllThreeFunction.
|
|
|
|
|
Hi,
I am using CPPUNIT code for Unit testing purpose. I have created a Win32-console application to show its output. Now i want to generated TEXT/HTML/ formated file which will contain the excat lines{output} as in console o\p window. Please suggest what should be VC++ code to achive this requirement. Thanks
modified 31-Jul-13 9:55am.
|
|
|
|
|
You just need to use one of the file writing functions or fstream interfaces to write to a file. Check the documentation on MSDN.
Use the best guess
|
|
|
|
|
You can solve this in two different ways: Inside your program or outside your program. The "outside" solution is probably simpler and more roboust and easier to implement.
Outside:
When you are running your program you redirect its output to another program that does the following: prints the incoming data to the console but at the same time it writes it into a text file and of course at the same time it can do other things too with the log data. You can do the redirection either by writing another program that runs the test with redirected input/output or you can choose an easier solution, piping together programs with the help of your cmd or bash:
Example python script that prints the input to console and logs to file at the same time:
file: x.py
import sys
with open('logfile.txt', 'w') as log_file:
while 1:
s = sys.stdin.readline()
if not s:
break
sys.stdout.write(s)
log_file.write(s)
log_file.flush()
Commandline usage:
TestProgram | python x.py
Of course this program could be anything, not only a python script but a perl script or a c/C++ program or a java program.
Inside:
If you want to solve the problem inside your test program then create your own logger and log through that instead of using printf() or similar methods. In your logger you can create many outputs so when your test program logs something your logger can direct it towards different outputs for example a console writer output, a html writer output and a text file writer output.
Almost forgot to mention: If you are on linux or you have cygwin on windows then you can use the tee command that does basically the same as the above python script.
modified 31-Jul-13 12:13pm.
|
|
|
|
|
Hello everybody,
I am trying to convert CString to float using atof(). but its not giving the exact value.
for eg.
CString strVal;
GetDlgItem(IDC_MAXLAYER)->GetWindowText(strVal);
float mVal = atof(strVal);
IDC_MAXLAYER is edit box and in that, i am having the value 386.080, but after atof() conversion, mVal shows 386.07999
is that possible to get exact 386.080 by converting?
Thanks in advance.
A. Gopinath.
|
|
|
|
|
Floating point numbers can not represent all real numbers accurately. Generally speaking: floating point numbers have a precision that is the greatest when the value is near zero. As soon as the whole part of the floating point number contains more and more digits, the fraction part quickly becomes super-inaccurate. Try entering numbers to your editbox like "234224.34654" into your editbox, you will see that the digits in the whole part will "steal" the precision from the fraction part because the value of this number is quite "far from zero". Read some more about floating point numbers:
http://blogs.msdn.com/b/dwayneneed/archive/2010/05/07/fun-with-floating-point.aspx[^].
http://en.wikipedia.org/wiki/IEEE_754[^]
People tend to use floating point numbers as a golden hammer when they don't know about its dark side. Sometimes its better to use just integers or fixed point arithmetic.
|
|
|
|
|
Hello Friends
I am writing to File using FILE object Pointer using fread and fwrite functions.
this is my class:
class Test
{
public:
int a;
int b;
std::vector<int> c;
};
If I don't use vector then it is writing fine and reading too.
But after using vector,its not reading properly if use
fread(&obj,sizeof(Test),1,file);
Do I need to Write separately vectors using std::ostream_iterator and using copy method of STL?
Or is there any way If I Can Write Directly class object in single shot bcoz my class is having too many vectors as member variables.
Regards
Y
|
|
|
|
|
The vector contains just pointers to the actual data stored by the vector. If you write out your struct then you write out just some pointers that will probably be invalid the next time you want to load your data. The serialization method you use is the 0th solution everyone starts with and it works just with primitive types - as soon as you start using complex types like a vector you have to consider using a more sophisticated serialization method. Unfortunately serializing correctly needs more work and a serialization framework. I'm using my own reflection-like framework that is similar to AutoSerial[^] but is more lightweight. If you have reflection info / typeinfo then you can easily write different kind of serializers (binary, xml, ...) that will automatically work with all of your structs and types that have typeinfo attached. In my system I register every serializable member of a struct manually but from that point the struct is serializable as xml, binary, and so on depending on the kind of serialzers I have written. Runtime typeinfo has a bit of perofrmance penalty that matters quite rarely. Some other serializer frameworks do the dirty job with templates and bind to serializable data at compile time with better performance and the third type of serializers generate serializer classes/code for you by parsing your source code. In general I don't like code generators. Another popular serialization framework to check out is boost::serialzation[^].
A serialization framework can have additional benefits compared to a single-shot file-write: It can handle endianness problems and struct member alignment too if you compile the same serializer code on two different machines (in case of a server-client program that serializes data to send over network, or if you transfer the serialized data file to a completely different machine that has different endiannes/compiler struct member alignment).
modified 31-Jul-13 6:54am.
|
|
|
|
|
ok, I understand.
But this library is very old and not compiling,one of header file is missing.
Do we have any other Library for serialization Except Boost ?
Thanks For your Reply.
Regards
Y
|
|
|
|
|
There are probably but I have always used my own creatures for this kind of task so I can't recommend you a good and (I guess) free solution if you don't like boost. Long ago when I checked out the available solutions and I didn't really liked them. Maybe the others can recommend you one or you can use google to search for something that meets your requirement. As a final solution you can write your own framework that is a fun way to learn something new if you have the time and interest.
|
|
|
|
|
Thanks Dear
In case of using AutoSerial, Do I need to include only AutoSerial.h ?
or Something else I need to do. I didn't get from this Docs.
Thanks Once Again.
Regards
Y
modified 31-Jul-13 8:35am.
|
|
|
|
|
You are welcome! Unfortunately I cannot answer this as I used it only once long ago.
Serialization in C++ is a difficult topic. Every solution is messy as serialization isn't really supported by the language. In my opinion it would be very useful to have a bit more detailed runtime type info support in C++ that can be used for serialization. On detailed runtime type info I mean for example auto-generated list of struct/class members, member names, enum member list/member names, ........ On top of such info (that I'm currently putting together manaully in my serialization system) it is quite easy to write reasonably simple yet effective serializers.
I would give boost::serialization a try, that is a quite popular and maintained library.
|
|
|
|
|
Ok, But Boost::Serialization seems to me a heavy library.
It wud be better to have one own and fun to learn a new framework.
Anyway, thanks Buddy For all your replies.
Regards
Y
|
|
|
|
|
You are welcome! I'm also using my own solution because its quite lightweight and provides only a few features I need in a better way. Good luck with creating your own stuff and have fun! Don't forget to take a look around to check out the source code of some existing frameworks to steal good ideas before starting out with your own stuff!
|
|
|
|
|
Are overlapped file writes guaranteed to happen in the order in which they are issued? (On Windows)
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Hi,
No.
Although the IRP requests are generally dispatched from a FIFO queue... a call to WriteFile [^] results in a IRP_MJ_WRITE[^] request being sent from the i/o manager down through the filter manager and associated minifilter stack. If any installed legacy, FS or filter driver return STATUS_PENDING for your write request... this would potentially allow other i/o requests to complete out-of-order.
Best Wishes,
-David Delaune
|
|
|
|
|
Wow, thanks. I'm glad you were around to answer this with your knowledge of the driver stack.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Even if the current implementation on your windows version/installation guarantees this order you shouldn't exploit it (for example because this implementation may change in the future if the documentation doesn't explicitly state that it wont). Generally in case of async operations (not only in case of file IO) you shouldn't assume any order in which the async tasks are completed. If an async system doesn't have to guarantee completion order than it has more freedom to perform optimizations. If you have to process the completed async requests in a specified order then its relatively easy to make the result processing ordered.
|
|
|
|
|
Thank you.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Hello ,
Is it possible to create a empty file with predefined size of that file.
please reply me soon ...
Regards
Sarfaraz
|
|
|
|
|
Maybe it is just me but I think the predefined size of an empty file is zero. Maybe this is something you are looking for: SetEndOfFile()[^]
|
|
|
|
|
How to create the the empty file with defined size in c++ or MFC.
thanks for reply .
see i am looking to create a file that should be empty and should not have data inside the file.
you can say acquiring memory space from the particular drive ..
Thanks
|
|
|
|
|
This is the easiest. Open/Create a new file and then close it immediately without writing into it. That's it.
|
|
|
|
|
ya i agree what about the size which i want to define think that around 1gb or 100 mb ..
thanks
|
|
|
|
|
OK, it is time to decide: Do you want an empty file or one that is 1gb large???
|
|
|
|