|
I am not actually sure how to debug DLL :s
- Stop thinking in terms of limitations and start thinking in terms of possibilities -
|
|
|
|
|
here's how i debug DLL + VB situations:
1. in the C++ project, "run" the DLL.
2. VS will prompt you for a debug target. tell it to run VB.exe (VB itself)
3. when VB opens, open your VB application
4. put a breakpoint on the call to your DLL
5. run your VB app
now you can step into your C++ DLL
|
|
|
|
|
Quoted from this page[^]:
One important note is that all parameters must be passed with the ByVal keyword. This is because Visual Basic always passes parameters ByRef by default. Since C/C++ usually passes by value, this must be specified in the Visual Basic declaration. This is all that is necessary when standard C variable types (int, long, etc.) are used, however complex data types like strings and arrays require more overhead on both the client and DLL sides.
They also specify that a VB integer correspond to a short in C/C++. So, change the C function to accept a short and check if it works (and don't forget the ByVal).
|
|
|
|
|
Hi first of all thanks for quick reply.
Some how I realised that the speed of DLL and EXE could vary, so now I have timer which will get number every second. AND I did what you just said and now it's giving me random number between 0(1) - 100 (never seen 0 or 100) but yeh. But what happens now is that the numbers comes in ascending order.
2
12
43
56
78
90
95
1
3
5
and so on...
What surprises me most is that the same code works perfect with C but not with VB.
- Stop thinking in terms of limitations and start thinking in terms of possibilities -
|
|
|
|
|
Cedric Moonen wrote: ...but shouldn't you pass the integer ByVal instead of ByRef ?
I don't see this making any difference since the ByVal /ByRef keyword only affect how the argument is sent to rndNum() , not what type of value is returned from it.
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
I don't know how it is implemented in VB, but if the ByRef is in fact passing the address of the variable, then this is the problem because that will have an impact on what the function returns (because the random number will be between 0 and that number).
|
|
|
|
|
killerp wrote: ...I'm trying to receive RANDOM number from C and add to my VB form.
Unless this is just a test to see if the two can communicate, or you are just wanting to see how a DLL works, why not just let your VB app generate its own random numbers?
killerp wrote: But the number received is not random...
How are you verifying this?
killerp wrote: But the number received is...way to big than what I pass into the parameter.
This statement makes little sense. The argument passed to rndNum() is simply used to seed the random number generator. It has no bearing on anything else.
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
I'm doing bit of research on random numbers from different language, and I am already using VB, C# and C So I see what you are trying to say, but I want to use this.
- Stop thinking in terms of limitations and start thinking in terms of possibilities -
|
|
|
|
|
Hi,
Thanks for reply.
I haven't got any special method to verify the numbers received... It's just common sense to recognise Random numbers.
The other thing I figured out just now is that the problem lies in
srand( (unsigned)time( NULL ) );
I just removed this line and everything is working as I expected! But now i will get same numbers every time I use it. This simple dll is becoming more and more complicated...
- Stop thinking in terms of limitations and start thinking in terms of possibilities -
|
|
|
|
|
You should call srand only once, for example in the DllMain.
|
|
|
|
|
Yeh, I got this sorted now. It was srand. Because the speed of accessing values and passing value is so fast it was passing same time into srand. SO now i got static int and it will make sure that srand only takes place once when the application is started.
Anyway thanks for all you guys support. THANK YOU ALL.
- Stop thinking in terms of limitations and start thinking in terms of possibilities -
|
|
|
|
|
Probably will be better exporting srand too, otherwise he needs to restart the executable each time he needs a different sequence.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
In order for what you have to work, you're going to need a really, really slow computer. The problem is not int vs. long vs. short , or ByVal vs ByRef , but rather that rndNum() is being called so fast, that each call to srand() is seeding with the same value. To demonstrate this, put a call to Sleep(750) between srand() and rand() .
Moving srand() to DllMain() is what you need.
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
also, try using "Long" instead of "Integer" for the VB declaration. an Integer is 16 bits, a Long is 32 bits (like a C int)
|
|
|
|
|
Hi I did it but the results don't change much... cuz the MAX number I am thinking to use is 3000 so...
- Stop thinking in terms of limitations and start thinking in terms of possibilities -
|
|
|
|
|
1. You need to use the following declaration
Private Declare Function rndNum Lib "F:\Year - 2\CdllRndNum\Debug\CdllRndNum.dll" (ByVal iMaxNum As Long) As Long
killerp wrote: srand( (unsigned)time( NULL ) );
2. The above is a mistake. Don't initialise the random number generator each time you're calling it (and remember, time returns seconds).
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
i may not be an expert but if all you need is a random number in VB you should use:
' Initialize the random-number generator.<br />
Randomize()<br />
' Generate random value between 1 and 6.<br />
Dim value As Integer = CInt(Int((6 * Rnd()) + 1))<br />
|
|
|
|
|
Hey Thanks for Reply, but I have already mentioned that I DO NOT WANT TO USE VB (and yes I do know how to do it in VB. For .NET there is another method available by using Random class and then Random.Next())
But anyway thanks for reply.
- Stop thinking in terms of limitations and start thinking in terms of possibilities -
|
|
|
|
|
Hi
How can I compare CTime with FITETIME?
|
|
|
|
|
Hint: one of the CTime constructors looks promising
CTime(
const FILETIME& ft,
int nDST = - 1
);
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
See here[^] if its helpfuls.
|
|
|
|
|
Hi all,
I m using VC++2005,and in my application i m using editboxcontrol for enter numeric values.
but now i have a problem how can i get this numeric value from editboxcontrol.
please anyone can help me.
thanks in advance.
|
|
|
|
|
By associating a variable to the control and calling UpdateData(TRUE) in your dialog class.
You could also retrieve the text of the window by calling GetWindowText on the control.
Anyway, it is a very very basic question and it seems that you really need a good book about MFC. You'll be much more efficient that asking questions on a forum whenever you have an issue.
|
|
|
|
|
Thanks
Can u please suggest me a book for MFC because i m new in this field
|
|
|
|
|
"Programming Windows with MFC" by Jeff Prosise.
|
|
|
|