Is there a function to set the Code page of my program dynamically?

Hi,

There are several places in my program that I need to change between CString
and BSTR. (Maybe the rich edit controls also change between char and
unicode, I am not sure.)

I am using



USES_CONVERSION;

W2A

A2W



I found the same program worked under some languages, didn't under others.

Sometimes it worked in Edit control, but not in Rich Edit control.



I have added #define _CONVERSION_USES_THREAD_LOCALE in the stdafx.h but
found it not much help.



I trace into the mfc codes and found it called WideCharToMultiByte() at
last.

Is there a function so that I can set Code page (acp) dynamically?



inline LPSTR WINAPI AtlW2AHelper(LPSTR lpa, LPCWSTR lpw, int nChars, UINT
acp)

{

      ATLASSERT(lpw != NULL);

      ATLASSERT(lpa != NULL);

      // verify that no illegal character present

      // since lpa was allocated based on the size of lpw

      // don't worry about the number of chars

      lpa[0] = '\0';

      WideCharToMultiByte(acp, 0, lpw, -1, lpa, nChars, NULL, NULL);

      return lpa;

}



Thank you a lot,

Best regards,


0
Kelvin_gl (33)
6/8/2005 9:47:53 AM
vc.mfc 33608 articles. 0 followers. Follow

2 Replies
754 Views

Similar Articles

[PageSpeed] 13

I think SetThreadLocale is the Win32 API you need.

- Keith MacDonald

"Kelvin" <Kelvin_gl@yahoo.com.cn> wrote in message 
news:eiPF$9AbFHA.3120@TK2MSFTNGP12.phx.gbl...
> Hi,
>
> There are several places in my program that I need to change between 
> CString
> and BSTR. (Maybe the rich edit controls also change between char and
> unicode, I am not sure.)
>
> I am using
>
>
>
> USES_CONVERSION;
>
> W2A
>
> A2W
>
>
>
> I found the same program worked under some languages, didn't under others.
>
> Sometimes it worked in Edit control, but not in Rich Edit control.
>
>
>
> I have added #define _CONVERSION_USES_THREAD_LOCALE in the stdafx.h but
> found it not much help.
>
>
>
> I trace into the mfc codes and found it called WideCharToMultiByte() at
> last.
>
> Is there a function so that I can set Code page (acp) dynamically?
>
>
>
> inline LPSTR WINAPI AtlW2AHelper(LPSTR lpa, LPCWSTR lpw, int nChars, UINT
> acp)
>
> {
>
>      ATLASSERT(lpw != NULL);
>
>      ATLASSERT(lpa != NULL);
>
>      // verify that no illegal character present
>
>      // since lpa was allocated based on the size of lpw
>
>      // don't worry about the number of chars
>
>      lpa[0] = '\0';
>
>      WideCharToMultiByte(acp, 0, lpw, -1, lpa, nChars, NULL, NULL);
>
>      return lpa;
>
> }
>
>
>
> Thank you a lot,
>
> Best regards,
>
> 


0
nospam2782 (35)
6/8/2005 2:16:35 PM
On Wed, 8 Jun 2005 18:47:53 +0900, Kelvin wrote:

> Hi,
> 
> There are several places in my program that I need to change between CString
> and BSTR. (Maybe the rich edit controls also change between char and
> unicode, I am not sure.)
> 
> I am using
> 
> 
> 
> USES_CONVERSION;
> 
> W2A
> 
> A2W
> 
> 
> 
> I found the same program worked under some languages, didn't under others.
> 
> Sometimes it worked in Edit control, but not in Rich Edit control.
> 
> 
> 
> I have added #define _CONVERSION_USES_THREAD_LOCALE in the stdafx.h but
> found it not much help.
> 
> 
> 
> I trace into the mfc codes and found it called WideCharToMultiByte() at
> last.
> 
> Is there a function so that I can set Code page (acp) dynamically?

For the C++ level and below, see <locale>. For C, see <locale.h>. Unless
you're using C++ Standard Library features that use the C++ locale, you can
probably get away with using setlocale in <locale.h>.

-- 
Doug Harrison
Microsoft MVP - Visual C++
0
dsh (2498)
6/8/2005 3:31:13 PM
Reply:

