Author: wyoung
Date: Wed Mar 28 19:39:37 2007
New Revision: 1475

URL: http://svn.gna.org/viewcvs/mysqlpp?rev=1475&view=rev
Log:
Folded util module back into MFC example.  The whole Managed C++/.NET
stuff won't permit using this Win32-API-centric code.  Oh, we could, but
we'd end up basically having two versions, one the straight C++ code,
and the other with a whole bunch of data conversion stuff going on to
shuttle data back and forth between the managed and unmanaged worlds.
Better to just write a new util module for the Windows Forms example
that uses .NET classes and all managed data.

Added:
    trunk/examples/vstudio/mfc/stdafx.h
Removed:
    trunk/examples/vstudio/util.cpp
    trunk/examples/vstudio/util.h
Modified:
    trunk/examples/vstudio/mfc/mfc.cpp
    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.cpp
URL: 
http://svn.gna.org/viewcvs/mysqlpp/trunk/examples/vstudio/mfc/mfc.cpp?rev=1475&r1=1474&r2=1475&view=diff
==============================================================================
--- trunk/examples/vstudio/mfc/mfc.cpp (original)
+++ trunk/examples/vstudio/mfc/mfc.cpp Wed Mar 28 19:39:37 2007
@@ -24,6 +24,7 @@
  USA
 ***********************************************************************/
 
+#include "stdafx.h"
 #include "mfc.h"
 #include "mfc_dlg.h"
 

Modified: trunk/examples/vstudio/mfc/mfc.vcproj
URL: 
http://svn.gna.org/viewcvs/mysqlpp/trunk/examples/vstudio/mfc/mfc.vcproj?rev=1475&r1=1474&r2=1475&view=diff
==============================================================================
--- trunk/examples/vstudio/mfc/mfc.vcproj (original)
+++ trunk/examples/vstudio/mfc/mfc.vcproj Wed Mar 28 19:39:37 2007
@@ -203,10 +203,6 @@
                                RelativePath=".\mfc_dlg.cpp"
                                >
                        </File>
-                       <File
-                               RelativePath="..\util.cpp"
-                               >
-                       </File>
                </Filter>
                <Filter
                        Name="Header Files"
@@ -223,10 +219,6 @@
                        </File>
                        <File
                                RelativePath=".\Resource.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=1475&r1=1474&r2=1475&view=diff
==============================================================================
--- trunk/examples/vstudio/mfc/mfc_dlg.cpp (original)
+++ trunk/examples/vstudio/mfc/mfc_dlg.cpp Wed Mar 28 19:39:37 2007
@@ -24,6 +24,7 @@
  USA
 ***********************************************************************/
 
+#include "stdafx.h"
 #include "mfc_dlg.h"
 #include "util.h"
 
@@ -88,6 +89,19 @@
 }
 
 
+//// LoadSetting ///////////////////////////////////////////////////////
+// Loads up the value of the named registry value underneath the given
+// key and returns it in pcValue.
+
+bool
+CExampleDlg::LoadSetting(HKEY key, LPCTSTR pcName, LPTSTR pcValue,
+               DWORD nValueSize)
+{
+       return RegQueryValueEx(key, pcName, 0, 0, LPBYTE(pcValue),
+                       &nValueSize) == ERROR_SUCCESS;
+}
+
+
 //// OnBnClickedConnectButton //////////////////////////////////////////
 // This is essentially the same thing as examples/simple1.cpp
 
@@ -150,3 +164,102 @@
                }
        }
 }
+
+
+//// 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 ////////////////////////////////////////////////////////
+// Save the given strings to the registry so future runs and other
+// examples can use them.
+
+bool
+CExampleDlg::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
+CExampleDlg::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
+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=1475&r1=1474&r2=1475&view=diff
==============================================================================
--- trunk/examples/vstudio/mfc/mfc_dlg.h (original)
+++ trunk/examples/vstudio/mfc/mfc_dlg.h Wed Mar 28 19:39:37 2007
@@ -41,8 +41,15 @@
 
 protected:
        //// Internal support functions
-       virtual void DoDataExchange(CDataExchange* pDX);
        void AddMessage(LPCTSTR pcMessage);
+       void DoDataExchange(CDataExchange* pDX);
+       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);
 
        //// Message map
        afx_msg void OnBnClickedConnectButton();

Added: trunk/examples/vstudio/mfc/stdafx.h
URL: 
http://svn.gna.org/viewcvs/mysqlpp/trunk/examples/vstudio/mfc/stdafx.h?rev=1475&view=auto
==============================================================================
--- trunk/examples/vstudio/mfc/stdafx.h (added)
+++ trunk/examples/vstudio/mfc/stdafx.h Wed Mar 28 19:39:37 2007
@@ -1,0 +1,54 @@
+/***********************************************************************
+ stdafx.h - Common include file to bring in MFC support and other
+       basics.
+
+ 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
+
+#ifndef VC_EXTRALEAN
+#define VC_EXTRALEAN           // Exclude rarely-used stuff from Windows 
headers
+#endif
+
+// Modify the following defines if you have to target a platform prior to the 
ones specified below.
+// Refer to MSDN for the latest info on corresponding values for different 
platforms.
+#ifndef WINVER                         // Allow use of features specific to 
Windows XP or later
_______________________________________________
Mysqlpp-commits mailing list
[email protected]
https://mail.gna.org/listinfo/mysqlpp-commits

Reply via email to