Visual C++ :: Convert Unicode (UTF-16) Functions To Ansi (UTF-8)

Nov 20, 2012

Working in Win32 console app (VS 2010) I have been trying to convert several Unicode (UTF-16) C++ functions to Ansi C (UTF-8). The test app includes two tokenizer classes, each of which work perfectly well in their respective environments, CTokA and CTokW (UTF-8 and UTF-16).

A problem arises when I attempt to run the UTF-8 functions when the Character Set properties is set to 'Use Unicode Character Set' in that std::string manipulations do not perform as expected, e.g.,

printf("start
");

gets reproduced as

printf("start
");══════════ ²²²²

Attempting to null terminate the string where it is supposed to end simply results in a space in that position and the garbage end persists, e.g.,

printf("sta t
");══════════ ²²²²

Code:
sline[11] = 0x0000;

If I attempt to change the Character Set property to 'Use Multibyte Character Set' or 'Not Set', the app will not compile and hundreds of errors occur. Of course, I can eliminate all of the UTF-16 code, but it strikes me that it should not be necessary. Perhaps if M$ made everything UTF-16 without all of the necessary decorations like 'L' and '_T(', life would be much simpler. Unfortunately, I have a very extensive UTF-8 app under 10 years of development that works quite well, but my UTF-16 (Unicode) conversion doesnt work as well because of the mixing of pointers (I think), so I have had to revert much of the code back to UTF-8. (All of which has nothing to do with my question but is simply psychotheraputic for me to ventilate on.)

My question is this: Can UTF-8 and UTF-16 code coexist in a single Win32 console app?

View 6 Replies


ADVERTISEMENT

Visual C++ :: How To Convert UTF-8 String To Unicode String

Jun 15, 2013

I am using Visual Studio 2008. I just wonder if there are any library function in Windows SDK or MFC, or from third-parties, that can convert a UTF-8 string into Windows Unicode string(used in CString object).

Can MultiByteToWideChar or ATL String conversion macro like A2W to the conversion?

View 1 Replies View Related

Visual C++ :: Getting Unicode From API DLL Using Non-Unicode Program

Aug 29, 2013

I have some code that was compiled without Unicode turned on in the Preprocessor Definitions. I need to access an API that had Unicode turned on in the Preprocessor Definitions (I believe that it is on by default for DLL's) .

I need to call a function in the DLL that requires a structure like:

struct READERINFO {
TCHAR serial[32];
TCHAR altSerial[32];
TCHAR name[32];
TCHAR fccId[48];
TCHAR hwVersion[16];
int swVerMajor;
int swVerMinor;
char devBuild;
};

It returns some information in the structure some of it is Unicode based however the program that is calling it is not Unicode. The preprocessors are not turned on because if they were there would be a lot of things to change in this code. The code is old code that I inherited and now I must interface to some new devices.

I declare my structure as :

READERINFO info; Then I call the function in the DLL which looks like: ApiGetReaderInfo(hAPI, &info, sizeof(into));

Which is defined as:
ApiGetReaderInfo(HANDLE hApi,
Struct READERINFO * ri,
DWORD riSize);

Parameters:

hApiHandle to valid Api object instance
riPointer to the READERINFO structure.
riSizeSize of ri structure in bytes. Usually: sizeof(struct READERINFO).

When I call it from my program that does not have UNICODE defined in the Pre-Processors I get :

Characters like : ÌÌÌÌÌ in the TCHAR fields and invalid numbers in the integer fields.
int ModuleVersion(HANDLE hApi) {
struct READERINFO info;
ApiGetReaderInfo(hApi, &info, sizeof(info));

[Code] ....

When I call it from my program that has some sample code just for this and has the UNICODE defined in the Preprocessors it works just fine. how I can call this from my old code and get the correct information. I have already tried to do the follow without success:

int ModuleVersion(HANDLE hApi) {
#define UNICODE
struct READERINFO info;
#undef UNICODE
ApiGetReaderInfo(hApi, &info, sizeof(info));

[Code] .....

View 4 Replies View Related

C++ :: Unicode And Win32 API Functions

Aug 11, 2014

You told me that it's better to use UNICODE all the time.

What if the Win32 Api function doesn't have a UNICODE version.

For example CryptProtectData() takes a BYTE (DATA_BLOB *) which is an unsigned char?

[Code] ......

View 7 Replies View Related

Visual C++ :: Whether 0xFFFF Is A Valid Unicode Character

Dec 22, 2013

I just wonder whether 0xFFFF is a valid Unicode character.

When I using the following code:

CStringW strTempW;
CString strTemp1;
INT_PTR nLen;
strTempW.Format(L"%c", 0xFFFF);
nLen = strTempW.GetLength();
strTemp1 += strTempW;
nLen = strTemp1.GetLength();

After executing the first codeline strTempW.Format(L"%c", 0xFFFF), I will get strTempW of length 1, but cannot see it first character in Visual Studio watch window.

After executing the codelilne strTemp1 += strTempW, I will get strTemp1 of length 0.

Whether 0xFFFF is taken as a valid Unicode or not?

View 1 Replies View Related

Visual C++ :: Saving Unicode Strings To Txt Files

Jan 20, 2014

In my project , we need to create an Array of Unicode Strings . The Array will contain 5000 Strings.

I need to write those strings to a text file which can be opened or edited with NotePad.

Normal _tfopen and fwrite are not able to create notepad compatible .txt file .. I mean the file I created is not readable with Notepad though file open mode is "w+t"

How can I save my unicode strings to a text file

View 6 Replies View Related

Visual C++ :: Hex Values From Stream - Unicode Settings?

Feb 18, 2014

I am using VC++ 2005, Multibyte char set. I am getting hex values from stream and i have to show it in respective language.

in below example

char mt[] = { 0x0C, 0x85, 0x0C, 0x86, 0x0C, 0x87,0x0C, 0x88,0x0C, 0x89, 0x0C, 0x8A,0x0C, 0x8B,
0x0c, 0x85 , 0x0c , 0x86 , 0x0c , 0x87 , 0x0c , 0x88 , 0x0c , 0x89 , 0x0c , 0x8a , 0x0c , 0x8b , 0x00 , 0x20,
0x0c, 0x8e , 0x0c , 0x8f , 0x0c , 0x90 , 0x0c , 0x92 , 0x0c , 0x93 , 0x0c , 0x94 , 0x00 , 0x20 , 0x0c , 0x95,
0x0c, 0x96 , 0x0c , 0x97 , 0x0c , 0x98 , 0x0c , 0x99 , 0x00 , 0x20 , 0x0c , 0x9a , 0x0c , 0x9b , 0x0c , 0x9c,
0x0c, 0x9d , 0x0c , 0x9e , 0x00 , 0x20 , 0x0c , 0x9f , 0x0c , 0xa0 , 0x0c , 0xa1 , 0x0c , 0xa2 , 0x0c , 0xa3,
0x00, 0x20 , 0x0c , 0xa4 , 0x0c , 0xa5 , 0x0c , 0xa6 , 0x0c , 0xa7 , 0x0c , 0xa8 , 0x00 , 0x20 , 0x0c , 0xaa,
0x0c, 0xab , 0x0c , 0xac , 0x0c , 0xad , 0x0c , 0xae , 0x00 , 0x20 , 0x0c , 0xaf , 0x0c , 0xb0 , 0x0c , 0xb2,
0x0c, 0xb5 , 0x0c , 0xb6};

How can i convert the mt string to below string?

"ಅಆಇಈಉಊಋ ಎಏಐಒಓಔ ಕಖಗಘಙ ಚಛಜಝಞ ಟಠಡಢಣ ತಥದಧನ ಪಫಬಭಮ ಯರಲವಶ"

To cross check the mt array, If you place the above string to the below link you get mt array [URL] ....

Cant i do it in "Multibyte char set" settings? or should i use Unicode settings.

View 3 Replies View Related

Visual C++ :: Transferring Unicode String From One Program To Another With UTF-8 Encoding?

Mar 20, 2015

I'm transferring a unicode string from one program to another with UTF-8 encoding.

Program that is sending:

Code:
// Convert path
std::wstring_convert<std::codecvt_utf8<wchar_t>> utf8_converter;
CString arg = L" /PATH="" + CString(utf8_converter.to_bytes(path).c_str()) + L""";

Program that is retrieving:

Code:
// Restore original path
std::wstring_convert<std::codecvt_utf8<wchar_t>> utf8_converter;
std::wstring path = utf8_converter.from_bytes( argument );

Everything has worked fine, until running on a Japanese edition of Windows.

The "byte path" then looks something like "C:¥Users¥d✝?✝a ,?¥AppData¥Local¥Temp¥file.txt".

"from_bytes()" will throw an std::range_error exception "bad conversion".

The program works fine when working with Japenese writing inside paths in the English edition.

What could be causing the "bad conversion"?

View 10 Replies View Related

C :: Using A Printer In ANSI

Oct 29, 2014

Is there a way to access the printer in ANSI C ?

I have written a program and would like to print out the data (held in a file).

All I can find is that there seems to be no way to send a file to the printer and stay within the confines of ANSI C.

I am restricting my use to ANSI specs for the portability. Do I have any options?

View 1 Replies View Related

C :: Using Functions To Convert Change Into Dollars

Jul 20, 2013

I know this is pretty basic script the problem I have is that I have to use functions for each calculation. The problem I face is that when the user types in the amount of quarters, dimes, nickels, and pennies when a function tries to add them together it displays a huge number instead of the right number.

Here is my code:

#include <stdio.h>
void insert_money(int p, int n, int d, int q, int total){
printf("How much of each coin do you want to insert:
");
printf("Quarters: ");
scanf("%d", &q);

[Code] ....

View 7 Replies View Related

C :: Save Output From Ansi Escape Sequence To Variable

Apr 13, 2013

I'm trying to get the current position of the cursor in the terminal window. I know that the ansi escape sequence "33[6n" will display the current x and y location of the cursor. But what I can't figure out is how to store the x and y locations into their respective integer variables.

This is what I've done so far:

Code:
#include <stdio.h>
int main(void) {
int line, column;
char cursor_curr_pos[9];
char escape_sequence[] = "33[6n"; //outputs x and y location of cursor e.g. ^[[18;1R
snprintf(cursor_curr_pos, 9, "%s", escape_sequence); //save output to string
sscanf(cursor_curr_pos, "^[[%d;%dR", &line, &column); //only read numbers from string
}

View 2 Replies View Related

C/C++ :: Convert The Functions To Deal With Integers Instead Of Chars

Mar 29, 2014

current functions are:

char *createEnvironment(int width, int height, int numWoodChips);
void printEvrionment(char *environment, int width, int height);

need to be:

int* createEnvironment(int width, int height, int numWoodChips);
void printEvrionment(int* environment, int width, int height);

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>

[Code]....

View 1 Replies View Related

C :: ANSI Program To Print Out Each Command Line Argument On Separate Line Using For Loop

Mar 5, 2013

I need to write a ANSI program to print out each command line argument on a separate line using a for-loop. also it need to print the name of the executable .so far I have

Code:

#include <stdio.h>
int main(int argc, char **argv) {
int i;
printf("")

[code]....

View 1 Replies View Related

Visual C++ :: How To Convert IP To Hex

Sep 27, 2012

I don`t known how to convert IP to hex .

In this link [URL] .... . I see hex IP : Hex IP 0x462a1779

I want to convert IP "70.42.23.121" to "0x462a1779"

Code:
#include <winsock.h>
#include <windows.h>
#include <stdio.h>
UINT32 ip_to_hex(UINT32 ip_add) {
UINT32 ip_hex;
//code convert ip to hex
return ip_hex;

[Code[ ....

And this is result : 7b 1e 80 and a , not 0a

Further i think we must separate each octect by a (dot) . , Then convert decimal to hex.

View 6 Replies View Related

Visual C++ :: Convert HSB Color To RGB And RGB To HSB?

Jun 11, 2014

I am trying to make this code working and to remake it to work also for RGB to HSB? This code is for C and I need to make it working in Visual Studio C++ .

Code:
// mask1.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <stdio.h>
#include <math.h>
typedef struct RGB_t { unsigned char red, green, blue; } RGB;
typedef struct HSB_t { float hue, saturation, brightness; } HSB;

[code]....

Error I got is error C3861: 'fmaxf': identifier not found

What file or namespace should I include. Do I need to add some library into linker?

View 14 Replies View Related

Visual C++ :: How To Convert DLL Project To MFC Extension

Oct 5, 2012

If I drop this regular dll project and create a new MFC extension dll project, it will involve too much work. I wonder if there is relatively easier way to convert an existing regular dll project to a MFC extension dll project? BTW, how can I tell a MFC extension dll project from a regular dll project?

View 1 Replies View Related

Visual C++ :: Convert Money To Denominations?

Sep 26, 2013

Problem:Given any amount of money expressed in dollars, and cents, this program computes the number of 100 , 50, 20, 10, 5 and 1 dollar bills and number of quarters, dimes, nickels, and pennies to be returned, returning how many of each denomination are included.

I figured out how to program it correctly for the most part except I cannot figure out how to handle large numbers, such as 14.49999999999999999999999999999999.When converting that number to int it returns it as 14.50. How to handle converting doubles, similar to the one above, to an integer correctly?

This is the code that my teacher did not want, since I handled the input as a string:

Code:
#include <iostream>
#include <string>
#include<iomanip>
#include<windows.h>
using namespace std;
int main(){
const int hundredsConst=10000, fiftiesConst=5000, twentiesConst=2000, tensConst=1000;

[code].....

View 3 Replies View Related

Visual C++ :: Convert MM/DD/YY Hh:mm Stream To Integer?

Nov 7, 2012

I'm trying to read in two instances of date and time (from user input) into a string value (MM/DD/YY hh:mm).
I need to be able to calculate the difference between the two in order to return how much time has elapsed from the first date/time to the second date/time.

What would be the most efficient way to go about obtaining said results?

I was thinking I need to convert each year, month, day, hour, and minutes into its own integer variable, after researching immensely online I'm still not sure how to convert from a string of characters to an integer.

View 10 Replies View Related

Visual C++ :: Convert C# Module Into Unmanaged DLL?

Oct 21, 2014

I am in need to convert some C# code into C++ equivalences. But I don't want to spend the efforts to do so. Is there an handy way to convert an existing code of C# into C++ (unmanaged code)?

View 7 Replies View Related

Visual C++ :: How To Convert MFC Dependent Source To Non-MFC

Feb 25, 2013

IDE = Visual Studio 2008 Express

I am a novice programmer(still...) , and I am trying to build the Code Project project located at this address:

[URL] .....

The project page is titled " Remote Control PCs ".

I would like to use this program plus I wanted to practice programming using the code base. However, I don't have MFC so I thought I would just convert it to non-MFC.

For example, It seems to me that any class inherited from MFC would need to be reimplemented. I think I also need to reimplement any code that uses "stdafx.h"

I built a custom project out of the zlib library and compiled it as a Windows library with the /MT settings. Both 32 and 64 bit library files, in Release and Debug mode, are included. The ZLIB.H and ZCONF.H files are also included. For examples of single-threaded usage, see the CZLib class. For examples of multi-threaded usage, see the classes CDriveMultiThreadedCompression, CMultiThreadedCompression, and CZLib.

1)How should I go about compiling this zlib custom project?

2)Where does the /MT option go ?

3)How do I use the output ( zlib.lib - I guess)?

View 9 Replies View Related

C++ :: How To Use Unicode Characters

Jan 25, 2015

I'm trying to have a button marked by the sqrt sign, '√'.

I wrote below code and typed that sign by holding down "alt" and typing 251 using numpad. But result is the question mark instead of sqrt mark!

My machine is Windows 7 x86 and IDE is visual studio 2012.

#include <GUI.h>
using namespace Graph_lib;
//---------------------------------
class Test : public Window {
public:
Test(Point, int, int, const string&);

[Code] .....

View 3 Replies View Related

Visual C++ :: Mq4 Platform Calling Functions From DLL

Feb 10, 2013

I have Mq4 platform calling functions from DLL some how it doesnt make any differents when I make the call....

// DLL Code

#define WIN32_LEAN_AND_MEAN
#define MT4_EXPFUNC __declspec(dllexport)
using namespace std;
std::string My_String;
#define stringify(mymonths ) # mymonths

[Code] ....

I call this function

bool counts = StartRulls(bars);
Print("counts =",counts );
2013.02.09 23:03:242010.03.31 16:37 My_Mq4.mq4 EURCAD,M5: counts = 1

My result always stays 1

View 4 Replies View Related

Visual C++ :: Functions Were Discarded On Build Of DLL With 8.0

Dec 9, 2012

I want to build a dll library with visual c++ 8.0 and got an "unresolved symbol" linker error message when trying to use the library with an application. So I checked the dll library with dependency walker for the exported functions, the needed functions were missing in the library.

I then dumped the corresponding object file with dumpbin.exe, the function was declared as public, like the other exported functions. On the next step, I set the verbose switch for link.exe.

The verbose log told me, that the function was discarded on the linker run. What can lead to that behaviour of the visual c++ linker ?

View 3 Replies View Related

Visual C++ :: Can Two Functions In Same DLL Be Called By Two Threads?

Aug 27, 2014

I write a DLL MyDLL.dll with Visual C++ 2008, as follows:

(1)MFC static linked
(2)Using multi-thread runtime library.

In the DLL, this is a global data m_Data shared by two export functions, as follows:

ULONGLONG WINAPI MyFun1(LPVOID *lpCallbackFun1) {
...
Write m_Data(using Critical section to protect)

[Code]....

Although MyThread1 and MyThread2 using critical section to protect the shared data m_Data, I will still suspend MyThread1 before accessing the shared data, to prevent any possible conflicts.

The problem is:

(1)When the first invoke of MyFun2, everything is OK, and the return value of MyFun2(that is nResult2) is 1 , which is expected.

(2)When the second, third and fourth invoke of MyFun2, the operations in MyFun2 are executed successfully, but the return value of MyFun2(that is nResult2) is a random value instead of the expected value 1. I try to using Debug to trace into MyFun2, and confirm that the last return statement is just return a value of 1, but the invoker will receive a random value instead of 1 when inspecting nResult2.

(3)After the fourth invoke of MyFun2 and return back to the next statement follow MyFun2, I will always get a "buffer overrun detected" error, whatever the next statement is.

I think this looks like a stack corruption, so try to make some tests:

1.I confirm the /GS (Stack security check) feature in the compiler is ON.

2.If MyFun2 is invoked after MyFun1 in MyThread1 is completed, then everything will be OK.

3.In debug mode, the codeline in MyFun2 that reads the shared data m_Data will not cause any errors or exceptions. Neither will the codeline in MyFun1 that writes the shared Data.

View 4 Replies View Related

Visual C++ :: Const Member Functions

Jan 24, 2013

Code:
class Editor {
// c'tors etc
Gtk::EventBox canvas_event_box;
void functionA();
void functionB() const;

[Code] ....

When I try to compile functionB in Visual C++ it gives me this error:-

glibmm/refptr.h(199) : error C2440: 'initializing' : cannot convert from 'const Gdk::Window *' to 'Gdk::Window *'
Conversion loses qualifiers

And this is the code from glibmm/refptr.h

Code:
// The templated ctor allows copy construction from any object that's castable. Thus, it does downcasts:
// base_ref = derived_ref
template <class T_CppObject>
template <class T_CastFrom>

[Code] .....

I don't actually want to change anything in the member variable canvas_event_box. I just want to be able to call one of its functions from my 'const' member function. Is there any syntax I can use to tell VC++ that I'm not actually changing the variable - just using it.

View 11 Replies View Related

Visual C++ :: How To Convert PNG Image Into Byte Array

Mar 12, 2013

I m loading a png image by using the ATLImage library.

CImage Image;
Image.Load (L"D:ImagesPNG_ImagesImage7.png");

how to retrieve the byte array value of this png image. I tried retrieving it as

byte *png = reinterpret_cast<BYTE *>(Image.GetBits());

but when i access the data , der is a loss of data while converting it in the above manner.

I found a snippet in net for decoding the raw data . but der is a line is the code which is unknown to me. The code is as follows :

CImage atlImage;
HMODULE hMod = GetModuleHandle(NULL);
atlImage.Load(bstr);
void* pPixel = atlImage.GetBits();
intpitch = atlImage.GetPitch();
intdepth = atlImage.GetBPP();

[Code] ....

How do I get the byte * value form the png image loaded?

View 3 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved