|
The Towers of Hanoi problem is recursive - make sure you've implemented it properly, then optimise for size. A key optimisation might be taking the invariant out of your tight inner loops.
--
Andrew.
|
|
|
|
|
Hey Guys
I am totally stuck i have a structure that is working fine of 3 TCHAR arrays but as soon as i add a 4th TCHAR array the structure causes the program to crash has anyonegot any ideas.
This is the Structure
struct CertificateNames
{
TCHAR sCommonName[STRING_LENGTH];
TCHAR sIssuerName[STRING_LENGTH];
TCHAR sFriendlyName[STRING_LENGTH];
};
The only thing i can think is that there is a set size for a structure.
STRING_LENGTH = 256
Cheers Guys
Peter
|
|
|
|
|
You're obviously able to create a structure of four TCHAR's, you need to show us some code where it crashes to try and fix the problem.
Christian
After all, there's nothing wrong with an elite as long as I'm allowed to be part of it!! - Mike Burston Oct 23, 2001
|
|
|
|
|
This is the Structure
struct CertificateNames
{
CERT_INFO CertID;
TCHAR sCommonName[STRING_LENGTH];
TCHAR sIssuerName[STRING_LENGTH];
TCHAR sFriendlyName[STRING_LENGTH];
};
As for what happens to it i only write values into the string arrays.
Cheers
Peter
|
|
|
|
|
given that a CERT_INFO structure has variable size, have you tried putting it last in the structure ? Having still not seen your code, I'm guessing you're writing in the wrong spot somewhere, and given that the size of CERT_INFO can change by the size of rgExtension, it seems to make sense to me to put it at the end.
Christian
After all, there's nothing wrong with an elite as long as I'm allowed to be part of it!! - Mike Burston Oct 23, 2001
|
|
|
|
|
Hey Christian
The problem happens even with out the CERT_INFO structure (which i have now removed anyway). It seems i can add anything else to the structure except another TCHAR array. As for the code where it is used the reason i haven't given you any is it literally is passed into a function and then data written into the string. Anyway this is one of the functions.
bool CCrypto::GetSubjectNameFromCert(PCCERT_CONTEXT pCertificate, CertificateNames *CertInfoStruct)//(PCCERT_CONTEXT pCertificate, TCHAR *sSignerName)
{
OSVERSIONINFO OSVersion;
GetVersionEx(&OSVersion);
SYSTEMTIME ExpireDateCert;
FILETIME ExpireDateCertUTC;
if(OSVersion.dwPlatformId == 4 && OSVersion.dwMinorVersion == 10)
{
CERT_NAME_BLOB CertSubjectNameBlob;
CERT_NAME_BLOB CertIssuerNameBlob;
TCHAR sCertificateName[BUFFER_LENGTH];
DWORD dwSizeOfsCertificateName = sizeof(sCertificateName);
TCHAR sCertificateCommonName[BUFFER_LENGTH];
bool bQuoteFlag = FALSE;
CertSubjectNameBlob = pCertificate->pCertInfo->Subject;
CertIssuerNameBlob = pCertificate->pCertInfo->Issuer;
CertNameToStr(X509_ASN_ENCODING, &CertSubjectNameBlob, CERT_X500_NAME_STR, sCertificateName, dwSizeOfsCertificateName);
for(int i = 0; i < BUFFER_LENGTH; i++)
{
if(sCertificateName[i] == 'C')
{
if(sCertificateName[++i] == 'N')
{
if(sCertificateName[++i] == '=')
{
++i;
for(int y = i, d = 0; y < BUFFER_LENGTH; y++, d++)
{
if(sCertificateName[y] == '"')
{
if(bQuoteFlag == TRUE)
{
bQuoteFlag = FALSE;
}
else
{
bQuoteFlag = TRUE;
}
}
if(sCertificateName[y] == ',' && bQuoteFlag == FALSE)
{
CertInfoStruct->sCommonName[d] = NULL;//sCertificateCommonName[d] = NULL;
break;
}
else
{
CertInfoStruct->sCommonName[d] = sCertificateName[y]; //sCertificateCommonName[d] = sCertificateName[y];
}
}
}
}
}
}
delete &CertSubjectNameBlob;
_strset(&sCertificateName[0], NULL);
CertNameToStr(X509_ASN_ENCODING, &CertIssuerNameBlob, CERT_X500_NAME_STR, sCertificateName, dwSizeOfsCertificateName);
for(int k = 0; k < BUFFER_LENGTH; k++)
{
if(sCertificateName[k] == 'C')
{
if(sCertificateName[++k] == 'N')
{
if(sCertificateName[++k] == '=')
{
++k;
for(int g = k, h = 0; g < BUFFER_LENGTH; g++, h++)
{
if(sCertificateName[g] == '"')
{
if(bQuoteFlag == TRUE)
{
bQuoteFlag = FALSE;
}
else
{
bQuoteFlag = TRUE;
}
}
if(sCertificateName[g] == ',' && bQuoteFlag == FALSE)
{
CertInfoStruct->sIssuerName[h] = NULL;//sCertificateCommonName[d] = NULL;
break;
}
else
{
CertInfoStruct->sIssuerName[h] = sCertificateName[g]; //sCertificateCommonName[d] = sCertificateName[y];
}
}
}
}
}
}
delete &CertIssuerNameBlob;
}
else
{
CertGetNameString(pCertificate, CERT_NAME_SIMPLE_DISPLAY_TYPE, 0, NULL, CertInfoStruct->sCommonName, STRING_LENGTH);
CertGetNameString(pCertificate, CERT_NAME_SIMPLE_DISPLAY_TYPE, CERT_NAME_ISSUER_FLAG, NULL, CertInfoStruct->sIssuerName, STRING_LENGTH);
CertGetNameString(pCertificate, CERT_NAME_FRIENDLY_DISPLAY_TYPE, CERT_NAME_ISSUER_FLAG, NULL, CertInfoStruct->sFriendlyName, STRING_LENGTH);
ExpireDateCertUTC = pCertificate->pCertInfo->NotAfter;
FileTimeToSystemTime(&ExpireDateCertUTC, &ExpireDateCert);
//GetDateFormat(NULL, 0, &ExpireDateCert, "MMM dd',' yyyy", CertInfoStruct->sDateCertExpires, STRING_LENGTH);
}
return 0;
}
|
|
|
|
|
The problem is the structure seems to cause the problem on initalisation not when being passed or used in functions.
Peter
|
|
|
|
|
You can test this - you can write a constructor for a struct. Do that and initialise the values to something sensible, then try creating an instance of the struct and display them.
Christian
After all, there's nothing wrong with an elite as long as I'm allowed to be part of it!! - Mike Burston Oct 23, 2001
Sonork ID 100.10002:MeanManOzI live in Bob's HungOut now
|
|
|
|
|
TCHAR are used for Unicode systems, this is a macro that allows your code to be compiled in both ANSI and UNICODE
if you are compiling in ANSI, then use char instead
if you are using UNICODE then when comparing it against other chars you need to qualify the char with the _T macro
e.g.
change
if(sCertificateName[k] == 'C')
to
if(sCertificateName[k] == _T('C'))
|
|
|
|
|
I tried 20 TCHAR arrays of size 256 along with CERT_INFO in a simple diaglog program having the same struct in VC++ 7.0 and the program did not crash. This seems to be something else.
|
|
|
|
|
i've read it's possible to manipulate the browser from mfc app.
but how do i get my mfc app to execute an exe file?
is it possible to open an exe file and read into a buffer, and execute the file from there?
Or is it possible to point to an area in the exe file and start executing from there?
after all it was simple in c, u used the exec comand!
|
|
|
|
|
MFC adds no special support for executing prrgams, as it does not restrict any method to do it (which means you can still use your exec() command if that suits your needs).
There's no easy way to get an exe into a buffer and execute it from there; but probably you won't have such a special need.
There are a number of APIs that can execute programs, each with its pros and cons. Check these out:exec()
system()
ShellExecute()
CreateProcess()
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Hi,
How can I seek in a CMemFile?
It looks like the CMemFile::Seek function hangs my program...
Thanks in advance,
Erik Hammar
|
|
|
|
|
Alright All, I have a small brain teaser to do with Toolbars. I have managed to setup a toolbar successfully in the CMainFrame section of MDI App. Every time I open a file / create a new file it adds the relevant information to the combo box (i.e. the name of the file). Its then possible that I do some operations on these files, the names of these operations are then also recorded IN ORDER in the combo box. However, since I have an MDI app, and I`ve used the CMainFrame section to house the combo box, it is possible that the user mixes up the entries in the combo box that are associated with the different windows. I would like to be able to keep them separate, so that when the user clicks on a particular window, the combo box reflects the changes I`ve made to that one and that one only (and if I re-activated the other window it would re-display all the changes to that one etc.). I would appreciate any advice on this, even if it was to just tell me where to store the combo box control or how to switch back and forth different combo boxes as the different windows are activated.
Cheers again guys,
Alan.
"When I left you I was but the learner, now I am the Master" - Darth Vader
|
|
|
|
|
I would recommend keeping the list of changes you have made in the document object. Then wehn tyhe user switches document, (or toa different view), you can handle the OnSetActive of that view and populate the combo box in the toolbar. Something like:
void CMyView::OnSetActive(bool m_bActivate)
{
if (m_bActivate)
{
CComboBox* pCombo = &((CMainFrame*)(AfxGetApp()->m_pMainWnd))->m_ComboBox ;
pCombo->ResetContent() ;
}
}
Its a bit rough and done from memory so it may be a little bit buggy
Roger Allen
Sonork 100.10016
|
|
|
|
|
After I had written the question, for some unknown reason (I`ll call it fate), this exact same solution came into my head. I was, in fact just about to delete this thread thinking that no-one would respond so quickly, amazing. I would, however, like to thank you for responding and re-affirming this solution, because it came from nowhere in my head, and I always tend to think "is this the best solution - mmmm I dunno", but since your response I have no fear.
Thanks Roger, very much appreciated,
Alan.
P.S. your solution seems pretty damn good, if thats "a bit rough" I feel quite inadequate .
"When I left you I was but the learner, now I am the Master" - Darth Vader
|
|
|
|
|
I make a MFC App (Visual C++ Project) using a CHtmlView. I run this MFC App and I open a "Word Document" on CHtmlView through Navigate2("WordDoc.doc",0,NULL) and I can updated it, it's fun. But if I run Microsoft Word (in the same time that MFC App) to work on another Word Document and atfer a close Microsoft Word, when I come back on my MFC App, I can't access on my "Word Document" (no cursors). To check this problem, you can tried to use MFCIE sample on Msdn to open a "Word Document", it's the same result ...
Thanks....
|
|
|
|
|
I have a dialog based app, no doc/view, in which I have a listview control, and I want to add a context menu, so that when the user right clicks in the list view, a context menu pops up, and the user can choose to add, delete, etc. an entry. Do you have to have doc/view in order to have a context menu? If so, is there a way around this?
|
|
|
|
|
You can do this quite easily. First Create a menu resource
MyPopup->Item 1
Item 2
...
Then handle the NM_RCLICK message for the list control and add code such as this
CMenu menu ;
CMenu *pPopup ;
CPoint point ;
int item_selected ;
GetCursorPos(&point) ;
menu.LoadMenu(IDR_MENU_RESOURCE_ID) ;
pPopup = menu.GetSubMenu(0) ;
item_selected = ::TrackPopupMenuEx(pPopup->m_hMenu, TPM_RETURNCMD | TPM_NONOTIFY, point.x, point.y, m_hWnd, NULL) ;
switch (item_Selected)
{
case ID_MENU_ITEM1 :
...
break ;
}
You use the TPOM_RETURNCMD flag so that you don;t have to handle the command as WM_COMMAND message. This allows you to keep all the code together for the different menu options in one place. You also don;t have to write all the ON_COMMAND macros and function prototypes
Enjoy
Roger Allen
Sonork 100.10016
|
|
|
|
|
Hi everyone,
I've posted a thread regarding the retrieval of sound and graphics card info such as driver name, manufacturer and version.
Many of the answers I have received all boils down to using WMI (Windows Management Instrumentation) but after using it I realize it's an enormous overkill for my simple needs and that it is not supported for win 95/98 unless you install it yourself.
There must be another, more standard way to get the display and sound info, right...?
If you know how or can point me in the right direction, I'd be VERY grateful!
/Tommy
|
|
|
|
|
I built an application using Micro. visual c++. When in debug run it turns nothing...but when I compile/build in Win32 Release n try to execute this error occur in the message box in windows 2000
"The instruction at "0x00430432" reference memory at "0x0000000c". The memory could not be "read" ".
n I click ok
again it emerge with different error message box,
"The instruction at "0x0042377c" reference memory at "0x00000004". The memory could not be "read" ".
any idea what is this error
|
|
|
|
|
i can't really help you... but this article may help...
http://www.codeproject.com/debug/survivereleasever.asp
hope this helps
bernhard
"There are three roads to ruin: women, gambling and technicians. The most pleasant is with women, the quickest is with gambling, but the surest is with technicians." Georges Pompidou
|
|
|
|
|
Hi Guys,
Did it ever happened to you that you wanted to send some big files to a friend in small pieces by mail and you needed to do all the hard work of using one application to split it and then attach the pieces your self...
I had this problem and I found an application that does this for you and more and I want to recommend it.
It is called "Moving" application and it can be downloaded from the site:
http://www.domoving.com
It does the above in a very easy way and you can also ask for confirmation that the reciever who got your pieces succeeded in opening them.
It also bypass firewalls so I can send exe,mp3,etc. files to friends that are "blocked" and can get this kind of mail.
Eran
|
|
|
|
|
10x for your recommendation,
this a really cool tool, one of the best I bump into lately.
|
|
|
|
|
I need to draw an image onto a part of the Desktop!If anybody knows how to do it please help me with a a sample!
Thanks in advance!!
|
|
|
|
|