How do I display unicode characters in a web page using an isapi dll?

I have an ISAPI extension DLL that needs to output unicode data using
the WriteClient() function. The unicode characters are not displayed
properly. The text that is displayed in the web browser looks like
garbage even though viewing the source HTML shows Chinese characters
correctly.

DWORD WINAPI HttpExtensionProc(EXTENSION_CONTROL_BLOCK *pECB)
{

            DWORD dwLength;

            std::wstring html;

            html =3D L"<html><head><meta http-equiv=3D'content-type'
content=3D'text/html; charset=3Dutf-8' /></head><body><p>=C6=BB=B9=FB=BC=C6=
=CB=E3=BB=FA=B9=AB=CB=BE</p></
body></html>";

            dwLength =3D (DWORD) html.length();

            dwLength =3D dwLength * sizeof(wchar_t);


            int rc =3D pECB->WriteClient(pECB->ConnID, (LPVOID)
html.c_str(), &dwLength, HSE_IO_SYNC);


            return HSE_REQ_DONE_WITH_SESSION;
}


Any help would be greatly appreciated.
0
rwagner1 (3)
1/18/2008 7:10:55 PM
vc.mfc 33608 articles. 0 followers. Follow

4 Replies
513 Views

Similar Articles

[PageSpeed] 3

There are several encodings for Unicode, like UTF-8 and UTF-16.
std::wstring or Windows WCHAR are Unicode UTF-16. Unicode UTF-16 is fine for 
internal processing inside a Windows application.
But, in general, when you move Unicode text and strings over the web (also 
in HTML pages) outside an application boundaries, you usually use Unicode 
UTF-8.

In fact, when I read your source code, I found that you clearly declared 
that you do use Unicode UTF-8 in your HTML:

>            html = L"<html><head><meta http-equiv='content-type'
> content='text/html; charset=utf-8' /></head><body><p>ƻ���������˾</p></
> body></html>";

[see "charset=utf-8" --> it means that you are using UTF-8 as Unicode 
encoding for the HTML]

So, my guess is that you are declaring that you are going to use Unicode 
UTF-8, but instead you are actually using UTF-16.

I think you should convert your Unicode UTF-16 text (including Chinese 
"characters") into UTF-8 (e.g. using ::WideCharToMultiByte Win32 API, 
specifiying CP_UTF8 as CodePage ID:

http://msdn2.microsoft.com/en-us/library/ms776420(VS.85).aspx


Giovanni



"Ryan" <rwagner@iconect.com> ha scritto nel messaggio 
news:88430573-f36b-44e8-9ed6-6d5596c5f75f@j20g2000hsi.googlegroups.com...
I have an ISAPI extension DLL that needs to output unicode data using
the WriteClient() function. The unicode characters are not displayed
properly. The text that is displayed in the web browser looks like
garbage even though viewing the source HTML shows Chinese characters
correctly.

DWORD WINAPI HttpExtensionProc(EXTENSION_CONTROL_BLOCK *pECB)
{

            DWORD dwLength;

            std::wstring html;

            html = L"<html><head><meta http-equiv='content-type'
content='text/html; charset=utf-8' /></head><body><p>ƻ���������˾</p></
body></html>";

            dwLength = (DWORD) html.length();

            dwLength = dwLength * sizeof(wchar_t);


            int rc = pECB->WriteClient(pECB->ConnID, (LPVOID)
html.c_str(), &dwLength, HSE_IO_SYNC);


            return HSE_REQ_DONE_WITH_SESSION;
}


Any help would be greatly appreciated. 


0
1/18/2008 7:37:22 PM
thank you very much for your quick response. It was extremely helpfull
and using WideCharToMultiByte has solved our problems :-)


