|
Hi All
error C2440: '=' : cannot convert from 'void *' to 'FL_FILE *'
how can i solve this error?
I use Precompiled Headers off.
Code is here
void main()
{
FL_FILE *file;
media_init();
fl_init();
if (fl_attach_media(media_read, media_write) != FAT_INIT_OK)
{
printf("ERROR: Media attach failed\n");
return;
}
fl_listdirectory("/");
file = fl_fopen("/file.bin", "w");
if (file)
{
unsigned char data[] = { 1, 2, 3, 4 };
if (fl_fwrite(data, 1, sizeof(data), file) != sizeof(data))
printf("ERROR: Write file failed\n");
}
else
printf("ERROR: Create file failed\n");
fl_fclose(file);
}
|
|
|
|
|
You haven't really given people many clues to solve this one. Like which line the error occurs on... And no includes. And no mention of what library you're using (where all the fl_* guff comes from).
After that it looks like the only place you can get this error is file = fl_fopen("/file.bin", "w"); From the error message it looks like fl_open returns a void * and you're trying to assign it to an FL_FILE * . However as it looks like you're using C and not C++ that should be an allowed conversion...
Are you:
- compiling your code as C++ when it should be compiled as C?
- including all the headers you should be for the library you're using?
- using any build configuration settings, like #defines, that the library writer specified?
In addition have you tried compiling the code with all warnings switched on (that's /W4 on both VC++ and gcc)? That might give you some hints as to what's going on.
Ash
|
|
|
|
|
My questions is, im trying to make a small benchmark and im not sure if i am correctly doing this.
I am using a high-resolution performance counter, ive placed it in bold
This uses MD5, which you can simply get it at http://www.evenbalance.com/downloads/pbmd5.cpp[^]
im not really sure if im getting the correct bytes per second
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include "md5.h"
#define MUL_BYTES 1024
#define MUL_KB (MUL_BYTES*1024)
#define MUL_MB (MUL_KB*1024)
void Benchmark_MD5(void)
{
unsigned __int64 iPerf;
unsigned __int64 iBaseTime;
double dbFreq;
unsigned char bzBuffer[] = {0x0a, 0x55, 0x23};
unsigned __int64 iValue;
MD5_CTX md5;
int iPasses = 5000;
QueryPerformanceFrequency((LARGE_INTEGER *)&iPerf);
dbFreq = 1.0 / (double)iPerf;
QueryPerformanceCounter((LARGE_INTEGER *)&iBaseTime);
for (int i = 0; i < iPasses; i++) {
MD5Init(&md5, 0);
MD5Update(&md5, bzBuffer, 3);
MD5Final(&md5);
}
QueryPerformanceCounter((LARGE_INTEGER *)&iValue);
double seconds = ((double)(iValue - iBaseTime) * dbFreq);
double bps = (double)((double)(16 + iPasses) / seconds);
printf("DEBUG: [Passes = %d] %5.3f Byte/s\n", iPasses, bps);
printf("RESULT:\t");
if (bps < MUL_BYTES)
printf(" %5.2f Bytes/sec\n", bps);
else if (bps < MUL_KB)
printf(" %5.2f KB/sec\n", bps / 1024);
else if (bps < MUL_MB)
printf(" %5.2f MB/sec\n", bps / 1024 / 1024);
else
printf(" %5.2f GB/sec\n", bps / 1024 / 1024 / 1024);
}
void main(void)
{
Benchmark_MD5();
}
|
|
|
|
|
|
This is the results
DEBUG: [Passes = 5000] 311191.953 Byte/s
RESULT: 303.90 KB/sec
DEBUG: [Passes = 5000] 734956.927 Byte/s
RESULT: 717.73 KB/sec
DEBUG: [Passes = 5000] 391962.053 Byte/s
RESULT: 382.78 KB/sec
DEBUG: [Passes = 5000] 274082.350 Byte/s
RESULT: 267.66 KB/sec
DEBUG: [Passes = 5000] 281520.063 Byte/s
RESULT: 274.92 KB/sec
|
|
|
|
|
saiyuk6=7 wrote: double seconds = ((double)(iValue - iBaseTime) * dbFreq);
To get seconds, shouldn't you be dividing by the timer's frequency?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
I've updated the code somewhat now, i have taken your advice by dividing the timers freq
i've changed how the bps is calculated as well
double bps = (double)((ulSize * iPasses) / tm.Seconds());
i've multiplied the Size of the Buffer by the number of passes that runs in the for loop
results are
<br />
DEBUG: 1074556249.047 Byte/s<br />
MEMSET: 0.00/sec 0.98/ms 1.00 GB/sec<br />
RESULT: 6.91/sec 6905.56/ms 72.41 MB/sec<br />
class CTimer {
public:
CTimer() {
m_TimeStart.QuadPart = 0;
m_TimeStop.QuadPart = 0;
QueryPerformanceFrequency(&m_Frequency);
}
void Start(void) {
QueryPerformanceCounter(&m_TimeStart);
}
void Stop(void) {
QueryPerformanceCounter(&m_TimeStop);
}
double Seconds() const {
return (double)(m_TimeStop.QuadPart - m_TimeStart.QuadPart) / (double)m_Frequency.QuadPart;;
}
double Milliseconds() const {
return Seconds() * 1000.0;
}
private:
double m_dbFreq;
LARGE_INTEGER m_Frequency;
LARGE_INTEGER m_TimeStart;
LARGE_INTEGER m_TimeStop;
};
#define MUL_BYTES 1024.0
#define MUL_KB (MUL_BYTES*1024.0)
#define MUL_MB (MUL_KB*1024.0)
#define MUL_GB (MUL_MB*1024.0)
std::string BPStoString(double dbPerSec)
{
char *pTemp[] = {
"Bytes", "KB", "MB",
"GB", "TB", "PB",
"EB", "ZB", "YB"
};
char szTemp[30];
int i = 0;
while (dbPerSec >= 0.9 * MUL_BYTES) {
dbPerSec /= MUL_BYTES;
i++;
}
sprintf(szTemp, "%5.2f %s/sec", dbPerSec, pTemp[i]);
return std::string(szTemp);
}
void Benchmark_MD5(void)
{
CTimer tm;
tm.Start();
unsigned long ulSize = MUL_KB;
unsigned char *bzBuffer = new unsigned char[ulSize];
if (bzBuffer != NULL) {
memset(bzBuffer, 0, ulSize);
tm.Stop();
<code>double bps = (double)((ulSize * 1) / tm.Seconds());</code>
printf("DEBUG: %5.3f Byte/s\n", bps);
printf("MEMSET: %5.2f/sec %5.2f/ms %s\n", tm.Seconds(), tm.Milliseconds(),BPStoString(bps).c_str());
}
tm.Start();
MD5_CTX md5;
int iPasses = 500;
for (int i = 0; i < iPasses; i++) {
MD5Init(&md5);
MD5Update(&md5, bzBuffer, ulSize);
MD5Final(&md5);
}
tm.Stop();
<code> double bps = (double)((ulSize * iPasses) / tm.Seconds());</code>
printf("RESULT: %5.2f/sec %5.2f/ms %s\n", tm.Seconds(), tm.Milliseconds(),BPStoString(bps).c_str());
delete bzBuffer;
}
modified on Monday, July 19, 2010 8:57 PM
|
|
|
|
|
saiyuk6=7 wrote: unsigned char *bzBuffer = new unsigned char[ulSize];
Why not:
unsigned char bzBuffer[MUL_KB];
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
well i've tried doing that but i get this error
bm.cpp
bm.cpp(40) : error C2057: expected constant expression
bm.cpp(40) : error C2466: cannot allocate an array of constant size 0
bm.cpp(40) : error C2133: 'bzBuffer' : unknown size
Well i had started to allocate memory for it because later on i was going to start using a hash driver that i was going to make that would provide me with several hash algo's,.... example
there might be errors below, but its just a example of what i had planned to do
unsigned char *bzBuffer;
for (int i = HT_MD5; i < (HT_WHIRLPOOL + 1); i++) {
hash.Init(i);
bzBuffer = new unsigned char[hash.DigestSize()];
if (bzBuffer == NULL) {
return 0;
}
hash.Update(hashTest[i].buffer, hashTest[i].length);
hash.Final(bzBuffer);
for (int h = 0; h < hash.DigestSize(); h++)
printf("%02.2%", bzBuffer[i]);
delete bzBuffer;
}
modified on Tuesday, July 20, 2010 12:28 PM
|
|
|
|
|
int _cdecl main(int argc, char *argv[])
{
OutputDebugString("Hello World");
}
When I compile and debug with Target = Win32 I get:
Hello World
(plus a lot of 'instlsp.exe': Loaded 'C:\WINDOWS\SysWOW64\....dll', Cannot find or open the PDB file)
When I compile and debug with Target = x64 I get nothing
It runs but the output is filtered somewhat.
I tried this
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Debug Print Filter]
"DEFAULT"=dword:0000000f
And also 0xFFFFFFFF
No success even after reboot.
I feel like I am stuck in chapter 1 of the Kernighan and Ritchie C book.
I am using Visual C++ Express under Windows XP Pro x64
Is this just a bad day?
Going to the zoo now. Perhaps the monkeys will have a clue, I should take a couple of typewriters with me.
|
|
|
|
|
Pascal Ganaye wrote: Going to the zoo now. Perhaps the monkeys will have a clue,
Sorry, but I have no clue.
Seriously though, I'm on Windows 7 x64 and it works just right for me. Which platform are you on?
It's time for a new sig. Seriously.
|
|
|
|
|
Hi
I am developing a application
knowing the size of downloaded data from the net
for a month for a PC.
How to do this?
|
|
|
|
|
You need to be more specific. What 'data'? Where is it stored? Is it part of your application?
If you have a more intelligent router connecting you to the Internet then you could use SNMP to pull statistics from the router.
Sorry but while you are so vague it is impossible to advise further.
P.S. this is more a general IT question.
Alan
|
|
|
|
|
|
I tried compiling my application in 64bit, during compilation I got errors. Cause my application uses UNICODE, does 64bit lack UNICODE support???
|
|
|
|
|
Fareed Rizkalla wrote: Cause my application uses UNICODE
The sentence is not clear.
Do you mean "because I'm using Unicode strings" or "because it seems the UNICODE preprocessor symbol is not defined"?
In the second case, just look in the compiler options if the Unicode support is activated ad if UNICODE and _UNICODE are in the defines symbol specifications.
2 bugs found.
> recompile ...
65534 bugs found.
|
|
|
|
|
It would help if you showed the relevant lines of code and the exact error messages produced by the compiler.
It's time for a new signature.
|
|
|
|
|
I am stuck actually, im trying to write a md5 / blowfish function
im not sure if i am correctly converting the MD5[16] buffer into a unsigned long[4]
this doesnt really make too much sense too me
typedef struct _tag2Long {
unsigned long _1;
unsigned long _2;
unsigned long _3;
unsigned long _4;
} _2LONG;
void SignBuffer(unsigned char *pbzKey, unsigned char *pbzBuffer,
unsigned int iSize, unsigned long pSignature[4])
{
MD5_CTX md5;
BLOWFISH_CTX bf;
MD5Init(&md5);
MD5Update(&md5, pbzBuffer, iSize);
MD5Final(&md5);
_2LONG *tl = (_2LONG*) md5.digest;
printf("BLE 1\t\t %x %x %x %x\n", tl->_1, tl->_2, tl->_3, tl->_4);
Blowfish_Init(&bf, pbzKey, 16);
Blowfish_Encrypt(&bf, &tl->_1, &tl->_2);
Blowfish_Encrypt(&bf, &tl->_3, &tl->_4);
pSignature[0] = tl->_1;
pSignature[1] = tl->_2;
pSignature[2] = tl->_3;
pSignature[3] = tl->_4;
printf("BLE 2\t\t %x %x %x %x\n", pSignature[0], pSignature[1],
pSignature[2], pSignature[3]);
}
bool VerifyBuffer(unsigned char *pbzKey, unsigned char *pSignature,
unsigned int iSize, unsigned long pBuffer[4])
{
BLOWFISH_CTX bf;
MD5_CTX md5;
bool bResult = false;
printf("BLD 1\t\t %x %x %x %x\n", pBuffer[0], pBuffer[1],
pBuffer[2], pBuffer[3]);
Blowfish_Init(&bf, pbzKey, 16);
Blowfish_Decrypt(&bf, &pBuffer[0], &pBuffer[1]);
Blowfish_Decrypt(&bf, &pBuffer[2], &pBuffer[3]);
printf("BLD 2\t\t %x %x %x %x\n", pBuffer[0], pBuffer[1],
pBuffer[2], pBuffer[3]);
MD5Init(&md5);
MD5Update(&md5, pSignature, iSize);
MD5Final(&md5);
_2LONG *tl = (_2LONG*) md5.digest;
if (tl->_1 == pBuffer[0] && tl->_2 == pBuffer[1] &&
tl->_3 == pBuffer[2] && tl->_4 == pBuffer[4])
bResult = true;
return bResult;
}
void main(void)
{
unsigned char bszBuffer[2] = {'A', 'B'};
unsigned long ulSig[4];
SignBuffer((unsigned char*)"key", bszBuffer, 2, ulSig);
printf("\n");
if (VerifyBuffer((unsigned char*)"key", bszBuffer, 2, ulSig))
printf("\nok");
else printf("\nerr");
}
and this is the output of them
BLE 1 b0c66fb8 733df651 4c2d26de a9a0e334
BLE 2 f12b0ed9 782fae18 a87960ac f37b342e
BLD 1 f12b0ed9 782fae18 a87960ac f37b342e
BLD 2 dc95818a 65685d43 8d7d54b9 8827b217
err
modified on Friday, July 16, 2010 3:32 PM
|
|
|
|
|
the conversion looks fine.
but doesn't Blowfish use 64-bit (8-byte) blocks ?
so this Blowfish_Encrypt(&bf, &tl->_1, &tl->_2); will encrypt the 8 bytes starting at tl->_1 ? since _1 is only four bytes, it's going to run over into _2.
so, you're doing BF(_1 + _2) -> _2 + _3.
or maybe not. i don't know what Blowfish_Encrypt looks like.
|
|
|
|
|
|
ah, ok. it's expecting 2 32-bit parts. i thought the params were input and output.
|
|
|
|
|
do you happen to know how i can fix it? i am lost
|
|
|
|
|
you're doing this, right:
Sign:
Sig = BFE(MD5(data))
Verify:
X = BFD(Sig)
Sig2 = MD5(Sig)
Compare:
X == Sig2 ?
but shouldn't that bold line be Sig2 = MD5(data) ? the MD5 of the signature doesn't get you anything.
|
|
|
|
|
i fixed it, thank you very much for your help, i noticed
if (tl->_1 == pBuffer[0] && tl->_2 == pBuffer[1] &&
tl->_3 == pBuffer[2] && tl->_4 == pBuffer[4])
bResult = true;
pBuffer[4] should of been pBuffer[3] i was going out of range of the array which didnt exist
here is the updated code
int _ustrlen(unsigned char *pbz)
{
const unsigned char *ptr;
for (ptr = pbz; *ptr; ++ptr);
return (ptr - pbz);
}
void SignBuffer(unsigned char *pbzKey, unsigned char *pbzBuffer,
unsigned int iSize, unsigned long *pSignature)
{
MD5_CTX md5, md5key;
BLOWFISH_CTX bf;
MD5Init(&md5);
MD5Update(&md5, pbzBuffer, iSize);
MD5Final(&md5);
_2LONG *tl = (_2LONG*) md5.digest;
printf("BLE 1\t\t %x %x %x %x\n", tl->_1, tl->_2, tl->_3, tl->_4);
MD5Init(&md5key);
MD5Update(&md5key, pbzKey, _ustrlen(pbzKey));
MD5Final(&md5key);
Blowfish_Init(&bf, md5key.digest, 16);
Blowfish_Encrypt(&bf, &tl->_1, &tl->_2);
Blowfish_Encrypt(&bf, &tl->_3, &tl->_4);
pSignature[0] = tl->_1;
pSignature[1] = tl->_2;
pSignature[2] = tl->_3;
pSignature[3] = tl->_4;
printf("BLE 2\t\t %x %x %x %x\n", pSignature[0], pSignature[1],
pSignature[2], pSignature[3]);
}
bool VerifyBuffer(unsigned char *pbzKey, unsigned char *pSignature,
unsigned int iSize, unsigned long *pBuffer)
{
BLOWFISH_CTX bf;
MD5_CTX md5, md5key;
bool bResult = false;
printf("BLD 1\t\t %x %x %x %x\n", pBuffer[0], pBuffer[1],
pBuffer[2], pBuffer[3]);
MD5Init(&md5key);
MD5Update(&md5key, pbzKey, _ustrlen(pbzKey));
MD5Final(&md5key);
Blowfish_Init(&bf, md5key.digest, 16);
Blowfish_Decrypt(&bf, &pBuffer[0], &pBuffer[1]);
Blowfish_Decrypt(&bf, &pBuffer[2], &pBuffer[3]);
printf("BLD 2\t\t %x %x %x %x\n", pBuffer[0], pBuffer[1],
pBuffer[2], pBuffer[3]);
MD5Init(&md5);
MD5Update(&md5, pSignature, iSize);
MD5Final(&md5);
_2LONG *tl = (_2LONG*) md5.digest;
printf("BLD 3\t\t %x %x %x %x\n", tl->_1, tl->_2, tl->_3, tl->_4);
if (tl->_1 == pBuffer[0] && tl->_2 == pBuffer[1] &&
tl->_3 == pBuffer[2] && tl->_4 == pBuffer[3])
bResult = true;
return bResult;
}
void main(void)
{
unsigned char bszBuffer[2] = {'A', 'B'};
unsigned long ulSig[4];
SignBuffer((unsigned char*)"key", bszBuffer, 2, ulSig);
printf("\n");
if (VerifyBuffer((unsigned char*)"key", bszBuffer, 2, ulSig))
printf("\nok");
else printf("\nerr");
}
I had made _ustrlen because i got tired of using casting for (unsigned char*), unless there is a different way?
|
|
|
|
|
Hello!
It might only be me but it is not obvious (to me) where you are trying to do this conversion you are talking about, you should at least highlight the part of interest in your code so people who want to help don't have to study your whole program trying to grasp the way you think.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> "It doesn't work, fix it" does not qualify as a bug report. <
> Amazing what new features none of the programmers working on the project ever heard of you can learn about when reading what the marketing guys wrote about it. <
|
|
|
|
|