Similar Artilces:

ROUND Function with other function
Hi, I have this formula: =IF(R8>0,CONCATENATE("+",R8),R8) and the results shows me for example: +11.6 but what I really want t show is +12. I've been trying to put the "Round" function at a few places in th formula but it doesn't work. The closest I got was with this formula: =ROUND(IF(R8>0,CONCATENATE("+",R8),R8),0) where it showed me 12, without the "+" sign before.... Can anyone help me ? Thank -- Outapi ----------------------------------------------------------------------- Outapin's Profile: http://www.excelforum.com/member...

How do I sort area codes by time zones
How do I sort area codes by time zones you have your area codes in say column A and your associated time zone data in column B.Select both columns and Data>Sort Ascending by column B -- paul remove nospam for email addy! "Paul" wrote: > How do I sort area codes by time zones ...

Returning a range from an inner function
I have a range of data, which has had the DOLLAR() function performed on it. I would like to get the total of this range using the SUM() function. doing SUM(F1:F4) will not work, so I need to convert the data into values that will work. The VALUE() function is perfect for converting the data into values that will work for SUM(), but the formula SUM(VALUE(F1:F4)) does not work because VALUE() will not accept a range as a parameter (and also does not return a range). I need to perform the VALUE() function on each cell before submitting it to SUM(). There must be some way to do this, cons...

cannot set outlook as default mail client
I cannot set Outlook as the default mail client. When I go to setup a mail profile it opens the Internet Account mail dialog box. I have followed MS's articles to set Outlook as the default client in IE 5.5 SP2, but still no change. Any suggestions would be appreciated. Robin What version of Outlook? --� Milly Staples [MVP - Outlook] Post all replies to the group to keep the discussion intact. Due to the Swen virus, all e-mails sent to my actual account will be deleted w/out reading. After searching google.groups.com and finding no answer mainr@tc.gc.ca <anonymous@discussions.mi...

vba code for saving file
Hi, I want to create a button that save (saveas) the workbook where the filename should be the string thats in cell B2 Anyone? txs One way: Public Sub CommandButton1_Click() Const ERRSTR As String = "File not saved." & _ vbNewLine & vbNewLine Dim fName As String On Error GoTo Handler With ActiveWorkbook fName = .Sheets("Sheet1").Range("B2").Text If Len(Trim(fName)) = 0 Then _ Err.Raise 32769 If Mid(fName, Len(fName) - 3, 1) <> "." T...

JustifyString function problem
Hi, I'm using the "JustifyString" function (from Stephan Lebans) to right justify three columns in a ListBox. Two of them are working fine ... one's a simple number (long integer) and the other's currency. The third causes an Access 2003 crash! That third column is a long integer which is a link to the autonumber field in another table. Both tables are in the query as I need columns from both tables in the ListBox. If I change the JustifyString to reference the autonumber field in the other table, I still get an Access crash. I didn't review the Access er...

sample custom extension code?
I would like to try my hand at creating a custom extension that would get triggered by the additem hook. Is there any place where I can find a generic example to work with and modify? I looked in customersource and didn't find anything - just not sure where to look specifically thank you, kevin ...

automating functions
I am a complete novice at CRM 1.2, but want to be able to create, for example, a workflow process that will monitor the CSR's and the queues and automatically assign a new case to the least busy CSR. Any input would be appreciated. Thanks in advance Jim Please tell me what I would have to do and with what tools in order to create such a workflow process. "jmb" wrote: > I am a complete novice at CRM 1.2, but want to be able to create, for > example, a workflow process that will monitor the CSR's and the queues and > automatically assign a new case to the lea...