On Jan 18, 2:37=C2=A0pm, "Giovanni Dicanio" <giovanni.dica...@invalid.com>
wrote:
> There are several encodings for Unicode, like UTF-8 and UTF-16.
> std::wstring or Windows WCHAR are Unicode UTF-16. Unicode UTF-16 is fine f=
or
> internal processing inside a Windows application.
> But, in general, when you move Unicode text and strings over the web (also=

> in HTML pages) outside an application boundaries, you usually use Unicode
> UTF-8.
>
> In fact, when I read your source code, I found that you clearly declared
> that you do use Unicode UTF-8 in your HTML:
>
> > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0html =3D L"<html><head><meta ht=
tp-equiv=3D'content-type'
> > content=3D'text/html; charset=3Dutf-8' /></head><body><p>=C6=BB=EF=BF=BD=
=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=CB=BE</p></
> > body></html>";
>
> [see "charset=3Dutf-8" --> it means that you are using UTF-8 as Unicode
> encoding for the HTML]
>
> So, my guess is that you are declaring that you are going to use Unicode
> UTF-8, but instead you are actually using UTF-16.
>
> I think you should convert your Unicode UTF-16 text (including Chinese
> "characters") into UTF-8 (e.g. using ::WideCharToMultiByte Win32 API,
> specifiying CP_UTF8 as CodePage ID:
>
> http://msdn2.microsoft.com/en-us/library/ms776420(VS.85).aspx
>
> Giovanni
>
> "Ryan" <rwag...@iconect.com> ha scritto nel messaggionews:88430573-f36b-44=
e8-9ed6-6d5596c5f75f@j20g2000hsi.googlegroups.com...
> I have an ISAPI extension DLL that needs to output unicode data using
> the WriteClient() function. The unicode characters are not displayed
> properly. The text that is displayed in the web browser looks like
> garbage even though viewing the source HTML shows Chinese characters
> correctly.
>
> DWORD WINAPI HttpExtensionProc(EXTENSION_CONTROL_BLOCK *pECB)
> {
>
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 DWORD dwLength;
>
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 std::wstring html;
>
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 html =3D L"<html><head><meta htt=
p-equiv=3D'content-type'
> content=3D'text/html; charset=3Dutf-8' /></head><body><p>=C6=BB=EF=BF=BD=
=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=CB=BE</p></
> body></html>";
>
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 dwLength =3D (DWORD) html.length=
();
>
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 dwLength =3D dwLength * sizeof(w=
char_t);
>
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 int rc =3D pECB->WriteClient(pEC=
B->ConnID, (LPVOID)
> html.c_str(), &dwLength, HSE_IO_SYNC);
>
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 return HSE_REQ_DONE_WITH_SESSION=
;
>
> }
>
> Any help would be greatly appreciated.

0
rwagner1 (3)
1/18/2008 9:07:22 PM
Thank you very much for your help and quick response.
It has solved our issue. I can't thank you enought. :-)


On Jan 18, 2:37=C2=A0pm, "Giovanni Dicanio" <giovanni.dica...@invalid.com>
wrote:
> There are several encodings for Unicode, like UTF-8 and UTF-16.
> std::wstring or Windows WCHAR are Unicode UTF-16. Unicode UTF-16 is fine f=
or
> internal processing inside a Windows application.
> But, in general, when you move Unicode text and strings over the web (also=

> in HTML pages) outside an application boundaries, you usually use Unicode
> UTF-8.
>
> In fact, when I read your source code, I found that you clearly declared
> that you do use Unicode UTF-8 in your HTML:
>
> > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0html =3D L"<html><head><meta ht=
tp-equiv=3D'content-type'
> > content=3D'text/html; charset=3Dutf-8' /></head><body><p>=C6=BB=EF=BF=BD=
=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=CB=BE</p></
> > body></html>";
>
> [see "charset=3Dutf-8" --> it means that you are using UTF-8 as Unicode
> encoding for the HTML]
>
> So, my guess is that you are declaring that you are going to use Unicode
> UTF-8, but instead you are actually using UTF-16.
>
> I think you should convert your Unicode UTF-16 text (including Chinese
> "characters") into UTF-8 (e.g. using ::WideCharToMultiByte Win32 API,
> specifiying CP_UTF8 as CodePage ID:
>
> http://msdn2.microsoft.com/en-us/library/ms776420(VS.85).aspx
>
> Giovanni
>
> "Ryan" <rwag...@iconect.com> ha scritto nel messaggionews:88430573-f36b-44=
e8-9ed6-6d5596c5f75f@j20g2000hsi.googlegroups.com...
> I have an ISAPI extension DLL that needs to output unicode data using
> the WriteClient() function. The unicode characters are not displayed
> properly. The text that is displayed in the web browser looks like
> garbage even though viewing the source HTML shows Chinese characters
> correctly.
>
> DWORD WINAPI HttpExtensionProc(EXTENSION_CONTROL_BLOCK *pECB)
> {
>
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 DWORD dwLength;
>
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 std::wstring html;
>
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 html =3D L"<html><head><meta htt=
p-equiv=3D'content-type'
> content=3D'text/html; charset=3Dutf-8' /></head><body><p>=C6=BB=EF=BF=BD=
=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=CB=BE</p></
> body></html>";
>
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 dwLength =3D (DWORD) html.length=
();
>
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 dwLength =3D dwLength * sizeof(w=
char_t);
>
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 int rc =3D pECB->WriteClient(pEC=
B->ConnID, (LPVOID)
> html.c_str(), &dwLength, HSE_IO_SYNC);
>
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 return HSE_REQ_DONE_WITH_SESSION=
;
>
> }
>
> Any help would be greatly appreciated.

0
rwagner1 (3)
1/18/2008 9:15:19 PM
"Ryan" <rwagner@iconect.com> ha scritto nel messaggio 
news:8260118d-dfa8-4593-a9b5-5d0614a389b7@v29g2000hsf.googlegroups.com...
> Thank you very much for your help and quick response.
> It has solved our issue. I can't thank you enought. :-)

You're very welcome :)

G



0
1/19/2008 9:43:30 AM
Reply:

Similar Artilces:

Display As A Top Windows
Dear helper, How to write code to display a window on top of every window but not top most? I mean the equivalent to VB Code: formName.ZOrder Thanks you. > How to write code to display a window on top of every window but not > top most? I mean the equivalent to VB Code: formName.ZOrder... SetWindowPos(wndNoTopMost, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE); moves window's to z-order above all non-top-most and below top-most... May need to add other SWP_* flag check MSDN on the SetWindowPos() page... SetWindowPos. I'm not sure how "on top of every window but no...

Radar (aka spider web looking) Charts
I have radar charts in excel which I link to a publisher file. I run a macro from an access database to feed the excel file and update it on a regular basis. I am having a very frustrating problem where my radar charts are being re-sized in excel when I update my excel file or when I update the links in publisher. Any suggestions? Thanks, Denise ...

Displaying a Word doc in form
I have a form that will be used to enter information submitted to me on Word files (comment sheets on procedure reviews). The files do not lend themselves to being converted to text files and imported into an access table. I would like to be able to click a button, choose the *.doc file from the directory, select the file and have it display in a field on this data entry form (linked OLE field?). I could then cut text (paragraphs) from Word and paste it into a memo field on the form. I can program the button to find the file I want, but that's where I am stuck. The Ac...

Using Outlook 2007 and Gmail Apps Premier
My wife and I are Realtors and occasionally when one of us is working from home and the other one is in the office, we email attachments to eachother. They show has being sent by "me" in our gmail apps premier accounts. These messages go to the All Mail folder and not the Inbox. We are now using apps sync and Outlook 2007 with a single domain name. When we send these emails they show up in the sent mail folders of Outlook but not in the Inbox. They are in the All mail folder in gmail. This is a bit confusing. Is there away to send them to the Inbox instead of All...

Restore last session or go to home page
Is there a way to disable the 'your last browsing session closed unexpectedly' message box? Every time I click to open IE8 after starting the computer from a shut down I receive this message box. Thanks. --- Leonard Grey Errare humanum est Kitti Ritter wrote: > Is there a way to disable the 'your last browsing session closed > unexpectedly' message box? Every time I click to open IE8 after starting the > computer from a shut down I receive this message box. Thanks. > 1. How do you normally shut down Internet Explorer? 2. Is Internet Expl...

Using money on two computers ?
I wish to organise my personal accounts from both home and work. Can work done on money be saved and brought home to be continued on ? Are there any synchronisation features that money has ?? TIA Simon In microsoft.public.money, Simon77 wrote: >I wish to organise my personal accounts from both home and work. Can work >done on money be saved and brought home to be continued on ? > >Are there any synchronisation features that money has ?? > Do Help->MicrosoftMoneyHelp and enter "synchronize" into the Ask Money box. To the extent that this does not answer your...

Cannot use RPC over HTTPS with Cox cable
I have two users who were on DSL for over a year with zero problems. They switched to Cox cable and now cannot connect to Exchange (RPC over HTTP). No settings have changed. They can switch the connection back to DSL and connect in seconds. Switch to cable and never connect. All the tests I can think of pass. They can connect to the /rpc share on the Exchange server using IE. It appears that Cox is blocking them, but I don't see how. Isn't the rpc over https encrypted? Could Cox even tell they were connecting to Exchange? All other users using various other ISP's work perfe...

Financial planning using Money?
My wife and I are new to online banking and are considering getting Money 2005 when it comes out in a couple weeks. I have 2 questions: 1) Does the standard version of Money have long-term (i.e., lifetime) financial planning capabilities, or do you have to upgrade to Deluxe or even Premium for that? 2) Can anyone who has used Money's financial planning functionalities comment on how useful/efficient they found them to be? Thanks a lot! Tim With respect to your second question concerning the usefulness of the Lifetime Planner in Money 2004, my own assessment is that the tool is gene...

