|
Try this:
class MyStruct
{
public:
MyStruct()
{
m_pMsg = new char[128];
lstrcpy(m_pMsg, "Hello World");
}
~MyStruct()
{
delete [] m_pMsg;
m_pMsg = NULL;
}
char *m_pMsg;
void Exec( void )
{
AfxMessageBox(m_pMsg);
}
};
MyStruct myStruct;
COPYDATASTRUCT dataToSend;
dataToSend.cbData = sizeof(MyStruct);
dataToSend.lpData = &myStruct;
dataToSend.dwData = 0;
::SendMessage(GetSafeHwnd(), WM_COPYDATA, (WPARAM) GetSafeHwnd(), (LPARAM)&dataToSend);
COPYDATASTRUCT *dataReceived = (COPYDATASTRUCT *)pCopyDataStruct;
MyStruct *pStruct = (MyStruct *) dataReceived->lpData;
pStruct->Exec();
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
You cannot pass a pointer between processes. All the data has to be self-contained in the block of memory that you refer to in the COPYDATASTRUCT .
|
|
|
|
|
Exactly, like I said to toxcct, if I do this, I lost the control of the pointer.
And I did this before, Michael, can you tell me how can I solve?
I've tested with structures, works very fine, but what I want is a object. Hence I'm trying to solve this using based pointers. It's my very first time using based pointers.
|
|
|
|
|
You cannot pass a pointer between processes. A based pointer doesn't solve this, because it's just an offset from another pointer.
|
|
|
|
|
That means, it's not possible to send an object to another window right? If an object is a pointer, there's not a way to send it. My app actually is passing structs, but what I want to pass is an object.
|
|
|
|
|
Hello,
I have two strings username and password and I want to create a hash of it at the server side and at the client side where the data is reached I want to compare the hash again with another hash. So two questions
How do you hash two strings in C++
How do you compare two hashes in C++?
Please let me know.
Thanks
vg
|
|
|
|
|
There are many different ways to hash values, a simple CRC can be considered a hash, all the way to an MD5 message digest hash.
Usually, comparing them is just comparing the hash results. Compare the binary values, or convert them to strings and then compare them, it is all the same.
Peace!
-=- James Please rate this message - let me know if I helped or not!<HR> If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! See DeleteFXPFiles
|
|
|
|
|
Dear James,
In that case can you please show me around two ways to calculate a hash for username and password strings. Also how would you compare by using ==?
Thanks.
vg
|
|
|
|
|
As alreasy posted, CryptHashData(...) and its related functions can generate a hash value from your raw data (username/password).
You will not be able to just use == to compare the hash values unless you have the hash values encapsulated in an object that overrides that operator. You can always use memcmp(...) to compare the raw data.
One thing - some systems store password hashes in a database instead of the plaintext password, and then just have to compare the hash values to verify it - that way, you do not risk the plaintext password if someone gets into the database.
However, do not try to do the same thing usernames - depending on the hashing technique, there exists a chance (however slim it may be) for two different usernames produce the same hash value. If this happens, you will be unable to disambiguate one from the other in the database and will not know which one is logging in, or which password hash to compare against.
Peace!
-=- James Please rate this message - let me know if I helped or not!<HR> If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! See DeleteFXPFiles
|
|
|
|
|
Dear James,
I don't think CryptHashData can be used for creating hashes for strings and comparing. For example if I do CryptCreateHash I have to do
if(!CryptAcquireContext(&hProv, NULL, MS_DEF_PROV, PROV_RSA_FULL, 0))
before that and infact if you try to do CryptCreateHash two times you'll see that you don't actually get the same hashes so this will not work when you need to compare hash. This I believe is used for encryption.
What I need is to make a hash from username and password and make another one at the client side and compare the two.
Thanks.
vg
vg
|
|
|
|
|
You can use the crypto API, look up CryptCreateHash() and CryptHashData()
|
|
|
|
|
Dear Mike,
I don't think these are used for creating hashes for strings. For example if I do CryptCreateHash I had to do if(!CryptAcquireContext(&hProv, NULL, MS_DEF_PROV, PROV_RSA_FULL, 0))
before that and if you do it two times CryptCreateHash you'll see that you don't actually get the same hashes so this will not work when you need to compare hash. This I believe is used for encryption.
What I need is to make a hash from username and password and make another one at the client side and compare the two.
Thanks.
vg
|
|
|
|
|
|
Dear Mike,
I have used the piece of code in this link to create a hash of an username and password on the server side and on the client side create another hash of an username and password. However when I compare the hashes they are not similar even though its the same string on both ends. Can you please help.
Thank you.
vg
|
|
|
|
|
vgandhi wrote: How do you hash two strings in C++
How do you compare two hashes in C++?
hashes have different purposes, as you see by your answers, there are perfect hashes, in which case you are trying to generate an absolute reference hash for two different strings of expected input. Cryptographic hashes try to be perfect hashes, when they are found to not be unique within the bit range of the expected input, this is considered a bug and they are fixed or replaced.
as for comparing... you need an api routine that runs on strings, run them, compare them. These are non-cryptographic hashes, similar to CRC but they are designed for optimum distribution range not just uniqueness. With optimized bit distribution of the result, you can mod the result to your own range.
http://www.azillionmonkeys.com/qed/hash.html[^] there is also a test project that compares the hash routines.
_________________________
Asu no koto o ieba, tenjo de nezumi ga warau.
Talk about things of tomorrow and the mice in the ceiling laugh. (Japanese Proverb)
|
|
|
|
|
Question.
I am using overlapped child windows in a dialogue box. According to the documentation, OnNcActivate can be used to control the colour of the total bar, between active and inactive colours. However this message (OnNcActivate TRUE FALSE) is not being sent to the window for child windows. Is there another way of setting the titlebar state colour, or a way of ensuring that this message is sent to allow this to be controlled?
Thanks for any input
Sandy
|
|
|
|
|
Is there an ON_WM_NCACTIVATE entry in the mesage map for the window?
Mark
|
|
|
|
|
Yes ON_WM_NCACTIVATE is there
We are not getting as far as the OnNcActivate routine - we are just not getting the message from Windows for the child window.
Thanks for the response Mark. Any other ideas?
Sandy
|
|
|
|
|
Sandy Kinghorn wrote: we are just not getting the message from Windows for the child window
You're not trying to catch it in the parent, right?
Mark
|
|
|
|
|
Trying to catch via the windows message map. OnNcPaint is being passed through the map. OnNcActivate is not.
The window causing problems has a style of child set in its proerties, and is used as a child of a modal dialogue. Several instances are created o the fly, and need to indicate active one via its title bar.
thanks
Sandy
|
|
|
|
|
Sandy Kinghorn wrote: ...used as a child of a modal dialogue...
I think the built in activation only works on "top-level" windows, not on child windows. I tried
with imbedded overlapped children an couldn't get it to work either, whether the parent dialog
was modal or modeless.
The only way I know of to get the built in activation behavior with overlapped child windows is
to use MDI windows. Not necessarily a desired solution.
Otherwise you could look into indicating the active window some other way - drawing the title bar
yourself, changing the window frame appearance, etc.
Mark
|
|
|
|
|
I want to have a key shortcut to call a dialog in an MFC Application. CFormView I can do it in CView but for some reason I can't seem to get it to work in CView if anyone knows how please tell me.
Thanks
Jenn
|
|
|
|
|
You can use an "Accelerator" and in its handler you can open the dialog you want.
Your text is missing punctuation, so I am not sure I was able to understand it.
"We trained hard, but it seemed that every time we were beginning to form up into teams we would be reorganised. I was to learn later in life that we tend to meet any new situation by reorganising: and a wonderful method it can be for creating the illusion of progress, while producing confusion, inefficiency and demoralisation."
-- Caius Petronius, Roman Consul, 66 A.D.
|
|
|
|
|
I never read over my message sorry it didn't make much sense. I tried an accelerator but for some reason nothing seemed to happen. Do you know how exactly to do it???
|
|
|
|
|
How to get reference count on File handle... I mean how many process opened the paticular file...
|
|
|
|