|
Nish [BusterBoy] wrote:
I might try out some simple STL too
Join us... don't be afraid....
Seriously, it's not hard once you get into it, I spent a lot more time trying to fathom out COM than I did STL. And obviously I'll be here to help if you get stuck..
Christian
I have come to clean zee pooollll. - Michael Martin Dec 30, 2001
Picture the daffodil. And while you do that, I'll be over here going through your stuff.
Picture a world without war, without hate. And I can picture us attacking that world, because they would never expect it.
Sonork ID 100.10002:MeanManOzI live in Bob's HungOut now
|
|
|
|
|
Christian Graus wrote:
Join us... don't be afraid....
LOL
That sounds like right out of a thriller movie.
You are a revolutionary leader. I am the cool hero confused as to whether I should continue being a handsome playboy screwing french women or whether I should join the revolution. Finally I give in and we take over the solar system. You are made king and I become a count [you give me one of the jovian moons] and marry a beautiful princess born and brought up in Mars and live happily ever after
Nish
Sonork ID 100.9786 voidmain
www.busterboy.org
If you don't find me on CP, I'll be at Bob's HungOut
|
|
|
|
|
Nish [BusterBoy] wrote:
Christian Graus wrote:
Join us... don't be afraid....
LOL
That sounds like right out of a thriller movie.
Actually I'm quoting Dilbert, the pointy haired boss to be exact. But yours sounds like more fun....
Christian
I have come to clean zee pooollll. - Michael Martin Dec 30, 2001
Picture the daffodil. And while you do that, I'll be over here going through your stuff.
Picture a world without war, without hate. And I can picture us attacking that world, because they would never expect it.
Sonork ID 100.10002:MeanManOzI live in Bob's HungOut now
|
|
|
|
|
First of all, please only ask the one question once.
Secondly, the following code should work, assuming the numbers are properly delimited. It currently reads in strings, but you can use atoi, or convert it to read int's, I am sure.
This program is my playground for using IOStreams, so I sure there are #include and using std:: statements in there that are not needed.
<pre>
#include "stdafx.h"
#include <string>
#include <vector>
#include <algorithm>
#include <fstream>
#include <iostream>
#include <sstream>
using std::copy;
using std::vector;
using std::string;
using std::ifstream;
using std::ostream_iterator;
using std::cout;
using std::back_inserter;
using std::getline;
using std::ostringstream;
using std::istream_iterator;
int main(int argc, char* argv[])
{
string currentLine;
ifstream str("c:\\winzip.log");
if (!str.is_open())
{
cout << "It's stuffed\n";
return -1;
}
vector<string> file_contents;
copy(istream_iterator<string>(str),istream_iterator<string>(), back_inserter(file_contents));
// Now print out the results
copy(file_contents.begin(), file_contents.end(), ostream_iterator<string>(cout, "\n"));
return 0;
}
</pre>
Christian
I have come to clean zee pooollll. - Michael Martin Dec 30, 2001
Picture the daffodil. And while you do that, I'll be over here going through your stuff.
Picture a world without war, without hate. And I can picture us attacking that world, because they would never expect it.
<Center><A href = "http://www.sonork.com" target = "_Blank">Sonork</A> ID 100.10002:MeanManOz</Center><Center>I live in <U><B>Bob's HungOut</B></U> now</center>
|
|
|
|
|
Nice. By the simplicity of the original post (he didn't ask how to find 4000-digit primes in constant time), I would have guessed they were asking for the simple fopen(), fgets(), etc.
But this is a nice solution. Prolly waaaaay over the poster's head.
J
|
|
|
|
|
Jamie Hale wrote:
I would have guessed they were asking for the simple fopen(), fgets(), etc.
I had a look at those functions last night ( fulfilling a contract at the last minute, he wanted me to use them ), and I thought they looked way ugly. I try to avoid C functions whenever I can.
Jamie Hale wrote:
But this is a nice solution. Prolly waaaaay over the poster's head.
Probably. My hope was by showing an elegant C++ way of doing it that he may well dig deeper and analyse why it all works. That's how I learned most of the standard C++ stuff I know, by asking questions on comp.lang.c++, making a fool of myself often, and spending a lot of time trying to figure out what the answers I was given meant.
Christian
I have come to clean zee pooollll. - Michael Martin Dec 30, 2001
Picture the daffodil. And while you do that, I'll be over here going through your stuff.
Picture a world without war, without hate. And I can picture us attacking that world, because they would never expect it.
Sonork ID 100.10002:MeanManOzI live in Bob's HungOut now
|
|
|
|
|
Hi,
Does anyone know how to install a callback function between two applications?
I guess that this shouldn't be too difficult (basically you just have to transmit a callback address), but I'm worring about the operating system shifting my applications in the memory. In this case the address isn't correct anymore, is that right? Is there an easy way of doing this?
Thanks for your help
|
|
|
|
|
You do not need to worry about the OS moving your application around in memory because you only deal with a virtual address, and that will not change, however, the virtual address that you receive in process A will not be valid in process B. This makes calling a callback function not as simple as you would think.
You will need to do some form of inter-process Communication (IPC).
There are a number of ways that you can do this including, I listed these in an order of difficulty from easiest to most difficult:
Send a message to the second process and the message handler will call the function for you.
Create a COM object.
Use a memory mapped file to communicate between the two applications, monitor the data that is written in to the file and take appropriate actions.
Use a Remote Procedure Call (RPC). This is a networking mechanism that will scale to applications located on other machines, probably overkill in your case.
I would suggest the message mechanism. This is the same mechanism that you would probably use in a multi-threaded application.
Kilowatt
|
|
|
|
|
Thanks for your answer
Just another question: if I solve the problem by using messages between the two processes, this means I use messages to tell the second application the address of the callback? Or use the messages instead of the callback?
My concret problem: I have an application which renders a 3D world. The 3D world is refreshed continuously everytime the message queue is empty.
I have a second application which can make modification to some objects in the 3D world through a dll with a shared data segment. The modifications are not directly reported on the 3D world, because all modifications have to be done just before the rendering. The modifications are stored in the shared data segment until a "redraw"-command is executed. I think everything would be easier if I could install a callback (in which I can update the data) which is called just before the rendering.
Can't I somehow deduce the absolute adress of a callback function given the virtual adress?
|
|
|
|
|
The reason why you cannot do this is because you cannot access the memory in the second process. If you call the callback function in process 1 with an address of a function that you determined from process 2, you will be accessing the data this is at the memory location in process 1. This will most likely result in a memory access error.
WIN32 allows each application to have their own completely independent address space. This is why you cannot match the memory from one process to another. Even if you could find the absolute or physical address of the function call to the redraw command in your second app, the OS would change this address out from under you. That is why it is nice to work with virtual memory addresses, the memory moving becomes transparent to the application programmer. This would not be an issue in WIN16 because all applications shared the same address space.
The reason why you can access the shared data segment of the DLL and modify the memory is because windows maps the shared data segment of the DLL into a memory mapped file.
Since you already have shared data, you may just want to set an update bit that the Rendering app can monitor in its idle state and determine if it is time to update.
kilowatt
|
|
|
|
|
alright;
now i need to read a sequence of numbers from a file and then store them in a linked list.
thanks
|
|
|
|
|
Hi.
I am experience recursive random number. It seems that only happens when rand() is in a loop.
For example:
--------------------------------------
srand(time(0));
int tempNUM = 0;
for (int i = 0; i < 1000; ++i)
{
tempNUM = 1 + rand() %9999999;
cout << tempNUM + 1;
}
--------------------------------------
In a program I am working on with a similar code to the one above, the program generates duplicates random numbers. It seems I have to *wait* one second clock until it generates a something new. Does that have something to do with time(0)?
I would like something that can generate a completely random number almost instantaneously even when it is in a for loop like the one above.
Thanks,
Kuphryn
|
|
|
|
|
If you read the time() docs, you'll see the return value is a time_t, which counts seconds.
--Mike--
"COM didn't solve the old version of DLL hell - it just provided us with a new and improved version of hell."
-- John Simmons, 1/22/2002
My really out-of-date homepage
Sonork - 100.10414 AcidHelm
Big fan of Alyson Hannigan.
|
|
|
|
|
Make sure that srand() is called exactly once in your program. Your sample code works correctly because srand() is called outside of the loop.
|
|
|
|
|
Thanks.
You are right. I did not call srand() inside the for-loop, but I did call it at the beginning of a function that I think could be recursive. I was prepare for school lastnight and was not able to look up all the code. I am certain srand() is the problem. You are right on.
Kuphryn
|
|
|
|
|
I figured probably that most Win32 API gurus hang out here, and anyway, I posted a question in the VB forum (since the app i am talking about is written in VB) and as much as I hate to cross-post, I think it is an API problem, so allow me to post a link.
Please help if you can. Would be much appreciated
The thread
--
David Wengier
|
|
|
|
|
I am using ShellExecute to open another program which is located in a subdirectory. I do this by calling it with the file param as the filename, and the directory name as the subdirectory. It works under win2k/xp/nt but not on win95/98/ME....If anyone knows why and how I can fix it it would be of amazing help!
So imagine the directory is 'stuff' and the file is 'thing.exe'
I call ShellExecute(NULL,NULL,"thing.exe",NULL,"stuff",SW_SHOW);
This works fine in 2k but not 9x!!!!!! please someone help me!
: Wherever you go, there you are, and you wish you were somewhere else :
|
|
|
|
|
did you add the Microsoft layer for unicode to your 9x project.
here is the text that is found at that link:
- Add the following two files to your project:
- UnicoWS.dll -- the Microsoft Layer for Unicode DLL
- UnicoWS.lib -- the LIB file to which you link
Note that the Microsoft Layer for Unicode does not automatically load from the $(WINDOWS) or $(WINSYS) directories. Thus, do not put UnicoWS.dll there unless you are running from a system process that is located there. Instead, keep the UnicoWS.dll in your application directory and call LoadLibrary yourself to ensure that you load the correct .dll.
- Add the following to the link options for your application (note that these libraries are not separated by commas because that is how you add them to the link list):
- First, add the following: /nod:kernel32.lib /nod:advapi32.lib /nod:user32.lib /nod:gdi32.lib /nod:shell32.lib /nod:comdlg32.lib /nod:version.lib /nod:mpr.lib /nod:rasapi32.lib /nod:winmm.lib /nod:winspool.lib /nod:vfw32.lib /nod:secur32.lib /nod:oleacc.lib /nod:oledlg.lib /nod:sensapi.lib.
- Then add UnicoWS.lib.
- Finally, add the libraries that the Microsoft Layer for Unicode uses explicitly: kernel32.lib advapi32.lib user32.lib gdi32.lib shell32.lib comdlg32.lib version.lib mpr.lib rasapi32.lib winmm.lib winspool.lib vfw32.lib secur32.lib oleacc.lib oledlg.lib sensapi.lib. In this step, omit any libraries listed after advapi32.lib whose APIs are not used in your application. However, if your application uses another component, such as MFC, ATL, or CRT, be sure to include any libraries on which the component depends.
- Compile your application.
There is other information on the Web page, I would follow the link from above.
Kilowatt
|
|
|
|
|
Use "open" as the verb, not NULL.
--Mike--
"COM didn't solve the old version of DLL hell - it just provided us with a new and improved version of hell."
-- John Simmons, 1/22/2002
My really out-of-date homepage
Sonork - 100.10414 AcidHelm
Big fan of Alyson Hannigan.
|
|
|
|
|
if you are reading some input like this:
"JOHN 444-44-4444 Student"
and you want to create some object with those 3 variables>
how can you assign every detail to the right variable provided you have all the accessors and mutators?
thanx
|
|
|
|
|
sscanf
: Wherever you go, there you are, and you wish you were somewhere else :
|
|
|
|
|
can some one tell me please how do you write the return type of a function that would return an array of characters?
thanks in advance!
|
|
|
|
|
I am assuming you want a standard "c" style array.
In that case, your function prototype should look like this:
char* SomeFunction();
|
|
|
|
|
Matt Gullett wrote:
char* SomeFunction();
I'm not so sure. How would he know the number of elements? Unless the array is zero-terminated, but then he would call it a string and not an array of characters.
I vote pro drink
|
|
|
|
|
You are correct, he asked for an "array of characters" and I assumed he wanted a string.
To return an array with no predefined terminators or size, you could do one of several things.
1. Create a custom class to deal with it.
2. Instead of using a return value, use function parameters
void SomeFunction(char** pszValue, int& iLen);
This would be good if the function needed to determine the length and allocate the memory.
OR
void SomeFunction(char* pszValue, int iMaxLen);
This would be good if the function just needed a pre-exising array of max size.
3. Use a byte array and use the first N bytes to specify the length.
I am sure there are many other ways to do this also.
Matt Gullett
|
|
|
|