Returning a CHAR[] from a function
I have the following function that returns the path of where the program was run from. However I cant seem to return the butter as a CHAR. The code works if I use it in a procedure but not where I need to return the variable CHAR buffer. char CAutoRunDlg::GetProgramPath(void) { char buffer[_MAX_PATH]; //declares maimum path //opens window maximized //_getcwd(,)gets the current working directory // #include <direct.h> //needed for current working directory /* Get the current working directory: */ if( _getcwd( buffer, _MAX_PATH ) == NULL ) perror( "_getcwd error" )...

Windows installer & language settings appear everytime Pub opens
I've been using Pub 2007 for almost 2 years, but beginning a while ago everytime I open Pub i have the longest delays. First a windows installer window pops up...then a language MUI window. It is the longest process to get a doc opened. Same happens when I try to open the picture editor. So frustrating! How to use the repair process in the 2007 Office programs http://support.microsoft.com/kb/924614/en-us Have you installed the Service Pack? Description of the 2007 Microsoft Office suite Service Pack 1 http://support.microsoft.com/kb/936982/en-us -- Mary Sauer http://msauer.mvps.or...

Recovering deleted mails when retention policy is set
If the "recover deleted mails" option does not show any mails available to recover, how do i restore a users deleted mails? We have a retention policy set, and I'm wondering if the mails are retained somewhere on the exchange server even if they don't show as available for reovery via Outlook? if the emails were "hard deleted", see this: http://support.microsoft.com/kb/246153/en-us if they don't show up there, either, the user has gone into the dumpster and "purged" email...your only option after that is to restore from backup... -- Susan Con...

how do i make a footer in Publisher
I am new to Publisher, but in the other Microsoft software I can show in the footer both the current page number and the total number of pages in the document. Can I do this in Publisher and how do I do it. Thanks Sharyn After you Insert, page numbers. View, Master page, type page # of XXX, (page 1 of 199) -- Mary Sauer http://msauer.mvps.org/ "Sharyn Bir" <Sharyn Bir@discussions.microsoft.com> wrote in message news:FF0833E5-35A6-4304-A551-6ABCE7346DF3@microsoft.com... >I am new to Publisher, but in the other Microsoft software I can show in the > footer both t...

Turning Off Error Reporting using API Functions and VB
We want to automatically turn off the error reporting options using Windows API functions for the following functions area Click on Start, Settings, Control Panel, System, the Advanced tab and Error Reporting (at the bottom of the screen), which launches the Error Reporting screen. Another way to get to that screen: Open My Computer, right-click on Properties, click on Advanced tab and Error Reporting. Any assistance would be welcome. It's not a program's call. It's the user's decision. --=20 -------------------------------------------------------------------------= --...

Complex functions
Hi All, Suppose you have a very complex and long function that is also subject to a condition, then you will/can have something like: =if(condition(complex function), complex function, other complex function) It can have more lines in the formula bar, so readability below 0 Kelvin. Is there a way to 'name' a function? =If(condition(myfunc = complex function), myfunc, other complex function) With kind regards, JP Yes you can put a formula into an Excel Name (the same as you can give a range an Excel Name. Very powerful it can be too. Do a Google fo...

CFileDialog how to set thumbnail view by default
Hi, I know that when I open a CFileDialog to open an image file, I can set by default Icon, Small Icon, List or Detail, but I can't set thumbnail view. Do you know a place to find an example? Or give me a clue? Do I have the good dialog to do that? Because in Windows, in the open file dialog, you can set thumbnail view. Thank you. -- Caroline The article at this link shows how: http://msdn.microsoft.com/msdnmag/issues/04/03/CQA/ If you need more details, let me know. Rail -- Recording Engineer/Software Developer Rail Jon Rogut Software http://www.railjon...

ol2003 asks for a password when I never set a password
My OS = XP Media Center Edition. Office Professional 2003 I backed up my OL with a personal folders file before reinstalling windows. After reinstaling windows I copied the saved personal folders file to my documents on the hard drive. Then in OL: NEW > OPEN > OUTLOOK DATA FILE, I attempted to open the personal folders file and I was prompted for a password. I never set a password to my personal folders file. Does anyone know how I can "import" my OL personal folders file? Programs on the web claim to be able to "find" my password but I'm distrusting ...

Page Breaks for Entire Work Book
I have a 110 Worksheet Workbook and I want to set the same page breaks for each page without manually doing every worksheet individually. Any help or macros out there? Thanks, Steve you always can use Tools > Macro > rocord new macro then do the job on one worksheet the stop the recording and sse the vba code. (this will help next time) But today, and in your case, I suggest ActiveWorkbook.Sheets.HPageBreaks.Add Before:=Rows(8) one line all the job done (before row 8 in this example) Thanks a million "abcd" wrote: > you always can use > Tools >...

Match Function
Hi, I have put together a spreadsheet to find codes, states, descriptions. It finds the data by dates. Columns are: Dates, Codes, States, Descriptions If I put in a date it matches the code, state and description. My problem is that if I have 2 dates that are the same it will only match the first date it can find. What kind of formula do I need so that it will output the second or third date data. Thanks for your help. If you need a copy of the spreadsheet please let me know. How many rows of data do you have? -- Biff Microsoft Excel MVP "Melanie" <Melanie@discussio...

Can't find link on MOney home page
I am using Microsoft Money 2002 Standard OEM Edition on Windows XP. The Help file states the following: ******************** Note This Help topic assumes you are connected to the Internet. On the Help menu, point to Money on the Web , and then click Microsoft Money Home Page . In the left pane, click Online Finance , and then click All Financial Institutions Online . ******************** But there is no such link in the left pane (for Online Finance) at http://www.microsoft.com/money/default.asp Please help. Michael Thal In microsoft.public.money, Michael_99 wrote: > >But there i...

Error Code 481
Hi, I have a file that loads a Userform when opened. This works fine on several computers but on others Excel fails and returns a message that Error Code 481 has occurred. This error refers to saving Excel as an HTML file yet I am not doing this. All machines are running the same version of Excel (2000). Any ideas please? Mickey All sorted, the machines that would not load are missing an MS Patch. I had to delete some gifs to make the userform run acorss all our machines. I believe that you can use bitmaps to overcome this issue, however bitmaps would make my workbook too large...

background picture in one page only
Hello once again, One of my colleague have ask me is it possible to put the "background in one page only" displaying his whole body picture, coz when he issued the command : Format/Sheet/Bacground/Insert, the entire sheet is covered with his multiple pictures. Thanks in advance. aboiy ...

If Function Function
okay. So I am trying to workout a formula to compute a commision earning. Basically, if X amount of new business is made, then X*Y (corresponding Commision rate percentage), but if new business =<X, then X*Y (Commision rate percentage that is true). Problem is, it's super confusing...anyone have any suggestions? See if this helps: http://mcgimpsey.com/excel/variablerate.html -- Biff Microsoft Excel MVP "aetejada" <aetejada@discussions.microsoft.com> wrote in message news:AA4E55F7-9435-4BB6-837A-416A59BB72A0@microsoft.com... > okay. So I am...

Outlook 2002 Change Password function
I want users to be able to change password from the Outlook Login Page, but it does noet seem to work. Outlook 2002 Sp1 and Windows Server 2003 (AD) and Exchange 2003 SP1 Important: Outlook client is not member of the domain... There are not many Microsoft Articles about this. Anyone? -- Regards, Menko den Ouden Netherlands Menko den Ouden schreef in deze nieuwsgroep op 23-6-2005 15:28: > I want users to be able to change password from the Outlook Login Page, but > it does noet seem to work. > > Outlook 2002 Sp1 and Windows Server 2003 (AD) and Exchange 2003 SP1 > ...

Creating a dynamic IF statement
I have data in two sheets. I want to create an IF statement in the second sheet that has the ability to scan the first sheet for a value. If it finds a match to a value in the second sheet, deposit the value into the corresponding cells of sheet two. My example: Sheet 1 User B 12/10 User C 12/15 Sheet 2 User A User B In this example, I will have the IF statement in column B of Sheet 2. I want the IF statement to scan column A in sheet 1 for matches to column A of sheet 2. If it finds a match, place the corresponding value in column B (in this case, it wou...

DateDiff function throwing error in Where clause
I have a set of queries that generate dates and want to use DateDiff to select those records with certain dates are greater than others. The following clause keeps giving me an incompatible data type error: WHERE DateDiff('d',[From date],[DatumStvoreni])>0 I have the exact expression in the SELECT clause and it show positive and negative integers just fine, but when I add this test, I get the error. There are no bad values in the dataset, I've looked, and when I export the DateDiff column to a temp table and run a query on that, it works fine. Only when I use t...