|
|
This is a dialog-based app. I figured that had something to do with it... I just wasn't sure what (technically, I'm still not sure... can you enlighten me )
|
|
|
|
|
And I've found it... CWnd doesn't implement the processing of WM_INITMENUPOPUP, CFrameWnd does. So, what is the "appropriate" method of emulating this in a CDialog based class? As I said, I have one way, but am interested in what most people consider the "correct" way of handling it.
|
|
|
|
|
|
I'm writing a program that needs to make some folders, can I do this with createfile? I've been trying to do it this way but I keep erroring out. Am I missing something?
Thanks
Tom Wright
tawright915@yahoo.com
|
|
|
|
|
Use CreateDirectory .
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
That's it. I must be getting old cuz I just cannot remember all of these API's
Thanks
Tom Wright
tawright915@yahoo.com
|
|
|
|
|
Try ::CreateDirectory() instead.
..
..
if( !CreateDirectory(szDirPath, NULL) )
{
dwError = GetLastError();
if( dwError != ERROR_ALREADY_EXISTS )
return FALSE;
}
..
..
I Dream of Absolute Zero
|
|
|
|
|
On page 170 of Lippman's, "C++ Primer: 3rd Edition", about mid page, it shows this example:
bitset<32> bitvec3(012); Then he shows the output of that sample as:
0000...1010 Having read the passage that explains the expression and its result, I am still at a lost for clarity (because the result seems to be based on position rather than value).
There is no way that 00001010 is 12, numerically, so I set about doing some experiments of my own. I did:
bitset<8> bv012(012);
bitset<8> bv021(021);
bitset<8> bv12(12);
bitset<8> bv21(21); The results of those experiments were:
00001010
00010001
00001100
00010101 The last two (12, and 21) are the correct numeric values for their binary representation, but I am at a lost as to how "012" and "021" can positionally produce the result the computer has shown.
If anybody knows how this is accomplished, I would very much appreciate a clearer explanation than what Lippman has given.
Thanks.
William
Fortes in fide et opere!
|
|
|
|
|
Hey, you got caught by a language oddity coming back from the days of Kernighan and Ritchie: 012 is interpreted to be octal, thus its value is 8. In general, numeric literals beginning with 0 are interpreted to be base-8, much as numeric literals beginning with 0x are hexadecimal. This is one of those useless rarities of the language that everybody sooner or later gets kicked by (if you're in programming long enough, that is.)
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Thanks for replying.
Octal. Octal. I even hate the mention of it. Little wonder why it never got caught on.
The picture is clear now. Thanks. I appreciate it.
William
Fortes in fide et opere!
|
|
|
|
|
*chuckles* Never caught on?? On the contrary, everyone used octal originally. Hex became popular some years later.
--
-Blake (com/bcdev/blake)
|
|
|
|
|
Blake Coverett wrote:
On the contrary, everyone used octal originally
:-DThat was the time when real programmers, being used to switch in their program, looked down on the assembler-using weaklings, much like the C++-programmers of today look down on the VB-users?
I do not personally remember this time - too distracted learning to walk!
Who is 'General Failure'? And why is he reading my harddisk?!?
|
|
|
|
|
Does any know some sample code or application
to display the japanse/chinese in OpenGL?
Thanks in advance.
Shin
|
|
|
|
|
How do I list/iterate through all the Exchange servers on a local network? I need to create a list box with all the servers for a installation program.
|
|
|
|
|
I have a struct with a int and double in it. I can initialize them both just fine from inside the main. The problem arises when I try to convert the double to binary toward the end of the code, it seems to cause an error at: if((c.i) & (1 << bits)) on the c.i and I don't have a clue why. Only the double/float causes this error, all the other go throught just fine.
#include <stdio.h>
#include "typedefs.h"
typedef struct
{
double i;
long x;
}myStruct;
void main()
{
myStruct c;
int space = 0;
int bits = 0;
int on = 1;
int off = 0;
scanf("%d",&c.x);
for(bits=31; bits>=0; --bits)
{
if(space == 8)
{
printf(" ");
space = 0;
}
if(c.x & (1 << bits))
printf("%d",on);
else
printf("%d",off);
++space;
}
printf("\n");
scanf("%lf",&c.i);
space = 0;
for(bits=7; bits>=0; --bits)
{
if(space == 8)
{
printf(" ");
space = 0;
}
if((c.i) & (1 << bits))
printf("%d",on);
else
printf("%d",off);
++space;
}
printf("\n");
|
|
|
|
|
You cannot use the bitwise and operator & with double s just as you do with integer types. The representation of a floating point value in memory is not something amenable to this type of bitwise manipulations. You can cast your double to an integer type (an int for instance) and then use your algorithm.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Thanks for the advice. I will forget about the double then.
B.
|
|
|
|
|
Sirrius wrote:
The problem arises...
What problem? Is it a compiler error, or a run-time error? Which of the two conditions is suspect? What are the values of c.i and bits at the time of the problem? Double types are more than 8 bits in size so the second for loop might not produce the desired result.
Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?
|
|
|
|
|
Actually I figured the problem was arising when it was checking the bits with this statement:
if((c.i) & (1 << bits))
..ect;
It didn't like to let c.i be a double. It would have a compile error right on that line. c.i was declared a double in the struct.
B.
|
|
|
|
|
I have a list class here that is being handed a tree class(not included in the thread). I need to get this List to be ordered and have been having a devil of a time doing so.
It seems not to like anything I throw at it; bool operators to decide less than or greater than, if statements. Can sombody give me a push in the right direction.
Thanks.
B.
#include <iostream>
#include <string>
#ifndef LIST_H
#define LIST_H
using namespace std;
struct node
{
string data;
node *next;
node *successor;
node *predec;
};
class List
{
node *first;
node *successor;
node *predec;
public:
List()
{
first=NULL;
successor=NULL;
predec=NULL;
}
void insertNode(string newName)
{
node *p;
p=new node;
p->data=newName;
p->next=first;
first=p;
}
void outputList(ostream &out)
{
node *p;
p=first;
if(!empty())
{
cout << endl;
while(p!=NULL)
{
cout << p->data << " ";
p=p->next;
}
}
else
cout << "The list is empty!" << endl;
}
bool empty()
{
if(first==NULL)
return true;
else
return false;
}
};
#endif
|
|
|
|
|
I don't get your question. How are you trying to sort the list? Also, if this is an option you might consider using std::list instead of your own homemade container, it'll save you a lot of problems.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
One way would be to modify the insertNode() method, since it always adds to the front of the list. Something like:
void insertNode( string newName )
{
node *p, *n, *t;
p = new node;
p->data = newName;
p->next = NULL;
n = first;
t = first;
while (NULL != n && p->data > n->data)
{
t = n;
n = n->next;
}
if (NULL == first)
first = p;
else if (n == first)
{
first = p;
p->next = n;
}
else
{
t->next = p;
p->next = n;
}
}
Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?
|
|
|
|
|
Thanks for showing me another way to look at it. I was fixed on one method that didn't want to compile.
Thanks.
B.
|
|
|
|
|
Hi Everyone,
I have two applications (one developed in VC++ 6.0 and the other developed in VB.NET )which communicate to each other in secure manner.) I am using RC2 encryption to encrypt messages between the two applications. Both of them use the same key , IV , padding and the same cipher mode (ECB). I want to encrypt messages in one application and decrypt in the other application. But I am not able to do that. I am getting bad data exception when i Encrypt in one application and try to decrypt the message in another application.
I am pasting the code below from both the applications.
VC++ 6.0
GetSessionKey {
CryptAcquireContext( &hProv, NULL,
MS_ENHANCED_PROV , PROV_RSA_FULL, 0 );
CryptGetUserKey(hProv, AT_KEYEXCHANGE ,&hPublicKey);
BYTE tKey[] = { 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16};
DWORD tLen = 16 ;
DWORD dtLen = 16 ;
fResult = CryptEncrypt(hPublicKey ,0,TRUE ,0 , NULL , &tLen , dtLen );
BYTE *tKey1 = new BYTE [tLen] ;
memset(tKey1 ,'\0', tLen) ;
memcpy(tKey1 , tKey , dtLen) ;
BOOL fResult = CryptEncrypt(hPublicKey ,0,TRUE ,0 , tKey1 , &dtLen , tLen );
fResult = CryptGenKey(hProv, CALG_RC2, CRYPT_EXPORTABLE, &hTempKey);
dwSize = sizeof(DWORD);
DWORD dwBlobLen ;
fResult = CryptGetKeyParam(hTempKey, KP_KEYLEN, (LPBYTE)&dwProvSessionKeySize,
&dwSize, 0);
CryptExportKey( hTempKey, hPublicKey, SIMPLEBLOB, 0, NULL, &dwBlobLen);
pbKeyBlob = (BYTE*)malloc(dwBlobLen);
//--------------------------------------------------------------------
// Export the key into a simple key BLOB.
fResult = CryptExportKey(hTempKey, hPublicKey, SIMPLEBLOB, pbKeyBlob, &dwBlobLen);
int tlen = sizeof(ALG_ID) + sizeof(BLOBHEADER) ;
pbPtr = pbKeyBlob;
pbPtr =pbKeyBlob + sizeof(ALG_ID) + sizeof(BLOBHEADER) ;
//copy the key in the blob
for (n = 0 ; n < dwProvSessionKeySize ; n++)
{
pbPtr[n] = tKey1 [n];
}
if (hTempKey) CryptDestroyKey(hTempKey);
DWORD dErr = GetLastError() ;
fResult = CryptImportKey(hProv, pbKeyBlob , dwBlobLen,
hPublicKey, CRYPT_EXPORTABLE, &m_hcryptSessionKey);
dErr = GetLastError() ;
BYTE ivarray[] = {1,1,1,1,1,1,1,1};
fResult = CryptSetKeyParam(m_hcryptSessionKey , KP_IV , ivarray ,0) ;
DWORD dwMode = CRYPT_MODE_ECB;
fResult =CryptSetKeyParam(m_hcryptSessionKey, KP_MODE, (BYTE*)&dwMode, 0) ;
DWORD dwCount = 0 ;
dwMode = PKCS5_PADDING ;
fResult =CryptSetKeyParam(m_hcryptSessionKey , KP_PADDING , (BYTE*)&dwMode , 0 );
}
int CEncryption::EncryptData(LPSTR inStr , DWORD &dwLen , CString & outStr)
{
// convert string to bytes
DWORD dataLen = dwLen ;
if (dwLen == 0) return 0 ;
if (inStr == NULL) return 0 ;
BOOL bResult = CryptEncrypt(m_hcryptSessionKey ,0,TRUE , 0, NULL , &dwLen , dataLen) ;
BYTE *encTxt = new BYTE [dwLen] ;
memset(encTxt ,'\0' ,dwLen) ;
memcpy (encTxt ,inStr , dataLen) ;
//dwLen = dataLen ;
bResult = CryptEncrypt(m_hcryptSessionKey ,0,TRUE , 0, encTxt , &dataLen , dwLen) ;
delete encTxt;
return bResult;
}
int CEncryption::DecryptData(LPSTR inStr , DWORD &dLen , CString & outStr)
{
DWORD dataLen = 0 ;
BYTE *outBytes = NULL ;
__try
{
outBytes = new BYTE [dLen ];
memset(outBytes ,'\0' ,Len);
dataLen = Len ;
BOOL bResult = CryptDecrypt(m_hcryptSessionKey ,0,TRUE , 0, outBytes , &dataLen) ;
DWORD dErr = GetLastError() ;
outBytes[dataLen] = '\0' ;
outStr = (char *)outBytes ;
}
return TRUE;
}
vb.net code
Dim iv As Byte() = {1, 1, 1, 1, 1, 1, 1, 1}
Dim key As Byte() = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}
dim rc2CSP As new RC2CryptoServiceProvider
rc2CSP.iv = iv
rc2CSP.key = key
// encryption
Dim encrypted() As Byte
Dim toEncrypt() As Byte
Console.WriteLine("Effective key size is {0} bits.", rc2CSP.EffectiveKeySize)
Dim keysize As Integer = rc2CSP.EffectiveKeySize
'Create a new key and initialization vector.
'Get an encryptor.
Dim encryptor As ICryptoTransform = rc2CSP.CreateEncryptor(key, iv)
'Encrypt the data.
Dim msEncrypt As New MemoryStream
Dim csEncrypt As New CryptoStream(msEncrypt, encryptor, CryptoStreamMode.Write)
'Convert the data to a byte array.
'toEncrypt = textConverter.GetBytes(InnerString)
toEncrypt = plainText
'Write all data to the crypto stream and flush it.
csEncrypt.Write(toEncrypt, 0, toEncrypt.Length)
csEncrypt.FlushFinalBlock()
'Get encrypted array of bytes.
encrypted = msEncrypt.ToArray()
' Destruct classes
csEncrypt.Close()
csEncrypt = Nothing
msEncrypt.Flush()
msEncrypt.Close()
msEncrypt = Nothing
// decryption
Dim decryptor As ICryptoTransform = rc2CSP.CreateDecryptor(key, iv)
'Now decrypt the previously encrypted message using the decryptor
' obtained in the above step.
Dim msDecrypt As New MemoryStream(cipherText)
Dim csDecrypt As New CryptoStream(msDecrypt, decryptor, CryptoStreamMode.Read)
Dim fromEncrypt As Byte()
fromEncrypt = New Byte(cipherText.Length) {}
'Read the data out of the crypto stream.
csDecrypt.Read(fromEncrypt, 0, fromEncrypt.Length)
csDecrypt.Close()
csDecrypt = Nothing
msDecrypt.Close()
msDecrypt = Nothing
Any help in pointing me in the right direction will be highly appreciated
|
|
|
|
|