some problem using schema
Hello there I change some of my procedures as schema It works fine. but when i saw the definition of these procedures in sys.sql_modules the create statement still goes to DBO. why? Roy Goldhammer (royg@yahoo.com) writes: > I change some of my procedures as schema With ALTER SCHEMA? > but when i saw the definition of these procedures in sys.sql_modules the > create statement still goes to DBO. You would need to use ALTER PROCEDURE to fix that part, if it is an issue for you. The same thing if you rename a procedure - the stored text is left unc...

Booklet used to print correctly
My company just updated to MS Office 2007. I have a small booklet in Publisher that used to print perfectly, now pages are upside down. I’ve read previous posts, even tried smaller paper. Ahhh, please help… ...

customized field not displaying as a column choice in SmartList
We were sent the package file and sql scripts to add a customized field (Budget ID) to the Purchasing Item Detail Entry form by our VAR. My question is - how do you make that customized field visable in SmartList? The users requested this field so that they would be able to search PO's by the Budget ID. Of course, I assigned the security rights to the modified form, but that does not make it display as a column available to be used in a search in SmartList. Any help with this will be greatly appreciated! Patti, Unless adding this field to a built-in SmartList was part of the ...

Manual DLL Registration
Hello, I have a problem manually registering my DLL. I have created an MFC DLL and when I try to run 'regsvr32' I get a message saying: "exdll.dll was loaded, but the DllRegisterServer entry point was not found. This file can not be registered". I CAN export a function from my exdll.dll and use it by a non-VC++ app. But, when I try to run my VC++ 'msvg.dll' app that imports a function from 'exdll.dll', I get MessageBox messages that I inserted into my 'exdll.dll' (and then removed) several weeks ago. Where are those MessageBox messages c...

