Author: wyoung
Date: Wed Mar 28 16:56:14 2007
New Revision: 1468
URL: http://svn.gna.org/viewcvs/mysqlpp?rev=1468&view=rev
Log:
Factored Unicode conversion and registry code out of new MFC example
into new util module, to be used by the next example we create.
Added:
trunk/examples/vstudio/util.cpp
trunk/examples/vstudio/util.h
Modified:
trunk/examples/vstudio/mfc/mfc.vcproj
trunk/examples/vstudio/mfc/mfc_dlg.cpp
trunk/examples/vstudio/mfc/mfc_dlg.h
Modified: trunk/examples/vstudio/mfc/mfc.vcproj
URL:
http://svn.gna.org/viewcvs/mysqlpp/trunk/examples/vstudio/mfc/mfc.vcproj?rev=1468&r1=1467&r2=1468&view=diff
==============================================================================
--- trunk/examples/vstudio/mfc/mfc.vcproj (original)
+++ trunk/examples/vstudio/mfc/mfc.vcproj Wed Mar 28 16:56:14 2007
@@ -44,7 +44,7 @@
<Tool
Name="VCCLCompilerTool"
Optimization="0"
- AdditionalIncludeDirectories="..\..\..\lib,
C:\Program Files\MySQL\MySQL Server 5.0\include"
+ AdditionalIncludeDirectories="..,..\..\..\lib,
C:\Program Files\MySQL\MySQL Server 5.0\include"
PreprocessorDefinitions="WIN32;_WINDOWS;_DEBUG"
MinimalRebuild="true"
BasicRuntimeChecks="3"
@@ -129,7 +129,7 @@
/>
<Tool
Name="VCCLCompilerTool"
- AdditionalIncludeDirectories="..\..\..\lib,
C:\Program Files\MySQL\MySQL Server 5.0\include"
+ AdditionalIncludeDirectories="..,..\..\..\lib,
C:\Program Files\MySQL\MySQL Server 5.0\include"
PreprocessorDefinitions="WIN32;_WINDOWS;NDEBUG"
MinimalRebuild="false"
RuntimeLibrary="2"
@@ -223,6 +223,10 @@
/>
</FileConfiguration>
</File>
+ <File
+ RelativePath="..\util.cpp"
+ >
+ </File>
</Filter>
<Filter
Name="Header Files"
@@ -243,6 +247,10 @@
</File>
<File
RelativePath=".\stdafx.h"
+ >
+ </File>
+ <File
+ RelativePath="..\util.h"
>
</File>
</Filter>
Modified: trunk/examples/vstudio/mfc/mfc_dlg.cpp
URL:
http://svn.gna.org/viewcvs/mysqlpp/trunk/examples/vstudio/mfc/mfc_dlg.cpp?rev=1468&r1=1467&r2=1468&view=diff
==============================================================================
--- trunk/examples/vstudio/mfc/mfc_dlg.cpp (original)
+++ trunk/examples/vstudio/mfc/mfc_dlg.cpp Wed Mar 28 16:56:14 2007
@@ -27,6 +27,7 @@
#include "stdafx.h"
#include "mfc.h"
#include "mfc_dlg.h"
+#include "util.h"
#include <mysql++.h>
@@ -52,8 +53,11 @@
HKEY key = OpenSettingsRegistryKey();
if (key) {
// There are pre-existing defaults we can use, so copy them in
- LoadSetting(key, _T("user"), sUserName);
- LoadSetting(key, _T("server"), sServerAddress);
+ TCHAR acBuffer[100];
+ LoadSetting(key, _T("user"), acBuffer, sizeof(acBuffer));
+ sUserName = acBuffer;
+ LoadSetting(key, _T("server"), acBuffer, sizeof(acBuffer));
+ sServerAddress = acBuffer;
RegCloseKey(key);
}
if ((sUserName.GetLength() == 0) ||
@@ -97,26 +101,6 @@
}
-//// LoadSetting ///////////////////////////////////////////////////////
-// Loads up the value of the named registry value underneath the given
-// key and returns it in sValue.
-
-bool
-CExampleDlg::LoadSetting(HKEY key, LPCTSTR pcName, CString& sValue)
-{
- TCHAR acBuffer[100];
- DWORD nBufSize = sizeof(acBuffer);
- if (RegQueryValueEx(key, pcName, 0, 0, LPBYTE(acBuffer),
- &nBufSize) == ERROR_SUCCESS) {
- sValue = acBuffer;
- return true;
- }
- else {
- return false;
- }
-}
-
-
//// OnBnClickedConnectButton //////////////////////////////////////////
// This is essentially the same thing as examples/simple1.cpp
@@ -126,9 +110,10 @@
WCHAR awcTempBuf[100];
const int kTempBufSize = NELEMS(awcTempBuf);
- // Save the user inputs to our member variables, and as a side
- // effect, to the registry for future use.
- SaveInputs();
+ // Pull user input into our member variables, then save that to the
+ // registry for future use.
+ UpdateData(TRUE);
+ SaveInputs(sServerAddress, sUserName);
// Clear out the results list, in case this isn't the first time
// we've come in here.
@@ -191,98 +176,3 @@
return TRUE;
}
-
-//// OpenSettingsRegistryKey ///////////////////////////////////////////
-
-HKEY
-CExampleDlg::OpenSettingsRegistryKey()
-{
- HKEY key1, key2;
- if ((RegOpenKey(HKEY_CURRENT_USER, _T("Software"), &key1) ==
- ERROR_SUCCESS) && (RegCreateKey(key1,
- _T("MySQL++ Examples"), &key2) == ERROR_SUCCESS)) {
- RegCloseKey(key1);
- return key2;
- }
- else {
- return 0;
- }
-}
-
-
-//// SaveInputs ////////////////////////////////////////////////////////
-
-void CExampleDlg::SaveInputs()
-{
- // Kick DDX code, make it give us current data
- UpdateData(TRUE);
-
- // Save that data to the registry so future runs and other examples
- // can use it.
- HKEY key = OpenSettingsRegistryKey();
- if (key) {
- SaveSetting(key, _T("user"), sUserName);
- SaveSetting(key, _T("server"), sServerAddress);
- RegCloseKey(key);
- }
-}
-
-
-//// SaveSetting ///////////////////////////////////////////////////////
-// Saves the given value as a named entry under the given registry key.
-
-void
-CExampleDlg::SaveSetting(HKEY k, LPCTSTR pcName, const CString& sValue)
-{
- RegSetValueEx(k, pcName, 0, REG_SZ, (const BYTE*)(LPCTSTR)(sValue),
- sizeof(TCHAR) * (sValue.GetLength() + 1));
-}
-
-
-//// ToUCS2 ////////////////////////////////////////////////////////////
-// Convert a C string in UTF-8 format to UCS-2 format.
-
-bool CExampleDlg::ToUCS2(LPTSTR pcOut, int nOutLen,
- const char* kpcIn)
-{
- if (strlen(kpcIn) > 0) {
- // Do the conversion normally
- return MultiByteToWideChar(CP_UTF8, 0, kpcIn, -1, pcOut,
- nOutLen) > 0;
- }
- else if (nOutLen > 1) {
- // Can't distinguish no bytes copied from an error, so handle
- // an empty input string as a special case.
- _tccpy(pcOut, _T(""));
- return true;
- }
- else {
- // Not enough room to do anything!
- return false;
- }
-}
-
-
-//// ToUTF8 ////////////////////////////////////////////////////////////
-// Convert a UCS-2 multibyte string to the UTF-8 format required by
-// MySQL, and thus MySQL++.
-
-bool
-CExampleDlg::ToUTF8(char* pcOut, int nOutLen, LPCWSTR kpcIn)
-{
- if (_tcslen(kpcIn) > 0) {
- // Do the conversion normally
- return WideCharToMultiByte(CP_UTF8, 0, kpcIn, -1, pcOut,
- nOutLen, 0, 0) > 0;
- }
- else if (nOutLen > 0) {
- // Can't distinguish no bytes copied from an error, so handle
- // an empty input string as a special case.
- *pcOut = '\0';
- return true;
- }
- else {
- // Not enough room to do anything!
- return false;
- }
-}
Modified: trunk/examples/vstudio/mfc/mfc_dlg.h
URL:
http://svn.gna.org/viewcvs/mysqlpp/trunk/examples/vstudio/mfc/mfc_dlg.h?rev=1468&r1=1467&r2=1468&view=diff
==============================================================================
--- trunk/examples/vstudio/mfc/mfc_dlg.h (original)
+++ trunk/examples/vstudio/mfc/mfc_dlg.h Wed Mar 28 16:56:14 2007
@@ -54,15 +54,8 @@
// Misc
void AddMessage(LPCTSTR pcMessage);
- bool LoadSetting(HKEY k, LPCTSTR pcName, CString& sValue);
- void SaveInputs();
- void SaveSetting(HKEY k, LPCTSTR pcName, const CString& sValue);
- bool ToUCS2(LPTSTR out, int nOutLen, const char* in);
- bool ToUTF8(char* pcOut, int nOutLen, LPCWSTR kpcIn);
private:
//// Internal data
HICON hIcon_;
-public:
- HKEY OpenSettingsRegistryKey(void);
};
Added: trunk/examples/vstudio/util.cpp
URL:
http://svn.gna.org/viewcvs/mysqlpp/trunk/examples/vstudio/util.cpp?rev=1468&view=auto
==============================================================================
--- trunk/examples/vstudio/util.cpp (added)
+++ trunk/examples/vstudio/util.cpp Wed Mar 28 16:56:14 2007
@@ -1,0 +1,143 @@
+/***********************************************************************
+ util.cpp - Functions used by all of the Visual C++ examples. If you're
+ just trying to understand the examples, you can pretty much just
+ ignore this module and depend on the functions' names: they do what
+ they're called. :)
+
+ Copyright (c) 2007 by Educational Technology Resources, Inc. Others
+ may also hold copyrights on code in this file. See the CREDITS file in
+ the top directory of the distribution for details.
+
+ This file is part of MySQL++.
+
+ MySQL++ is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as published
+ by the Free Software Foundation; either version 2.1 of the License, or
+ (at your option) any later version.
+
+ MySQL++ is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+ License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with MySQL++; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
+ USA
+***********************************************************************/
+
+#include "stdafx.h"
+
+#include "util.h"
+
+
+//// LoadSetting ///////////////////////////////////////////////////////
+// Loads up the value of the named registry value underneath the given
+// key and returns it in pcValue.
+
+bool
+LoadSetting(HKEY key, LPCTSTR pcName, LPTSTR pcValue, DWORD nValueSize)
+{
+ return RegQueryValueEx(key, pcName, 0, 0, LPBYTE(pcValue),
+ &nValueSize) == ERROR_SUCCESS;
+}
+
+
+//// OpenSettingsRegistryKey ///////////////////////////////////////////
+
+HKEY
+OpenSettingsRegistryKey()
+{
+ HKEY key1, key2;
+ if ((RegOpenKey(HKEY_CURRENT_USER, _T("Software"), &key1) ==
+ ERROR_SUCCESS) && (RegCreateKey(key1,
+ _T("MySQL++ Examples"), &key2) == ERROR_SUCCESS)) {
+ RegCloseKey(key1);
+ return key2;
+ }
+ else {
+ return 0;
+ }
+}
+
+
+//// SaveInputs ////////////////////////////////////////////////////////
+// Save the given strings to the registry so future runs and other
+// examples can use them.
+
+bool
+SaveInputs(LPCTSTR pcServerAddress, LPCTSTR pcUserName)
+{
+ HKEY key = OpenSettingsRegistryKey();
+ if (key) {
+ SaveSetting(key, _T("user"), pcUserName);
+ SaveSetting(key, _T("server"), pcServerAddress);
+ RegCloseKey(key);
+ return true;
+ }
+ else {
+ return false;
+ }
+}
+
+
+//// SaveSetting ///////////////////////////////////////////////////////
+// Saves the given value as a named entry under the given registry key.
+
+bool
+SaveSetting(HKEY key, LPCTSTR pcName, LPCTSTR pcValue)
+{
+ DWORD nBytes = DWORD(sizeof(TCHAR) * (_tcslen(pcValue) + 1));
+ return RegSetValueEx(key, pcName, 0, REG_SZ, LPBYTE(pcValue),
+ nBytes) == ERROR_SUCCESS;
+}
+
+
+//// ToUCS2 ////////////////////////////////////////////////////////////
+// Convert a C string in UTF-8 format to UCS-2 format.
+
+bool
+ToUCS2(LPTSTR pcOut, int nOutLen, const char* kpcIn)
+{
+ if (strlen(kpcIn) > 0) {
+ // Do the conversion normally
+ return MultiByteToWideChar(CP_UTF8, 0, kpcIn, -1, pcOut,
+ nOutLen) > 0;
+ }
+ else if (nOutLen > 1) {
+ // Can't distinguish no bytes copied from an error, so handle
+ // an empty input string as a special case.
+ _tccpy(pcOut, _T(""));
+ return true;
+ }
+ else {
+ // Not enough room to do anything!
+ return false;
+ }
+}
+
+
+//// ToUTF8 ////////////////////////////////////////////////////////////
+// Convert a UCS-2 multibyte string to the UTF-8 format required by
+// MySQL, and thus MySQL++.
+
+bool
+ToUTF8(char* pcOut, int nOutLen, LPCWSTR kpcIn)
+{
+ if (_tcslen(kpcIn) > 0) {
+ // Do the conversion normally
+ return WideCharToMultiByte(CP_UTF8, 0, kpcIn, -1, pcOut,
+ nOutLen, 0, 0) > 0;
+ }
+ else if (nOutLen > 0) {
+ // Can't distinguish no bytes copied from an error, so handle
+ // an empty input string as a special case.
+ *pcOut = '\0';
+ return true;
+ }
+ else {
+ // Not enough room to do anything!
+ return false;
+ }
+}
+
Added: trunk/examples/vstudio/util.h
URL:
http://svn.gna.org/viewcvs/mysqlpp/trunk/examples/vstudio/util.h?rev=1468&view=auto
==============================================================================
--- trunk/examples/vstudio/util.h (added)
+++ trunk/examples/vstudio/util.h Wed Mar 28 16:56:14 2007
@@ -1,0 +1,36 @@
+/***********************************************************************
+ util.h - Declares the utility functions used by all of the Visual C++
+ examples.
+
+ Copyright (c) 2007 by Educational Technology Resources, Inc. Others
+ may also hold copyrights on code in this file. See the CREDITS file in
+ the top directory of the distribution for details.
+
+ This file is part of MySQL++.
+
+ MySQL++ is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as published
+ by the Free Software Foundation; either version 2.1 of the License, or
+ (at your option) any later version.
+
+ MySQL++ is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+ License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with MySQL++; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
+ USA
+***********************************************************************/
+
+#pragma once
+
+bool LoadSetting(HKEY key, LPCTSTR pcName, LPTSTR pcValue,
+ DWORD nValueSize);
+HKEY OpenSettingsRegistryKey();
+bool SaveInputs(LPCTSTR pcServerAddress, LPCTSTR pcUserName);
+bool SaveSetting(HKEY key, LPCTSTR pcName, LPCTSTR pcValue);
+bool ToUCS2(LPTSTR pcOut, int nOutLen, const char* kpcIn);
+bool ToUTF8(char* pcOut, int nOutLen, LPCWSTR kpcIn);
+
_______________________________________________
Mysqlpp-commits mailing list
[email protected]
https://mail.gna.org/listinfo/mysqlpp-commits