|
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
|
|
|
|
|
Hi, All:
I have a MFC application developed five years ago and it used CDaoDatabase and CDaoRecordset. It works fine with MS Access 97 DB. After we converted the DB to MS Access 2000. The Application fails on the DB open. I use the following to open the DB:
CDAODatabase pDB = new CDaoDatabase();
try
{
pDB->Open( "MyDBFilewithFullPath", FALSE, FALSE, _T("") );
}
I wonder if there is any easy way to make this work with MS Access 2000. Will using ODBC fix the problem?
Thanks in advance.
Dion
|
|
|
|
|
Use GetError() to find out the error code, then look it up, this will give a little bit of information. You do have to set up the ODBC Data Source Administrator to the correct value. This is in the Control Panel. In addition, look at any pre-compiled headers and you should look at what version daoXXX.lib you are linking to.
J.
----------------------------
|
|
|
|
|
I had this problem a few years back as well. The problem is that the MFC classes
uses DAO 3.5 to open the Access databases. Access 2000 and above however is
incompatible with 3.5.
There is a workaround on the Microsoft Knowledgebase. Have a look at:
http://support.microsoft.com/default.aspx?kbid=236991[^]
Maybe now's a good time to switch to ADO for database access.
I Dream of Absolute Zero
|
|
|
|
|
How do you create menus in VC++ dialog based MFC application?
Provide a sample code for it.
Karteek
|
|
|
|
|
Your dialog object will need a CMenu member variable. In the dialog's OnInitDialog() method, simply call that variable's LoadMenu() method followed by CDialog::SetMenu() . It's that easy!
Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?
|
|
|
|
|
Hi,
I'm using
RECT r;
GetClientRect(hWnd,&r);
CreateWindow(WC_EDIT,etc,etc,r.right,r.bottom....);
to get the client area of my window and putting an edit control in there which should fit precisely. I noticed that the returned value for the first window created by the application is wrong. The height is 10 pixels short(about the same height as a titlebar).
When used with any subsequently created windows the value is correct. Does anybody know what this is about? Maybe a bug?
|
|
|
|
|
I have found that when I want to have things sized perfectly in a client that I also need to process the WM_SIZE message to maintain proper sizing of the child.
|
|
|
|
|
Anyone know why VC++7 completely craps out when you change the name of the class or the .cpp or the .h files to be created in the MFC ODBC Consumer Wizard? Am I the only one with this problem? The OBDC driver is MySQL 3.51.
Matt (Padawan Learner)
|
|
|
|
|
|
Perhaps GetAdaptersInfo would help?
|
|
|
|
|