|
WOW! SORRY guys I did not know that it takes too many place ...
brainiax@wp.pl
|
|
|
|
|
Hello,
I am new to .Net and more of an old school programmer. I for the life of me can’t make srand() work in .Net. this is the line of code that has always worked for me in the past:
srand(time(NULL));
The Error I get is:
error C2365: 'srand' : redefinition; previous definition was a 'function'
And
error C2501: 'srand' : missing storage-class or type specifiers
Now that damn intellisense or however you spell it tells me that srand() will return an int when I hover my mouse over the function call. So I thought that the computer knew what was going on so I tried to catch that int in a variable only to be told:
error C2440: 'initializing' : cannot convert from 'void' to 'int'
So after searching many web sites and books the only way I can find to seed the rand() is with srand(). Have I been left in the dark? Has the call to the system clock changed? What is going on with my lousy srand() call?
P.S. I did include time.h and I have not redefined srand() or rand() at all. I am new to namespace std so maybe I have messed something up in there.
Thanks.
|
|
|
|
|
That still gives the same problem. Am I suppose to be using :: on the rand class? I tried that and it did not work, I also tried using it on noting just like you said. The little menu pops up and teases me that srand() exists but still no luck.
|
|
|
|
|
This is my basic header file that has:
#pragma once
#define WIN32_LEAN_AND_MEAN
#include <stdio.h>
#include <tchar.h>
#include <iostream>
#include <fstream>
using namespace std;
I have:
#include <vector>
using namespace std;
in classes that do not use the my standard header file.
In my rand.h file where the problem is occurring I have:
#include <time.h>
that’s all.
|
|
|
|
|
I messed up that last post so lets try again.
This is my basic header file that has:
#pragma once
#define WIN32_LEAN_AND_MEAN
#include <stdio.h>
#include <tchar.h>
#include <iostream>
#include <fstream>
using namespace std;
I have:
#include <vector>
using namespace std;
in classes that do not use the my standard header file.
In my rand.h file where the problem is occurring I have:
#include <time.h>
that’s all.
|
|
|
|
|
srand is defined in stdlib.h, so try to include that header in your project.
// Afterall, I realized that even my comment lines have bugs
When one cannot invent, one must at least improve (in bed).-My latest fortune cookie
|
|
|
|
|
I got it. I had placed srand() outside of a function so it thought it was definition. Thanks for the help.
|
|
|
|
|
Since I can't add an attachment, I will try to explain.
My tool bar has button that are 32X32 pixels.
I also added two edit boxes after the button.
The problem is that in order to add the edit box, you have to use a SEPARATOR as a place holder in the .rc file and now this separator is showing behind my edit box which is not as thick as the 32X32 buttons.
Got it ?
Shay
|
|
|
|
|
nop,
If I will do that, it will affect the size and location fo my Edit box that is on top of the separator.....
Any more ideas ?
Shay
|
|
|
|
|
|
Excellent !
Exactly what I was looking for.
Thanks.
|
|
|
|
|
I had no problem with:
_bstr_t *arr = new _bstr_t[10];
BSTR bstrName = L"Howard";
arr[0] = L"string_one " + _bstr_t(bstrName) + L" string_three";
arr[1] = L"string";
arr[2] = L"Moe";
arr[3] = L"Larry";
arr[4] = L"Curly";
TRACE("%s\n", (char *) arr[0]);
TRACE("%s\n", (char *) arr[2]);
TRACE("%s\n", (char *) arr[4]);
|
|
|
|
|
Me neither.
I checked the memory again and there are differences between creating _bstr_t using SysAllocString and not using it.
Not using SysAllocString has overwritten one of my other variables! That seems to be THE problem. Is there an easy way how to Alloc and Free all the variables regarding the internally use of pointers (_bstr_t wrapper class)?
I need to create long strings out of smaller ones. The length is variable.
|
|
|
|
|
Hi guys
How can I manage the right click message in a CListBox Control?
Best Regards
Dr.Pi
|
|
|
|
|
subclass it and handle it's WM_RBUTTONDOWN message
|
|
|
|
|
Oh , stupid of me. It was really easy.
Thanks a lot
Dr.pi
|
|
|
|
|
now it's me who has a question...
i need some information on how to retrieve the hardware's name by irq or the other way round!
any1 got an idea?
thx for every answer
Don't try it, just do it!
|
|
|
|
|
AFAIK,
Either you do it the no-brains VB-way and use WMI, or you do it the more low-level DDK way using... well, the NT Object API (not sure if that' documented though - you might need to go undocumented).
AFAIK there is no Win32 way (if you want to, you might read that as "MS never considered us Win32 developers 'worthy' to know this").
Sorry for the bad news, even that this is only AFAIK. Sucks, doesn't it.
|
|
|
|
|
lol, i won't do this the vb way of course
i'll check the kernel's api, maybe i'll find a useful one..
thx 4 you answer
Don't try it, just do it!
|
|
|
|
|
muhaha, i've just found a way!
there are some registry keys for it!
Don't try it, just do it!
|
|
|
|
|
I am attempting to write a simple MFC application that can pass user defined messages across classes.
I start a new MFC app and created 2 classes via classwizard, say CSendClass and CReceiveClass (both derived from generic Cwnd). To create the user-defined message stuff, I:
1. add the line "#define WMU_FUN_MSG (WM_APP + 20)" to stdafx.h (making it global)
2. Add the line "ON_MESSAGE(WMU_FUN_MSG, OnFunMessage)" in CReceiveClass.cpp, inbetween the lines BEGIN_MESSAGE_MAP(CReceiveClass, CWnd) and END_MESSAGE_MAP()
3. Add the line "afx_msg LRESULT OnFunMessage(WPARAM wParam, LPARAM lParam)" in CReceiveClass.h, just before DECLARE_MESSAGE_MAP()
4. Add the following message handling function to the end of CReceiveClass:
LRESULT CReceiveClass::OnFunMessage(WPARAM wParam, LPARAM lParam){
MessageBox("In WMU_FUN_MSG handler", NULL, MB_OK);
return 0;
}
Now that all the Message Handler stuff resides in CReceiveClass, I add the following line to the constructor of CSendClass:
"PostMessage(WMU_FUN_MSG, 0, 0);"
Finally, I added the following two lines to the Dialog Box's OnCreate Function:
CReceiveClass obj1; //Create instance of the receiving class
CSendClass obj2; //Create an instance of the sending class
Ideally, this is what the program should do:
1.. Program starts, creates CReceiveClass obj1 and CSendClass obj2.
2. In constructor for CSendClass obj2, PostMessage() is called, send a user defined message
3. CReceiveClass's message handler function is called, printed a MessageBox to the screen.
Unfortunately, it doesnt work that way. My program crashes when it gets to the PostMessage command, displaying a "Debug Assertion Failed!" dialog box. Because of this, my MessageBox is never displayed.
Any insight you can give would be most appreciated.
-Joel L.
Joel L.
|
|
|
|
|
Joel Lipschultz wrote:
"PostMessage(WMU_FUN_MSG, 0, 0);"
For user defined messages, I have found that this line should be:
PostMessage (WM_COMMAND, WMU_FUN_MSG, 0);
Dave
"You can say that again." -- Dept. of Redundancy Dept.
|
|
|
|
|
no change, my program still crashes. Thanks anyways.
Joel L.
|
|
|
|
|
Not sure about that. In this case you'll have to manage ON_COMMAND handler and no more ON_MESSAGE !!
But you can use PostMessage(WMU_FUN_MESSAGE,0,0) if you want!
|
|
|
|
|
cedric moonen wrote:
But you can use PostMessage(WMU_FUN_MESSAGE,0,0) if you want!
his message handler isn't in the same window, he has to use
::PostMessage(m_hWnd_of_CReceive, WMU_FUN_MESSAGE,0,0);
When he's checked ASSERT(::IsWindow(::FromHandle(m_hWnd_of_CReceive)));
|
|
|
|