|
Can anyone tell whether can we convert UTF-8 text file to unicode text file programmatically.
|
|
|
|
|
Why not?
Read in each line and use MultiByteToWideChar on it.
Write out the converted strings to another file.
|
|
|
|
|
Any examplecode how to use that MultiByteToWideChar(...) ?
_____________________________
...and justice for all
APe
|
|
|
|
|
MultiByteToWideChar(
CP_UTF8, // code page - UTF-8 since you know that is your source's code page
MB_PRECOMPOSED, // character-type options
lpMultiByteStr, // pointer to your UTF-8 string read from file
cbMultiByte, // number of bytes in string - length of line read from file
lpWideCharStr, // this is where the data will be converted into the wide-character buffer
cchWideChar // size of the wide character buffer
);
I like to make the wide character buffer at least 1.5 times larger than the source string in case you get several multi-bute characters in your input stream.
|
|
|
|
|
hi ,
i'm using coledatetime class for storing time value.
COleDateTime stTime(/*some time value*/);
CString s=stTime.Format(VAR_TIMEVALUEONLY);
if time value is 12:00:00 AM then value of s is blank.
other wise it is giving proper time values.
what could be problem.
thanks,
prasad
|
|
|
|
|
prasad_som wrote:
what could be problem
It is not actually a problem. It is a feature , as documented in the MSDN[^].
Why not specifically specify the time format your require?
e.g. stTime.Format(_T("%H:%M%:S")); <font color=green>// will give '23:16:23' for example</font>
I Dream of Absolute Zero
|
|
|
|
|
By chance, see if this makes a difference:
CString s = stTime.Format((DWORD) VAR_TIMEVALUEONLY);
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
i want to create a help file just like windows help for my software, how do i proceed. any examples?
|
|
|
|
|
You'll need to use the Windows Help Compiler (hcw.exe) for this. You'll need to create a Help Project (.hpj) file, which provides information to the help compiler. The MakeHm utility will take the #define statements from the project's resource.h file and make coressponding IDs in a .hm file. This is done by prefacing each of the IDs with an "H".
Search MSDN for these various keywords and the rest will fall into place.
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
I've tried using critical sections and interlocked functions (implemented as spin locks) in my VC++ 6 projects, believing them to be the more efficient means of providing thread synchronization. But I wonder if there's anything faster / more efficient...
Any ideas?
Thanks!
Nico
|
|
|
|
|
a critical section is an efficient solution for synchronization across threads.
Kuphryn
|
|
|
|
|
what are you trying to do so I can help you
gabby
|
|
|
|
|
I'm trying to block off a chunk of code responsible for sending a request to a server and receiving its immediate reply. I enclosed this chunk between the EnterCriticalSection(mutex) and LeaveCriticalSection(mutex) functions, or something like:
while (InterlockedExchange(&s_spinlock, 1) == 1)
{
Sleep(0);
}
//
// send request and receive reply from the server;
// something like send(request, reply)
//
InterlockedExchange(&s_spinlock, 0);
They seem to do the job. But when more client threads are involved (say 200-300), performance decreases significantly.
Basically, what happens within that chunk is the client sends a request to the server for it to perform a queue function (enqueue/dequeue) on a server side queue. The client sends the message to enqueue with the request as well, and then receives some reply from the server that has something to do with the outcome of the queue function.
|
|
|
|
|
I am suspecting the maount of threads is your problem?
You can try to use thread pools to decrease the number of threads in your system.
The context switching among so many threads will ultimately effect your peerformance more than worrying about the time spent on the thread synchronization objects.
|
|
|
|
|
Hello !
I made a program that connects to a Bluetooth device (a BT dongle is connected on my computer). So, I open the communication like a normal serial port (BT port is COM4 on my computer). The difference between the two is that when I try to write something to the port (using the WriteFile function) when nothing is connected, I don't have any timeout and thus my program hangs. The program doesn't hang when a standard serial port is opened...
Anybody have a solution for this problem ?? Of course, my program cannot hang when the device is not powered...
Thanks
|
|
|
|
|
Hmm..
To simplify things: does the BT stack offer the COM4 port even if the device wasn't connected ? I mean, regardless of the availability of the device, the port can always be opened ?
But, when a device is not connected, the port does open but no timeouts occur ?
One solution would be to use a custom timer. On the first attempt to communicate with the device, open the port, create a custom timer, and send a predefined command to the device, to which you know a response. This could be something like querying the serial number or software version. If your custom timer expires before a response is received, it is safe to assume that there is no device connected, and handle this as "No device available" -situation in the application.
-Antti Keskinen
----------------------------------------------
The definition of impossible is strictly dependant
on what we think is possible.
|
|
|
|
|
Hi !
Thanks for your response.
Ok, here is what happens:
1) if no dongle is connected to the computer, the port can be opened without problem
2) Same thing happens when the dongle is connected but the device is not powered (so still no communication).
In both cases, the WriteFile function hangs !! So I cannot use a timer because this instruction waits that all the data is transmitted and so my program is 'suspended'.
And I also tried to check the DTR line but it is always at 1 even if the dongle is disconnected !!
The only solution I've found for now is that the device need to send always data. When my program starts, I open the port and first check if I receive data (ReadFile doesnt' hang if no device is connected). If yes, the device is connected. If no, no device is connected.
But now I want to change the protocol so that the device send data only when I ask for them (yes, the device is made by us also, so we have access to the code)...
Any solution ??? I'm lost here
|
|
|
|
|
Solution: overlapped I/O.
The last parameter of WriteFile is a pointer to an OVERLAPPED structure that specifies the semantics of an overlapped write operation. This type of an operation is event-driven: when the WriteFile begins, it clears the event flag. When WriteFile finishes, it returns. When the I/O transaction is completed (bytes written), the overlapped flag is raised.
The only necessity is that you open the COM port by using FILE_FLAG_OVERLAPPED specification. Overlapped port access is a tid-bit different from the standard one, but needs to be used in this case. See the OVERLAPPED structure in MSDN for more information.
The basic approach is
1. Create an event object by using CreateEvent
2. Set this event handle into the OVERLAPPED::hEvent member
3. Open the communications port, specifying FILE_FLAG_OVERLAPPED
4. Call WriteFile , specifying the OVERLAPPED structure as the last parameter. WriteFile returns immediately.
5. To determine if the writing was succesfull (if there is a device), call WaitForSingleObject , specifying a suitable time-out. If the event is fired (WaitForSingleObject returns WAIT_OBJECT_0 ), then the writing was succesfull. If return value is WAIT_TIMEOUT , the timeout was reached.
6. Take appropriate action.
-Antti Keskinen
----------------------------------------------
The definition of impossible is strictly dependant
on what we think is possible.
|
|
|
|
|
Hi Antti !
Ok, thank you for your response but I just found the solution to my problem. In fact, if the BT and serial ports behave differently, it is because the BT do not send any data when the device is not connected and in a serial communication, the data is sent over the port even if no device is connected. So, I was so stuck by this thing that I didn't watch my timeout values. In fact, the timeout for write operations was set to MAXDWORD that means I wait till the data is sent !! So, I just changed this to another value and now that works fine .
Anyway thank you for your time
|
|
|
|
|
This is not strictly a c++ question. Feel free to flame me
We have an app running at a customer site. They are having intermitent crashes and the stack trace that we dump is always different. I cant reproduce the error in our testing environment and I think this may be beacuse the customer is using a dual CPU machine. I would like them to attempt to reproduce this issue using only one CPU. Is it posible to specify thread affinity on the command line when starting an app so I can force all the apps threads to run on one processor only?
|
|
|
|
|
There is no doubt that problems show up on multi-processor machines that don't on a single cpu. You could add a cmd line option to your app to force it to use a single cpu.
Neville Franks, Author of ED for Windows www.getsoft.com and coming soon: Surfulater www.surfulater.com
|
|
|
|
|
I had thought of that but I really want to do it without recompiling because this is our customers production environment
|
|
|
|
|
I m using MFC dialog based application.
i want to make it skinable with GIF images
in CP there are Exampls but thay use BMP files
wts the way for GIF to use
thnx
Regards.
|
|
|
|
|
The approach for using GIF as skin images is precisely similar as to using BMPs. The difference is that you must first run the GIF data stream through a decompressor to get actual image data. BMP images are not encoded, they are simply raw image data. Thus they don't need a decompressor.
So, find a tutorial that uses file-based images to skin the dialog. Then implement this procedure, but include a GIF-decompressor routine.
-Antti Keskinen
----------------------------------------------
The definition of impossible is strictly dependant
on what we think is possible.
|
|
|
|
|
i search but not find good one.
can u plz tell me any link or help
thanx
Regards.
|
|
|
|