outllib.dll is causing error
When I try to open Outlook it gives a error "This program performed an illigal operation and will be closed by windows. if i see in detail it says outllib.dll is cuasing aan error, if problem persist please contact your vendor" . i tried deleting this file and copied from the file from cd, still the same. then i tried re-installing office again same problem, finally i tried removing the office then re-installed windows 98 and then installed office, still the same problem!!. What could be the problem, please give me the solution. Thanks Mohammad Haneef Imtac llc Mohammadh@imt...

Removing everything after a character
Is there a way to remove everything in a field after a certain character using excel or anything else. It's from a product datafeed that has this format: Product name #85423 Product Name2 #84216 Product Name3 #51354 etc.. I want to get rid of everything after # TIA, Javi :) ------------------------------------------------ ~~ Message posted from http://www.ExcelTip.com/ ~~View and post usenet messages directly from http://www.ExcelForum.com/ Hi Javi You could try the Excel function Text to Columns (in the Data menu) and split with # as delimiter. -- HTH. Best wishes Harald Follo...

Excel Image not displayed when the physical file is N/A
Hello there, I'm having a problem on images that's generated from excel. I'm using the url method to generate the excel file and I'm aware that the images are stored in a physical location and the images won't be able to be displayed if the physical file is not available. I'm able to display the images out when the excel report is generated; however, when we save it as the default xls extension file, and open it in another location, the images are not displayed, as only the physical file path is being stored in the excel file. I've tested it on a c...

Full Screen Reading goes wrong on multi display environment
Hello, I am using 2 displays on my computer - primary is 1440x900 and secondary is 1024x1280. When I open Word 2007 document on the secondary display and switch to Full Screen Reading, it does not use the whole display area but rectangle 1024x900, so the bottom third of the display is not used. Is there any way to make Word use the whole display? Thank you, Libor ---------------- This post is a suggestion for Microsoft, and Microsoft responds to the suggestions with the most votes. To vote for this suggestion, click the "I Agree" button in the message pane. If yo...

