|
Hi,
I seldom recommend specific books, I tend to go to a book store, look at say 10 similar books and
choose 1 or 2. It is all very subjective, how familiar are you with programming, how much are you
interested in examples and exercises, etc.
|
|
|
|
|
|
This was my C++ primer: "Teach Yourself C++ in 21 Days" [^], Jesse's explanations of classes and inheritance are great for beginners.
Book teaches you C++ in logical and organized manner, and is perfect for beginners.
|
|
|
|
|
Does SetRegistryKey make the App registry default to ...\HKey_Current_User or is it decalred explicitly somwhere else, I would like to have some settings under .....\Hkey_Local_Machine for all users purposes.... Can someone clarify this for me a bit?
Thanks
sft
|
|
|
|
|
Software2007 wrote: Does SetRegistryKey make the App registry default to ...\HKey_Current_User
Yes. See the source code
It also only affects the "GetProfileInt, GetProfileString, WriteProfileInt,
and WriteProfileString member functions of CWinApp"
Software2007 wrote: I would like to have some settings under .....\Hkey_Local_Machine for all users purposes
Keep in mind that on Vista+, only app's running with elevated privileges will
be able to write to the HKLM key...
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
http://msdn.microsoft.com/en-us/library/7c2w6z4k(VS.80).aspx[^] is pretty clear:
It is stored in a key of the following form: HKEY_CURRENT_USER\Software\<company name>\<application name>\<section name>\<value name>.
If you want something stored under HKLM, you'll have to (wo)man up and write some real code. That said, you'll run into lots of problems trying to set it from any old user - it's all securitied, and for good reason.
For me, I use HKLM for machine parameters (ie, this machine has 5 motors) that are use independent, and KHCU for most others (ie, "I like blue!")
Iain.
Codeproject MVP for C++, I can't believe it's for my lounge posts...
|
|
|
|
|
Hi guys,
I'm attempting to add network printers to a local machine, only I've run into some trouble with the AddPrinter call. Essentially it returns 0 for the handle and doesn't tell me anything with GetLastError - I read somewhere this is a bug in the API, but don't know if its still there ( although, it appears so !)
Code goes like so:
PRINTER_INFO_2 *pi1=NULL;
DWORD size(0), numOfPrinters(0);
EnumPrinters(PRINTER_ENUM_NAME, (LPSTR)strPrintServerName.c_str(), 2, NULL, 0, (LPDWORD)&size, (LPDWORD)&numOfPrinters);
pi1 = new PRINTER_INFO_2[numOfPrinters+1];
if (EnumPrinters(PRINTER_ENUM_NAME, (LPSTR)strPrintServerName.c_str(), 2, (LPBYTE)pi1, size, (LPDWORD)&size, (LPDWORD)&numOfPrinters))
{
for(unsigned int i=0; i<numOfPrinters; i++)
{
PRINTER_INFO_2 *pi2 = &pi1[i];
std::cout << pi2->pPrinterName << std::endl;
HANDLE hPrinter(0);
hPrinter = AddPrinter(pi2->pPrinterName, 2, (LPBYTE)pi2);
if (hPrinter != 0)
{
std::cout << "Printer handle " << hPrinter << std::endl;
}
else
{
std::cout << "Failed to add printer " << pi2->pPrinterName << std::endl;
}
}
}
else
{
std::cout << "Enum Call failed - " << GetLastError() << std::endl;
}
delete [] pi1;
Any help you can offer would be much appreciated!
Andrew
|
|
|
|
|
Why are you passing pi2->pPrinterName in as the first parameter to AddPrinter? According to http://msdn.microsoft.com/en-us/library/ms535500(VS.85).aspx[^] this should be NULL for local printers.
You may also have to change the pServerName and Attributes members of the PRINER_INFO_2 structure (if only to remove the PRINTER_ATTRIBUTE_NETWORK part)
|
|
|
|
|
Its not a local printer. Its one of the printers hanging of the print server, that was returned in the EnumPrinters call.
Are you saying if I want to install a shared network printer, I still need to pass NULL to this function? (Just noticed I was passing the printer name instead of the server name anyway)
The call still fails using the print server name of NULL...
|
|
|
|
|
I assumed you were trying to copy the connected (network) printers for some reason. You enumerate the printers, then loop through and add them all again, it looks like to me.
|
|
|
|
|
What I'm trying to do is programmatically add network printers to a local terminal (minimum. 2K).
Am I going about it the right way?
|
|
|
|
|
I don't understand what you're trying to do. The printers are already connected (or else EnumPrinters wouldn't find them). Why do you need to connect to them again?
|
|
|
|
|
I need to programatically allow certain users access to the printers attached to the server.
If they're not authorised then they can't see the printers.
The printers are connected to the server and I want to bypass the usual way you would add a network printer via the GUI.
|
|
|
|
|
I am using CProperySheet and CPropertyPage in my application for creating tabbed dialog boxes.
For providing the RTL layout, I am using the WS_EX_LAYOUTRTL for Property Sheet and Property Pages both.
This is doing well.
The Titla bar ( System control and min/max/restore buttons) are now in RTL layout.
Tabs contents are also in RTL layout. However two issues are still remaining opened-
1. OK and CANCEL buttons (that were in the Right Side of the screen before applying WS_EX_LAYOUTRTL style) are now in the Middle of the screen. They should be in the Left of the screen.
(Point to notice is that i have hide the "Help" and "Apply" buttons.)
2. Tabs (Tab Bar) are still coming in the Left side of the screen. No effect of the RTL layout on the tabs (Tab Bar) alignment or in their order.
<br />
void CAllControlsSheet::AddControlPages()<br />
{<br />
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);<br />
m_psh.dwFlags |= PSP_USEHICON;<br />
m_psh.hIcon = m_hIcon;<br />
m_psh.dwFlags |= PSH_NOAPPLYNOW;
m_psh.dwFlags |= PSH_RTLREADING ; <br />
m_psh.dwFlags &= ~PSH_HASHELP;
<br />
Invalidate();<br />
<br />
AddPage(&m_treectrlpage);<br />
AddPage(&m_animctrlpage);<br />
AddPage(&m_toolbarpage);<br />
AddPage(&m_datetimepage);<br />
AddPage(&m_monthcalpage);<br />
<br />
}<br />
<br />
BEGIN_MESSAGE_MAP(CAllControlsSheet, CPropertySheet)<br />
ON_WM_QUERYDRAGICON()<br />
ON_WM_SYSCOMMAND()<br />
END_MESSAGE_MAP()<br />
<br />
<br />
BOOL CAllControlsSheet::OnInitDialog()<br />
{<br />
<br />
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);<br />
ASSERT(IDM_ABOUTBOX < 0xF000);<br />
<br />
CMenu* pSysMenu = GetSystemMenu(FALSE);<br />
if (pSysMenu != NULL)<br />
{<br />
CString strAboutMenu;<br />
strAboutMenu.LoadString(IDS_ABOUTBOX);<br />
if (!strAboutMenu.IsEmpty())<br />
{<br />
pSysMenu->AppendMenu(MF_SEPARATOR);<br />
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);<br />
}<br />
}<br />
<br />
SetIcon(m_hIcon, TRUE);<br />
SetIcon(m_hIcon, FALSE);<br />
ModifyStyleEx(0, WS_EX_LAYOUTRTL); <br />
return CPropertySheet::OnInitDialog();<br />
}<br />
<br />
|
|
|
|
|
How can I do it ?
Trying with the following code is not helpful :
<br />
wofstream fout;<br />
fout.open(fileTo, ios_base::out | ios_base::trunc | ios_base::binary);<br />
fout << content.c_str();<br />
fout << flush;<br />
fout.close();<br />
(where content is of type std::wstring)
Are there special header characters I need to insert in order to indicate to a standard UTF-8 text file reader (such as NotePad) that the file is actually encoded in UTF-8 ??
Thank you in advance.
modified on Wednesday, January 14, 2009 1:09 PM
|
|
|
|
|
Here's one way:
wstring content = L"Test String";
ofstream fout;
fout.open("e:\\testutf8.txt", ios_base::out | ios_base::trunc | ios_base::binary);
fout.write("\xEF\xBB\xBF", 3);
int bufsize = ::WideCharToMultiByte(CP_UTF8, 0, content.c_str(), -1, NULL, 0, NULL, NULL);
LPSTR buf = new CHAR[bufsize];
bufsize = ::WideCharToMultiByte(CP_UTF8, 0, content.c_str(), -1, buf, bufsize, NULL, NULL);
fout.write(buf, bufsize-1);
fout << flush;
fout.close();
delete[] buf;
That should match what Notepad writes.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hello Mark,
Thank you very much it works fine.
I did many ways but all were in vain. Main reason was because I convinced my self that it has necessarily to be done
through an wofstreamù instead of ofstream in order to handle the std::wstring content..
many thanks indeed.
|
|
|
|
|
hINTModuleState wrote: through an wofstreamù instead of ofstream in order to handle the std::wstring content..
There's probably a way to do the conversion to UTF-8 using the wcstombs()
function but I just went with what I know...
just go straight to the conversion API and write the result as a binary byte stream
Cheers,
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I have a simple server app that uses WritePrivateProfileString() when a client changes the status of a user. I want to protect against multiple 'change status' requests resulting in clashing file writes.
The clients communicate with the server using UDP and the server uses a listener socket. The listener socket uses 'OnReceive()' to call a function to write to the data file.
I've been using a temp file to write to and then delete the working file then rename the temp file. It works most of the time but once in a while the main data file is deleted and there is no temp file. It's a bug but I'm wondering if there is a better way?
Thank you.
|
|
|
|
|
Does each client get serviced on a separate thread by the server? If yes, you'll need to use some kind of synchronization object while writing to the file. A CRITICAL_SECTION might do nicely for you.
--
gleat
http://blogorama.nerdworks.in[ ^]
-- Number Two's eyes narrowed and became what are known in the Shouting and Killing People trade as cold slits, the idea presumably being to give your opponent the impression that you have lost your glasses or are having difficulty keeping awake. Why this is frightening is an, as yet, unresolved problem. -- HHGTG
|
|
|
|
|
I'm using a single instance of the listener socket. Would that be enough to ensure the file is only written by one client at a time?
|
|
|
|
|
What do you do when your "accept" (or the equivalent Windows socket extensions API) call returns? Do you launch another thread to respond to the client socket returned by "accept"? If you are doing it on the same thread as the one that invokes "accept" then you shouldn't require synchronization; in which case the problem lies elsewhere.
--
gleat
http://blogorama.nerdworks.in[ ^]
-- Number Two's eyes narrowed and became what are known in the Shouting and Killing People trade as cold slits, the idea presumably being to give your opponent the impression that you have lost your glasses or are having difficulty keeping awake. Why this is frightening is an, as yet, unresolved problem. -- HHGTG
|
|
|
|
|
I have a pointer to the server object (the object that created the listener socket), and I call a function in that server object. No additional threads.
Thank you for your time on this.
|
|
|
|
|
OK. You might want to conduct a little experiment. From your "OnReceive" handler, trace the return value of "GetCurrentThreadId" to a log and have multiple clients connect simultaneously to the server. Now inspect the log to see if the values logged are the same for all the clients.
Also, is there a code snippet that you can post that shows how you are doing the file processing?
|
|
|
|
|
CORBA::Boolean CScope::Fineroot
(
IlAdapter::BaseTable*& corbaTexts,
{
corbaTexts = new IlAdapter::BaseTable;
if (result)
{
}
return result;
}
modified on Monday, January 12, 2009 8:53 AM
|
|
|
|