|
Hello,
I want to create a random password generator. I would like to generate 56 chars of garbage like “₧○▲╫º╪§a2/1&*(#C23j;lc)(8sdalk+]ds<32ds?9s%ncKLJw@#*)54^”
Anyone know of any way to do this?
Rob
|
|
|
|
|
You could try using a loop and rand() to generate the ASCII codes for the characters, thats the only thing that comes to mind just now. And then swap the ASCII character into the string. Not looked in MSDN to see if thats possible and can't remember if it is.
|
|
|
|
|
char buf[ 56+1 ] ;
for ( size_t i=0 ; i < sizeof(buf)-1 ; ++i )
buf[i] = 32 + (rand() % (127-32)) ;
buf[i] = '\0' ;
he he he. I like it in the kitchen! - Marc Clifton (on taking the heat when being flamed)
Awasu v0.4a[^]: A free RSS reader with support for Code Project.
|
|
|
|
|
Perfect
Thanks
|
|
|
|
|
Great stuff Taka,
it was way beyond my hungover brain just now to think of the code so thanks for clearing it up for me
|
|
|
|
|
Getting the range right and avoiding off-by-one errors is such a drag, even when you're sober
he he he. I like it in the kitchen! - Marc Clifton (on taking the heat when being flamed)
Awasu v0.4a[^]: A free RSS reader with support for Code Project.
|
|
|
|
|
I've been working on a small utility that needs to read/write Linux style configuration files. I have just started templating the class responsible for holding the file's content and I've run into a small problem. The following is a listing of the template declaration for the class.
template<
class Element,
class Traits = std::char_traits<Element>,
class Allocator = std::allocator<Element>,
class Container = std::map<std::basic_string<Element, Traits, Allocator>,
std::basic_string<Element, Traits, Allocator> >
>
class basic_configuration {
};
My hope was to allow for the container used for storing the key/value pairs (key=value) to be changeable via a template parameter. Unfortunately, the above code will not compile... it crashes the compiler (VC 6.0, SP5).
Any suggestions on how I might go about fixing this?
cheers,
-B
|
|
|
|
|
Here is how, for anyone who's interested.
template<
class Element,
class Traits = std::char_traits<Element>,
class Allocator = std::allocator<Element>
>
struct MyContainer {
typedef std::basic_string<Element, Traits, Allocator> string_type;
typedef std::map<string_type, string_type> type;
};
template<
class Element,
class Traits = std::char_traits<Element>,
class Allocator = std::allocator<Element>,
class Container = MyContainer::type
>
class basic_configuration {
};
cheers,
-B
|
|
|
|
|
I have an old HP LaserJet 4 printer, which is a wonderfully reliable old piece of iron they will
probably bury with me. Under DOS I knew how to write code to put it in manual feed mode so I
could print envelopes fed into the manual feed bin. Now I am trying to figure out how to do so
using Microsoft VC++ under Windows (98, ME, 2000, and XP). I have written a short test procedure
(see TestPrint below), which does print the desired text but does not switch to the manual feed
bin as it I intended. The test procedure calls a function (HaveCapability) to test whether manual
feed is available and the fuction correctly determines that it is.
I would greatly appreciate any help you can give me in solving this problem.
//*********************************************************************************
void TestPrint()
{
// Instantiate a CPrintDialog.
CPrintDialog *printDlg = new CPrintDialog(FALSE, PD_ALLPAGES | PD_RETURNDC, NULL);
printDlg->GetDefaults();
//Set up to see if printer has a manual feed mode (pDevMode->dmDefaultSource == DMBIN_MANUAL)
LPDEVMODE pDevMode = NULL;
WORD nOldDefaultSource;
BOOL bHaveCapability = HaveCapability(printDlg->GetDeviceName(), printDlg->GetPortName(), DMBIN_MANUAL);
//If printer has a manual feed mode, select it
if (bHaveCapability == TRUE)
{
pDevMode = printDlg->GetDevMode();
nOldDefaultSource = pDevMode->dmDefaultSource;
pDevMode->dmDefaultSource = DMBIN_MANUAL;
}
// Obtain handle to the device context.
HDC hdcPrn = printDlg->GetPrinterDC();
if (hdcPrn == NULL)
{
delete printDlg;
return;
}
CDC* pDC = new CDC;
pDC->Attach(hdcPrn); // attach handle to a printer DC
pDC->StartDoc("Test print job");// begin a new print job
//Set the font
int nPointSizeX10 = 140;
CFont fntCurrent;
fntCurrent.CreatePointFont(nPointSizeX10, "Times New Roman", pDC);
CFont* pOldFont = pDC->SelectObject(&fntCurrent);
//Get the line height
TEXTMETRIC tm;
pDC->GetTextMetrics(&tm);
int nLineHeight = tm.tmHeight + tm.tmInternalLeading;
//Specify where to print on page
int nLineX = 10;
int nLineY = 10;
pDC->StartPage(); // begin a new page
//Create and print the test text
CString csTestText;
for (int i = 0; i < 4; i++)
{
csTestText.Format("Line %i", i + 1);
pDC->TextOut(nLineX, nLineY, csTestText);
nLineY += nLineHeight;
}
pDC->EndPage(); // end a page
pDC->SelectObject(pOldFont);//Restore font
pDC->EndDoc(); // end a print job
//Restore original paper source
if (bHaveCapability == TRUE)
{
pDevMode->dmDefaultSource = nOldDefaultSource;
}
pDC->Detach(); // detach the printer DC
delete pDC;
delete printDlg;
}
//***********************************************************************************
/* Notes on HaveCapability
HaveCapability calls DeviceCapabilities to determine whether specified capability is available.
The following is from the MSDN library regarding use of DeviceCapabilities.
DWORD DeviceCapabilities(
LPCTSTR pDevice, // printer name
LPCTSTR pPort, // port name
DC_BINS, // device capability
LPTSTR pOutput, // output buffer
CONST DEVMODE *pDevMode); // device data buffer
Retrieves a list of available paper bins. The pOutput buffer receives an array of WORD values
that indicate the available paper sources for the printer. The return value indicates the number
of entries in the array. For a list of the possible array values, see the description of the
dmDefaultSource member of the DEVMODE structure. If pOutput is NULL, the return value indicates
the required number of entries in the array.
Possible WORD values
DMBIN_ONLYONE
DMBIN_LOWER
DMBIN_MIDDLE
DMBIN_MANUAL
DMBIN_ENVELOPE
DMBIN_ENVMANUAL
DMBIN_AUTO
DMBIN_TRACTOR
DMBIN_SMALLFMT
DMBIN_LARGEFMT
DMBIN_LARGECAPACITY
DMBIN_CASSETTE
DMBIN_FORMSOURCE
*/
BOOL HaveCapability(CString csDeviceName, CString csPortName, WORD nCapabilityToTest)
{
WORD pOutput[64];//Should be big enough
DWORD nNumEntries = DeviceCapabilities(
csDeviceName,
csPortName,
DC_BINS,
(char*)pOutput,
NULL);
if (nNumEntries != -1)
{
for (DWORD i = 0; i < nNumEntries; i++)
{
if (pOutput[i] == nCapabilityToTest)
return TRUE;
}
}
return FALSE;
}
|
|
|
|
|
I am trying to convert a CString to char so I can run it through inet_addr I think I have done this before but cannot remember how. Thanks if anyone can help.
- Matt Newman / Windows XP Activist
"Well, the guy that's giving you a hard time is a f***in moron, and you can tell him thats straight from another Linux user." - John Simmons on Linux Users Just do the American thing and shoot him... - Jim Crafton on Linux Users Wh3n my l33t skillz 1mpr0v3, I w1ll h4ck M$, 4nd th3n wh0 w1ll b3 l4ugh1ng ? N0t Bill. H4 h4 h4 h4 h4 h4 h4. - Christian Graus
|
|
|
|
|
Matt Newman wrote:
convert a CString to char
I think you actually want a const char*. Anyway, you should be able to just pass the CString object right in because it has a default LPCTSTR operator.
|
|
|
|
|
Matt Gullett wrote:
I think you actually want a const char*.
I double checked and that is the one I want. However when I try to compile
CString strDest = _T("192.168.0.6");
...
dwForwardDest = inet_addr(strDest);
I get this compile error:
error C2664: 'inet_addr' : cannot convert parameter 1 from 'CString' to 'const char *'
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
- Matt Newman / Windows XP Activist
"Well, the guy that's giving you a hard time is a f***in moron, and you can tell him thats straight from another Linux user." - John Simmons on Linux Users Just do the American thing and shoot him... - Jim Crafton on Linux Users Wh3n my l33t skillz 1mpr0v3, I w1ll h4ck M$, 4nd th3n wh0 w1ll b3 l4ugh1ng ? N0t Bill. H4 h4 h4 h4 h4 h4 h4. - Christian Graus
|
|
|
|
|
CString strDest = _T("192.168.0.6");
char buff[512];
_tcscopy(buff,strDest);
dwForwardDest = inet_addr(buff);
Thats what I'd do, and I've used it on a couple of oldie winsock programs so it seems to work for me.
|
|
|
|
|
I tried this but I got an error
error C2664: 'wcscpy' : cannot convert parameter 1 from 'char [512]' to 'wchar_t *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
- Matt Newman / Windows XP Activist
"Well, the guy that's giving you a hard time is a f***in moron, and you can tell him thats straight from another Linux user." - John Simmons on Linux Users Just do the American thing and shoot him... - Jim Crafton on Linux Users Wh3n my l33t skillz 1mpr0v3, I w1ll h4ck M$, 4nd th3n wh0 w1ll b3 l4ugh1ng ? N0t Bill. H4 h4 h4 h4 h4 h4 h4. - Christian Graus
|
|
|
|
|
Is this a UNICODE build? Are you building under VC7?
I am not 100% sure, but on VC7 you may need to do (LPCTSTR)strSomeString to get what you want.
If this is a UNICODE build, you will need to convert the contents of the CString from UNICODE WCHAR to char. Take a look at the wctomb function.
|
|
|
|
|
I forgot about the UNICODE troubles but the (LPCTSTR) trick doesn't seem to work for this one.
- Matt Newman / Windows XP Activist
"Well, the guy that's giving you a hard time is a f***in moron, and you can tell him thats straight from another Linux user." - John Simmons on Linux Users Just do the American thing and shoot him... - Jim Crafton on Linux Users Wh3n my l33t skillz 1mpr0v3, I w1ll h4ck M$, 4nd th3n wh0 w1ll b3 l4ugh1ng ? N0t Bill. H4 h4 h4 h4 h4 h4 h4. - Christian Graus
|
|
|
|
|
I am able to use a standard CString, strange that its giving you an error.. Maybe try
dwForwardDest = inet_addr(LPCTSTR("192.168.0.6"));
|
|
|
|
|
It is giving me errors because I am converting a MBCS console application to a UNICODE MFC appplication so the UNICODE/MBCS types are conflicting etc
- Matt Newman / Windows XP Activist
"Well, the guy that's giving you a hard time is a f***in moron, and you can tell him thats straight from another Linux user." - John Simmons on Linux Users Just do the American thing and shoot him... - Jim Crafton on Linux Users Wh3n my l33t skillz 1mpr0v3, I w1ll h4ck M$, 4nd th3n wh0 w1ll b3 l4ugh1ng ? N0t Bill. H4 h4 h4 h4 h4 h4 h4. - Christian Graus
|
|
|
|
|
Matt Newman wrote:
cannot convert parameter 1 from 'CString' to 'const char *'
That tells me you're doing a Unicode build. CString has an LPCTSTR converter, which is a Unicode string in Unicode builds. Since you need a single-byte string, you'll need to convert it. The quickest way is an ATL conversion macro.
#include <atlconv.h>
{
USES_CONVERSION;
CString strDest = _T("192.168.0.6");
...
dwForwardDest = inet_addr( T2CA((LPCTSTR)strDest) );
}
--Mike--
When 900 years old you reach, look as good you will not. Hmm.
1ClickPicGrabber - Grab & organize pictures from your favorite web pages, with 1 click!
My really out-of-date homepage
Sonork-100.19012 Acid_Helm
|
|
|
|
|
Michael Dunn wrote:
T2CA
DOH! I with I knew about this several months ago. I know how to do it manually, but this is much, much easier.
|
|
|
|
|
I tell you all higher education does is makes you for get the UNICODE/MBCS conversion macros Thanks for the help!
- Matt Newman / Windows XP Activist
"Well, the guy that's giving you a hard time is a f***in moron, and you can tell him thats straight from another Linux user." - John Simmons on Linux Users Just do the American thing and shoot him... - Jim Crafton on Linux Users Wh3n my l33t skillz 1mpr0v3, I w1ll h4ck M$, 4nd th3n wh0 w1ll b3 l4ugh1ng ? N0t Bill. H4 h4 h4 h4 h4 h4 h4. - Christian Graus
|
|
|
|
|
thanks a lot !
|
|
|
|
|
hi
is there any simple way to load images such as BMP or Gif or any other formats from Resources and NOT FROM THE FILE using GDI+ .
for example i include a bitmap in Resource .how can i Load it in my project that project.EXE don't need that picture file anymore.
regards
|
|
|
|
|
Bitmap::FromResource()
--Mike--
When 900 years old you reach, look as good you will not. Hmm.
1ClickPicGrabber - Grab & organize pictures from your favorite web pages, with 1 click!
My really out-of-date homepage
Sonork-100.19012 Acid_Helm
|
|
|
|
|
i use this code line but it's not work . what is wrong with me?
<br />
Graphics graphics(dc.m_hDC);<br />
<br />
graphics.DrawImage(Bitmap::FromResource(AfxGetInstanceHandle(), L"IDB_BITMAP1"),0,0,400,400);
|
|
|
|
|