Problem of passing MFC pointers between DLL and EXE
There is a problem when pointers to MFC class objects are passed between an application and a Dll. Does any have a solution ? > There is a problem when pointers to MFC class objects are passed > between an application and a Dll. What problem is that? It works fine. Can you be more specific? ---- Ajay <charfeddine_ahmed@yahoo.fr> wrote in message news:1152692060.794841.20610@p79g2000cwp.googlegroups.com... > There is a problem when pointers to MFC class objects are passed > between an application and a Dll. > Does any have a solution ? This is usually caused by st...

Paging and cache
When a GridView gets information back from the server and it is doing paging (or anytime I suppose). Where is it putting the data while it renders the data. If I do a DataBind or use an SQLDataSource and the data comes back (say 10,000 rows) and you are having the GridView handle the paging. Where does it put the data in the interim? Does it cache it on the Client side somewhere? Thanks, Tom tshad wrote: > When a GridView gets information back from the server and it is doing paging > (or anytime I suppose). > > Where is it putting the data while i...

Unicode (UTF-8) text conversion
Hi , when i try to open a none xls file useing excel 2000, the text import wizard opens. on the drop down menu for file origin i see windows, MAC and DOS file origin. how do i add to files origin drop down list. i am looking for "6501 Unicode (UTF-8). office 2000 is full installed with all tools, converters and .... latest Service pack. Thanks Eddie ...

Sum using probably a VLOOKUP
Hi, I'm looking for a way to make a sum of values in a column depending on the respective value of another column. Example: A1 = 1 A2 = 2 A3 = 1 B1 = 100 B2 = 300 B3 = 125 I'd like to be able to make a sum of B values when A values = 1. In that case, my sum would be 225. Thanks, Alex One way: =SUMIF(A:A,1,B:B) In article <OQ#LYB6hEHA.356@tk2msftngp13.phx.gbl>, "Alex Langlois" <alex.nospam@nospam.net> wrote: > Hi, > I'm looking for a way to make a sum of values in a column depending on > the respective value of another column. ...

Using Form view in sharepoint
Hi, I am attempting to use a form view in SharePoint designer and connect this to an Access Database, which works fine. However, when I view this in Sharepoint I am able to add a record but I am not able to edit or delete records as I get an error message (saying "An unexpected error has occurred) and the record does not change in the database. Does anyone know why this might be happening and more importantly how to resolve it? Many thanks in advance, Emma ...

Send All emails in Outbox and Quit using VBA
Hi, I have MS Access creating emails objects in Outlook using a macro. I want to send them all and close outlook after. 1-Open Outlook 2-Send all emails in the outbox folder 3-Close Outlook How can I achieve it using VBA? Using command buttons does not seem to work since my Outlook is in French, I'm using Outlook 2003 SP3. Thank You Stephane You're not trying to use command button captions, are you? Use the IDs instead, with the FindControl method. They're language-neutral. The ID for Send All should be 5577. -- Sue Mosher, Outlook MVP Author o...

page numbering #5
In excel 2003, I want to number pages that will reflect pages included from another source. example, excel doc has 28 pages, other doucments to be icluded are 10, want the excel to be paged 1 - 38. HELP! You could try printing in stages, first one source, then another. In that way, you can control the starting page number of each individual source in XL by: <File> <PageSetUp> <Page> tab, At the bottom, change the "Auto" in the "FirstPageNumber" box to whatever page number that you wish to start with. -- HTH, RD -------------------------------------...

Hiding Personal.xls using Novell Groupwise integration
Hi All, I use Excel in Novell Groupwise integration. Trying to hide and save Personal.xls the GW Save macro stops with runtime error 91 at ActiveWorkbook.Save line, the GW Close macro at If Application.ActiveWindow.WindowNumber = 1 Then line. Obviously, the integration macros are not prepared for saving a hidden workbook. Has anybody heard that this bug has been fixed? Stefi I'm not sure how much else will break, but maybe you could code around it: If Application.ActiveWindow Is Nothing Then 'do nothing Else If Application.ActiveWindow.WindowNumber = 1 T...

I have published a worksheet to web but have one problem someone help please :(
Hello I published a worksheet to the web. The address is http://www.inforamp.com/~kidd/html/pmcshop1.htm The problem is I want to get rid of the scroll bars and the top men bar so ONLY the worksheet is present. Can someone tell me what I did wrong You help is greatly appricated Pau -- kid ----------------------------------------------------------------------- kidd's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=1579 View this thread: http://www.excelforum.com/showthread.php?threadid=27378 All I see is this :- To use this Web page interactively, you must...