Click here to Skip to main content
15,947,612 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: check file opened or not? Pin
basementman2-Apr-08 4:55
basementman2-Apr-08 4:55 
GeneralRe: check file opened or not? Pin
George_George2-Apr-08 20:38
George_George2-Apr-08 20:38 
AnswerRe: check file opened or not? Pin
Hamid_RT7-Apr-08 4:07
Hamid_RT7-Apr-08 4:07 
GeneralRe: check file opened or not? Pin
George_George7-Apr-08 4:10
George_George7-Apr-08 4:10 
GeneralRe: check file opened or not? Pin
Hamid_RT7-Apr-08 4:29
Hamid_RT7-Apr-08 4:29 
GeneralRe: check file opened or not? Pin
George_George7-Apr-08 4:38
George_George7-Apr-08 4:38 
GeneralRe: check file opened or not? Pin
Hamid_RT7-Apr-08 5:07
Hamid_RT7-Apr-08 5:07 
GeneralWrong DLL output Pin
parth.p2-Apr-08 3:15
parth.p2-Apr-08 3:15 
Hi,
I have a DLL written in C and I am calling it from VB and I am using Visual Studio 6. The problem I have is that I'm trying to receive RANDOM number from C and add to my VB form. But the number received is not random or is way to big than what I pass into the parameter.

Here's the Code for .CPP
<br />
#include "stdafx.h"<br />
#include <stdlib.h><br />
#include <stdio.h><br />
#include <time.h><br />
<br />
<br />
<br />
BOOL APIENTRY DllMain( HANDLE hModule, <br />
                       DWORD  ul_reason_for_call, <br />
                       LPVOID lpReserved<br />
					 )<br />
{<br />
    return TRUE;<br />
}<br />
<br />
int _stdcall rndNum(int iMaxNum)<br />
{<br />
	int iNum;<br />
	//srand( (unsigned)iMaxNum );<br />
<br />
<br />
	srand( (unsigned)time( NULL ) );		<br />
<br />
<br />
	iNum =  rand() % iMaxNum;<br />
	<br />
	return iNum;<br />
<br />
}<br />
</time.h></stdio.h></stdlib.h>


.DEF file
<br />
LIBRARY CdllRndNum<br />
<br />
EXPORTS<br />
rndNum @1<br />


VB Code
<br />
Private Declare Function rndNum Lib "F:\Year - 2\CdllRndNum\Debug\CdllRndNum.dll" (ByRef iMaxNum As Integer) As Integer<br />
<br />
Sub AddNums()<br />
Dim i As Integer<br />
For i = 0 To 40<br />
    <br />
    List1.AddItem rndNum(100)<br />
<br />
Next i<br />
<br />
End Sub<br />


Result VB:

28156
28156
28156
28156
28156 and same and same again....


Result C:
Number is 30
Number is 43
Number is 16
Number is 24
Number is 25
Number is 63
Number is 62
Number is 84
Number is 40
Number is 64
Number is 77
Number is 79
Press any key to continue


The C code gives me perfect results in C Console app. But not in VB. Anyone any idea what is going wrong??Confused | :confused: Confused | :confused: Confused | :confused:

- Stop thinking in terms of limitations and start thinking in terms of possibilities -

GeneralRe: Wrong DLL output Pin
Cedric Moonen2-Apr-08 3:18
Cedric Moonen2-Apr-08 3:18 
GeneralRe: Wrong DLL output Pin
parth.p2-Apr-08 3:22
parth.p2-Apr-08 3:22 
GeneralRe: Wrong DLL output Pin
Chris Losinger2-Apr-08 3:27
professionalChris Losinger2-Apr-08 3:27 
GeneralRe: Wrong DLL output Pin
Cedric Moonen2-Apr-08 3:29
Cedric Moonen2-Apr-08 3:29 
GeneralRe: Wrong DLL output Pin
parth.p2-Apr-08 3:42
parth.p2-Apr-08 3:42 
GeneralRe: Wrong DLL output Pin
David Crow2-Apr-08 3:33
David Crow2-Apr-08 3:33 
GeneralRe: Wrong DLL output Pin
Cedric Moonen2-Apr-08 3:37
Cedric Moonen2-Apr-08 3:37 
QuestionRe: Wrong DLL output Pin
David Crow2-Apr-08 3:23
David Crow2-Apr-08 3:23 
GeneralRe: Wrong DLL output Pin
parth.p2-Apr-08 3:30
parth.p2-Apr-08 3:30 
GeneralRe: Wrong DLL output Pin
parth.p2-Apr-08 4:18
parth.p2-Apr-08 4:18 
GeneralRe: Wrong DLL output Pin
Cedric Moonen2-Apr-08 4:23
Cedric Moonen2-Apr-08 4:23 
GeneralRe: Wrong DLL output Pin
parth.p2-Apr-08 4:39
parth.p2-Apr-08 4:39 
GeneralRe: Wrong DLL output Pin
CPallini2-Apr-08 4:43
mveCPallini2-Apr-08 4:43 
GeneralRe: Wrong DLL output Pin
David Crow2-Apr-08 4:48
David Crow2-Apr-08 4:48 
GeneralRe: Wrong DLL output Pin
Chris Losinger2-Apr-08 3:29
professionalChris Losinger2-Apr-08 3:29 
GeneralRe: Wrong DLL output Pin
parth.p2-Apr-08 3:43
parth.p2-Apr-08 3:43 
GeneralRe: Wrong DLL output Pin
CPallini2-Apr-08 4:36
mveCPallini2-Apr-08 4:36 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.