|
hi me again, ive been writting code that fills a vector with random numbers from two sources, all even elements are filled from source1 and odd ones from source2...this now works fine after much debuggingmyhead.
ive been trying to to do next part of my function which is more complex, it basically uses a iterator with a const value of 0.002. which is 20millseconds.
this iterator goes to every single element in the array and goes through every element in 0.002 segments..i.e if element value is 3.6 then it goes through it in 1,800 segements. basically splitting up the element into segments,
and it does this to distingusih between numbers from sourceone and sourcetwo because these numbers are usesd elsewhere.. i will paste the code which fills the vector and ive COMMENTEDout the 'new' but it doesnt work imnot sure what else to do.
#include <iostream><br />
#include <vector><br />
#include <stdlib><br />
#include <time><br />
#include <numeric><br />
#include <algorithm><br />
#include "exponentialgenerator.h"<br />
<br />
using namespace std;<br />
<br />
ExponentialGenerator one = 1.41;<br />
ExponentialGenerator two = 1.71;<br />
<br />
double nextNumber = reinterpret_cast<double>(one.generate());<br />
<br />
double nextNumber2 = reinterpret_cast<double>(two.generate());<br />
<br />
int counter = 0;<br />
<br />
void fillVectorToSum(vector<double>& v, double sum)<br />
{<br />
<br />
int total = 0;<br />
do {<br />
if (counter++ % 2){<br />
v.push_back(nextNumber);<br />
total += nextNumber;<br />
nextNumber = one.generate();<br />
}<br />
else {<br />
v.push_back(nextNumber2);<br />
total += nextNumber2;<br />
nextNumber2 = two.generate();<br />
}<br />
<br />
} while(total+nextNumber+nextNumber2 <= sum);<br />
if(total < sum)<br />
v.push_back(sum-total);<br />
}<br />
<br />
<br />
int main()<br />
{<br />
<br />
srand((unsigned) time(NULL));<br />
vector<double> v;<br />
fillVectorToSum(v, 30);<br />
<br />
cout << "Number of elements: " << v.size() << "\nTotal: "<br />
<< accumulate(v.begin(), v.end(), 0) << endl;<br />
copy(v.begin(), v.end(), ostream_iterator<double> (cout," "));<br />
<br />
<br />
<br />
<br />
<br />
<br />
}
|
|
|
|
|
I would like to determine if a computer is a member of domain or not.
I tried GetPDC but it seem to be returning the workgroup's name.
Enumerating network is also useless, since it is returning other standalone machine's names.
Any ideas about how to do this?
Orcun Colak
|
|
|
|
|
Use NetWkstaGetInfo() .
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
|
In my view class in the LButtonDown()I have
CPaintDC dc;
CRect c;
GetClientRect(&c);
dc.TextOut(c.Width()/2, c.Height()/2," abc");
I dont see the text when I click.
DO I need a different kind of DC? I was actually trying to do DrawIcon but when i didnt see the icon, I thought I'd see if textout worked....neither does..
thanks,
ns
|
|
|
|
|
Try CClientDC instead of CPaintDC.
MSN Messenger.
prakashnadar@msn.com
Tip of the day of visual C++ IDE.
"We use it before you do! Visual C++ was developed using Visual C++"
|
|
|
|
|
Thanks! The textout works. But this doesnt still:
dc.DrawIcon( f, w, hIcon3);
Does this need yet some other special DC? Why wasnt PaintDC suitable for TextOut? How do you choose which type of DC to use?
Thanks again,
ns
|
|
|
|
|
Imho drawing in mouse message handler is not a good practice. Does your picture should stay after you release button? Try placing other application above yours, and your picture will be lost.
Igor Green
http://www.grigsoft.com/ - files and folders comparison tools
|
|
|
|
|
ns wrote:
Why wasnt PaintDC suitable for TextOut
It wasn't that the CPaintDC wasn't suitable for a TextOut call it's that it wasn't suitable for where you were using it. CPaintDC should only be used in an OnPaint message handler. The reason behind this, as far as I know, is that it calls some functions (BeginPaint, EndPaint) that set the update region (area you can actually "paint" in) and in your button handler there probably hasn't been any part of your window that's been invalidated, therefore a CPaintDC wouldn't have any valid drawing area.
- Aaron
|
|
|
|
|
在这个论坛上必须发英文吗
I'm sorry!
I can't speak english
CDC* dc;
dc = GetDC();
dc->textout();
d
|
|
|
|
|
I use some structures in an app using pointers, basically everytime the program gets updated these addresses change slightly, I usually get told by someone what the address is.
Basically I want to be able to automatically find the address of the structure in the app, but i'm not sure how to do it.. I think i remember someone saying pattern searching or something.
Any help is appreciated.
|
|
|
|
|
I think I know what you are asking, but your comments make me think otherwise. Have you tried the address-of operator?
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
What do you use the address for ? is it a memeory address or a file offset number ?
MSN Messenger.
prakashnadar@msn.com
Tip of the day of visual C++ IDE.
"We use it before you do! Visual C++ was developed using Visual C++"
|
|
|
|
|
Your question is not clear.
Gurmeet S. Kochar
If you believe in God, it's because of the Devil
|
|
|
|
|
This question makes no since! What do you mean by "...someone what the address is." Either the code knows what the address is or it doesn't. You might know what the address is at a given run of the program and your debugger might give you the same address every time you rebuild, until you modify the code. But the address may be relitive to the base address of your program or it may be allocated (could be anywhere). You should never need to know the actual address (except maybe when debugging). Pattern searching has nothing to do with finding an address.
struct whatever {...};
struct whatever* pAddr;
or
myfunct(struct whatever* pAddr)
{
}
struct whaterver {...};
whatever* pAddr;
or
myfunct(whatever* pAddr)
{
}
INTP
|
|
|
|
|
Hi:
I want to let the CStatusBar support background bmp(just like CRebar's background).I try to draw the bmp in the onerasebackground() function,but it seems that this way only works in winxp;in win98/me/2000,the background doesn't show correctly.Could you give me any idea or any examplt?
Thanks
Benben
|
|
|
|
|
try OnPaint
Don't try it, just do it!
|
|
|
|
|
|
Hy everybody!
I'm having a little problem in a Windows Service (DOS App)...
I create a CAsyncSocket derived class to work as a server. I use the Listen(), and after that, I wait for a connection on my OnAccept(). Everything works fine... the socket is created, is listening (so I hope)... but when a connection request comes, nothing happens... and don't run the OnAccept mapped function.
(where I'll make Accept() in another socket)
The Unix process (my client) says to me that is connected and begin send data to me... but I even know that I'm connected with it.
Does anybody knows what could be happen?
thanks folks,
cheers!
|
|
|
|
|
Here is a possible cause of your problem:
The OnAccept() method is not called because there is no message pump in your windows service.
Here is my understanding (see MFC source code): When a request comes from a remote program, it is turned into a windows WM_SOCKET_NOTIFY message and posted to an internal window used by CAsynSocket. When the WM_SOCKET_NOTIFY message is processed by MFC, it will invoke the event handlers such as OnAccept, OnReceive, etc. Unless you added a message loop to your windows service, the WM_SOCKET_NOTIFY message will never be processed.
If you cut and paste your code into a MFC dialog based application, assuming there is no other bug, it will work.
If that is confirmed to be the problem, there are at least two relatively easy solutions.
1. Start a separate thread from the windows service. Create the socket in this new thread, call Create/Bind/Listen for the socket, then use a loop to call Accept/Reciev/Send (i.e. don't rely on the OnAccept notification).
2. Move everything to a dialog based application, when the program works, use this special windows service[^] to run your application.
Good luck.
P.S. Solution 1 does not work if multiple clients have to connect to your server simultaneously, in which case you need to add a message pump and rely on the socket events.
My articles and software tools
|
|
|
|
|
Ok, thanks Xiangyang Liu
I'll see if this is the problem, and if so, I'll try one of your sugestions.
Thanks a lot!
cheers!
|
|
|
|
|
The MFC socket classes depend on a message loop to process the notifications properly. Services don't have message loops (normally anyways) so I always use the low level socket routines for services. Check MSDN and they will explain the limitations of CSocket amd CAsyncSocket.
.............................
There's nothing like the sound of incoming rifle and mortar rounds to cure the blues. No matter how down you are, you take an active and immediate interest in life.
|
|
|
|
|
Well, Microsoft Installer (MSI) is a technology (or file format) rather than a tool for authoring installations. InstalShield and Wise produce MSI installations too.
|
|
|
|
|
Hello
Could anyone help me about the "Win 32 error 267" I get when I run a .exe I just correctly compiled with Visual C++?
The associated message is: "Could not execute: invalid directory"
As I'm a beginner, it may be a very stupid mistake....
Thank you in advance
JET
|
|
|
|
|
Is your executable (code) attempting to open a file or a document that does not exist, or does it specify a directory that does not exist ?
That is the apparent reason for the error, so you should check your code throughoghly. Then, set breakpoints into the code and use the debugger to determine the point where this error is caused.
It might also be that your user account has no execution priviledges on the directory where the executable resides. In this case, contact the Systems Administrator for a solution.
-Antti Keskinen
----------------------------------------------
The definition of impossible is strictly dependant
on what we think is possible.
|
|
|
|