|
Record.h
=========
#include <string>
using namespace std;
class Record
{
public:
void setPersonName(string);
string getPersonName();
void setEmail(string);
string getEmail();
void setTelephoneNumber(int);
int getTelephoneNumber();
private:
string personName;
string email;
int telephoneNumber;
}
-----------------------------------
Record.cpp
===========
#include <iostream>
#include <string>
using namespace std;
#include "Record.h"
void Record::setPersonName(string name)
{
personName=name;
}
string Record::getPersonName()
{
return personName;
}
void Record::setEmail(string mail)
{
mail=email;
}
string Record::getEmail()
{
return email;
}
void Record::setTelephoneNumber(int number)
{
number=telephoneNumber;
}
int Record::getTelephoneNumber()
{
return telephoneNumber;
}
---------
1> Record.cpp
1>c:\users\hoyin\documents\visual studio 2010\projects\record\record\record.cpp(7): error C2628:
1>c:\users\hoyin\documents\visual studio 2010\projects\record\record\record.cpp(8): error C2556:
1> c:\users\hoyin\documents\visual studio 2010\projects\record\record\record.h(7) : see declaration of
1>c:\users\hoyin\documents\visual studio 2010\projects\record\record\record.cpp(8): error C2371:
1> c:\users\hoyin\documents\visual studio 2010\projects\record\record\record.h(7) : see declaration of
1>
1>Build FAILED.
1>
|
|
|
|
|
you should add on .h file : "use std::string " or
class Record
{
public:
void setPersonName(string);
std::string getPersonName();
void setEmail(string);
std::string getEmail();
void setTelephoneNumber(int);
int getTelephoneNumber();
private:
std::string personName;
std::string email;
int telephoneNumber;
}
|
|
|
|
|
The end of your class definition needs a ;
class Record
{
};
|
|
|
|
|
I bought a fingerprint machine called ZKFinger 4500. The SDK provided is a raw code of Visual C++. I have been trying to converting this project into dll file and even if it cant be, how do i make use of it in my VB.Net Project?
|
|
|
|
|
|
Hi,
I'm have been trying to write an code in C++ by using the Win32 API to communicate through the RS232 serial port with equipment. It's a simplex communication (only the equipment sends data in blocks of 289 bytes). I'm using an dedicated thread to read the serial port. Firstly I tried to use non-overlapped communication, but I realized that is impossible to close the serial port if there's no data incoming (the thread gets stuck on WaitCommEvent function). So I tried to use overlapped I/O and WaitForMultipleObjects to solve this problem:
void *SerialRead(void *param) {
OVERLAPPED overlapped;
memset( &overlapped, 0, sizeof(overlapped) );
overlapped.hEvent = CreateEvent( NULL, TRUE, FALSE, NULL );
SerialEvents[0] = overlapped.hEvent;
ReadFile(SerialPort, SerialBuffer, 289, &dwBytesRead, &overlapped);
while (WaitForMultipleObjects(2, SerialEvents, false, INFINITE) == WAIT_OBJECT_0) {
ReadFile(SerialPort, SerialBuffer, 289, &dwBytesRead, &overlapped); }
ClosePort();
return 0;
}
I use the function SetEvent(SerialEvents[1]); to close serial port on the main thread.
To open the serial port:
SerialPort = CreateFile(PortName,
GENERIC_READ|GENERIC_WRITE,0, 0, OPEN_EXISTING,FILE_FLAG_OVERLAPPED, 0);
The problem is that even if I recive the 289 bytes, the thread keeps wating the function "WaitForMultipleObjects" return. If I recive the next 289 bytes the WaitForMultipleObjects function returns, but the data are mixed.
Someone could help me?
|
|
|
|
|
You have created 1 event but your call to WaitForMultipleObjects [^] says that there are 2 events. You also make no attempt to check the return value from WaitForMultipleObjects so you do not really know what is happening.
Veni, vidi, abiit domum
|
|
|
|
|
I forgot to mention that I created the other envent (SerialEvents[1]) on the main thread:
SerialEvents[1] = CreateEvent(NULL, FALSE, FALSE, NULL);
This event is used to close the serial port (signaled by the main thread when user press the close button) and it is working!.
I used the GetLastError() function after WaitForMultipleObjects(), and it returns "ERROR_IO_PENDING". What could it be? I'm sure that the equipment is sending all 289 bytes!
|
|
|
|
|
ERROR_IO_PENDING is a normal return value that indicates that the transfer is taking place in the background.
When you get that return value, you're supposed to wait on the event, then when the event is signaled, call GetOverlappedResult() .
Look up that function, and you'll see how it works.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Thanks for reply, I discovered the problem. It was that on setup when openning the serial port I was calling GetCommState() function before SetCommState(), so it was overwriting the DCB structure configuration, setting a wrong baud rate value. I fix it and now it's working wonderfully!
|
|
|
|
|
hi all,
why not initialize the array of variable length why there is always need to assign size first.
how can I do this
int buffer_length;
buffer_length=lenth of some string.
BYTE byte_buffer[buffer_length];
can anyody help me for this.
thanks.
|
|
|
|
|
Hi,
can anyody help me for this.
Check out the std::vector class.[^]
You can also create it on the heap:
PBYTE buf = new BYTE[buffer_length];
Best Wishes,
-David Delaune
|
|
|
|
|
here if the buffer_length=190 its generate out of memory exception.
PBYTE buf = new BYTE[buffer_length];
it means it not working after certain limit.
thanks.
|
|
|
|
|
|
If you need a dynamic array (one that changes sizes), you need to allocate it dynamically on the heap.
In C++ you use new (along with corresponding delete after you're done with it).
In C you use malloc (along with corresponding free after you're done with it).
Failure to deallocate will result in memory leaks.
In addition to those options, you can use "containers", which are essentially classes that "contain" the dynamic array. A few of these options include std::vector , std::array , among others (most libraries including MFC have at least a couple of different container options).
|
|
|
|
|
How about:
const int buffer_length = length of some string;
BYTE byte_buffer[buffer_length];
"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
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
|
|
|
|
|
|
hi all,
I want to generate the MD5 of given Unicode Binary hash value.
its done in c# like:
MD5 md5Hash = MD5.Create();
byte[] md5Buf = System.Text.UnicodeEncoding.Unicode.GetBytes(binary_hash_value);
byte[] md5Hash_buf = md5Hash.ComputeHash(md5Buf);
string hashString = "";
for (int i = 0; i < md5Hash_buf.Length; i++)
{
hashString += Convert.ToString(md5Hash_buf[i], 16).PadLeft(2, '0');
}
hashString.PadLeft(32, '0');
textBox3.Text = hashString;
but its done in my vc++ project can anybody help me to do this.
thanks in advance.
|
|
|
|
|
In C/C++ you just treat the Unicode string as an array of bytes, no need for any conversion operations.
Veni, vidi, abiit domum
|
|
|
|
|
I need md5 of given string only the Unicode string not fulfill my requirement according to this code md5 value of hello "fd186dd49a16b1bf2bd2f44e495e14c9"
Unicode value is "680065006c006c006f00"
and in vc++ Unicode value of it "00680065006C006C006F"
how can I get here the its md5 value please assist me...
|
|
|
|
|
If your original string is in Unicode then the MD5 hash will not be the same as the ASCII representation. If it is a prerequisite for what you want to do then convert your text to ASCII before hashing. Take a look at Example C Program: Creating an MD5 Hash from File Content[^] for further help.
Veni, vidi, abiit domum
|
|
|
|
|
I want to generate "fd186dd49a16b1bf2bd2f44e495e14c9" from hex value of hello = 680065006c006c006f00
but I the example its generate md5 ="5d41402abc4b2a76b9719d911017c592" from value hello
please help
|
|
|
|
|
I already suggested that you can convert the Unicode characters to ASCII as a test sample. You may also like to spend some more time studying MD5 and how it is used.
Veni, vidi, abiit domum
|
|
|
|
|
Hi,
Hope you had a great Christmas holiday. Could not help but notice that '680065006c006c006f00' is an array of BYTE representing the unicode version of the string 'hello'. You can easily do this:
#define LENGTH 16
int _tmain(int argc, _TCHAR* argv[])
{
HCRYPTPROV p = 0;
HCRYPTHASH h = 0;
DWORD dwError=0;
if(CryptAcquireContext(&p,NULL,NULL,PROV_RSA_FULL,CRYPT_VERIFYCONTEXT))
{
DWORD length = LENGTH;
BYTE md5[LENGTH];
BYTE buf[LENGTH];
if(CryptCreateHash(p,CALG_MD5, 0, 0, &h))
{
wsprintfW((LPWSTR)buf,L"hello");
if(CryptHashData(h, buf, wcslen((LPWSTR)buf) * sizeof(WCHAR), 0))
{
if(0 == dwError && CryptGetHashParam(h, HP_HASHVAL, md5, &length, 0))
{
std::cout << std::setfill('0');
std::for_each(md5,md5+LENGTH,
[](BYTE b)
{
std::cout << std::setw(2) << std::hex << static_cast<int>(b);
});
std::cout << std::endl;
}
}
}
}
return 0;
}
Output: fd186dd49a16b1bf2bd2f44e495e14c9
Best Wishes,
-David Delaune
|
|
|
|
|
thanks randor
can u help me to convert c# code in c++;
my code works gud in c# but I have not so much idea how these functions works in c++
static string convert_byte_array_to_string(byte[] byte_array)
{
string hashString = "";
for (int i = 0; i < byte_array.Length; i++)
{
hashString += Convert.ToString(byte_array[i], 16).PadLeft(2, '0');
}
return hashString;
}
MD5 md5Hash = MD5.Create();
byte[] str_Buf = System.Text.UnicodeEncoding.Unicode.GetBytes(value_str);
hashString = Form1.convert_byte_array_to_string(str_Buf);
byte[] strHash = md5Hash.ComputeHash(str_Buf);
hashString = Form1.convert_byte_array_to_string(strHash);
byte[] hashBuf = new byte[21 * 16];
for (int i = 0; i < 16; i++)
{
Array.Copy(strHash, 0, hashBuf, i * 21, 5);
Array.Copy(verifierBuf, 0, hashBuf, i * 21 + 5, 16);
}
hashString = Form1.convert_byte_array_to_string(hashBuf);
strHash = md5Hash.ComputeHash(hashBuf);
hashString = Form1.convert_byte_array_to_string(strHash);
uint block = 0;
Array.Copy(strHash, 0, hashBuf, 0, 5);
Array.Copy(BitConverter.GetBytes(block), 0, hashBuf, 5, 4);
hashString = Form1.convert_byte_array_to_string(hashBuf);
strHash = md5Hash.ComputeHash(hashBuf, 0, 9);
hashString = Form1.convert_byte_array_to_string(strHash);
byte[] rc4Key = new byte[16];
Array.Copy(strHash, rc4Key, 16);
hashString = Form1.convert_byte_array_to_string(rc4Key);
ManagedRC4.RC4 rc4 = new ManagedRC4.RC4();
rc4.Init(rc4Key, (uint)rc4Key.Length);
rc4.Decrypt(encryptedVerifier, (uint)encryptedVerifier.Length);
rc4.Decrypt(encryptedVerifierHash, (uint)encryptedVerifierHash.Length);
hashString = Form1.convert_byte_array_to_string(encryptedVerifier);
hashString = Form1.convert_byte_array_to_string(encryptedVerifierHash);
byte[] hashedVerifier = md5Hash.ComputeHash(encryptedVerifier);
hashString = Form1.convert_byte_array_to_string(hashedVerifier);
hashString = Form1.convert_byte_array_to_string(encryptedVerifier);
md5Hash.Clear();
please.
can I create dll for c code and use in my c++ code.
can u please help me for this.
modified 28-Dec-13 7:22am.
|
|
|
|
|