|
I would like to know whether a file(*.txt) is normal ansi text file or unicode file by program. Is there standard class in C++/MFC for reading UNICODE file?
Best Regards,
Suman
|
|
|
|
|
As with anything else, it is not a straight forward process:
http://codesnipers.com/?q=node/68[^]
"We make a living by what we get, we make a life by what we give." --Winston Churchill
|
|
|
|
|
If the app expects the files to be relatively small, you can read in the file raw into a buffer and use IsTextUnicode() against the buffer using the IS_TEXT_UNICODE_SIGNATURE flag.
In an MFC app, this should occur in the serialize method or be a function called from the serialize method. to get the filesize, get the file pointer using ar.GetFile() and call GetLenth() on the file pointer. Obviously, you'll read in the raw data using ar.Read().
Not the most efficient way I'll bet, but it seems to work. However, note the disclaimer in MSDN in the remarks section for IsTextUnicode()
|
|
|
|
|
AFAIK, there is a two byte signature at the very start of a UNICODE text file.
The signature consists of the character values FF hex (255 decimal) and FE hex (254 decimal).
They can be in the order FEFF or FFFE, which flags if the bytes in the file is big or little endian. I don't remember which is which, but Google is your friend.
You can try it yourself, just create a text file with Notepad, save it in UNICODE and then dump the file with a hexdump (or hexeditor) program.
Alcohol. The cause of, and the solution to, all of life's problems - Homer Simpson
|
|
|
|
|
hi,
I'm writing a ActiveX(OCX file) project in VC6 ,I want create one method in my project, this method have 2 parameters change in this method ,then when call this method in any language ( example delphi) I want see value change in these parameters ,
In fact I want my method return 2 strings value .
I don't know type these parameters and ...
thanks for any answer.
|
|
|
|
|
Accept these two parameters by reference / pointer (out parameter).
[id(1), helpstring("XXXX")] HRESULT foo([out,retval] long* out1, [out,retval] long* out2);
Regards,
Paresh.
|
|
|
|
|
thanks for your help paresh,
but, my project is AcriveX in Visual C++ 6 , and I create my method by classwizard, in classwizard type parameters is limited by combobox and have not this type ("[out,retval] long* out1") but I write this type manual and build my project , VC6 give error syntax error : '['
regards
|
|
|
|
|
Hello,
I am attempting to create a C++ dll for use with Visual Basic. I have managed to get my dll working when I late bind in Visual Basic6 using Private Declare Function ... but I wanted to make the dll so it was referencable in VB6, and have the function appear in the intellisense - without having to declare the dll and its functions in my VB6 project. I have been using this (dated) tutorial from microsoft as reference
I have achieved this with a fairly simple dll that takes a long from VB and returns a long. Here is the C++ code
<br />
int __stdcall testfunc(int incoming)<br />
{<br />
incoming += 10;<br />
return incoming;<br />
}<br />
and the code in the .idl file
<br />
[<br />
uuid(B99D1487-BC95-4d28-A064-55A4ED191343),<br />
helpstring("vbtestdll"),<br />
lcid(0x0409),<br />
version(1.0)<br />
]<br />
library vbtestdll<br />
{<br />
[<br />
helpstring("Sample functions exported by vbtest.dll"),<br />
version(1.0),<br />
dllname("vbtestdll.dll")<br />
]<br />
module MyDllFunctions<br />
{<br />
<br />
[<br />
<br />
helpstring("Returns an integer."),<br />
entry("testfunc")<br />
]<br />
int __stdcall testfunc([in] int incoming);<br />
}<br />
}<br />
This is how it appears in the VB6 Object Browser. the type library references perfectly and I can use the function in vb, just like it was a native function.
My problem arrises when I try a more complicated function. The function I am trying to make available to VB6 returns char* - Now this seems to work perfectly when I late-bind the function using
Private Declare Function encrypt_string Lib "BlowDll.dll" (ByVal key As String, ByVal str As String, ByVal MircRet As Boolean) As String
I pass it 2 strings and either true or false, and it returns an encrypted string perfectly.
However, when I try to add this function to a .idl file, and reference the type library in visual basic, the object browser reports that the return type is "As unsupported variant type". It does however recognise that strings must be passed to the function (which are char* in cpp)
Here is a screenshot of the object browser in VB6
I have pretty much narrowed the problem down to how the function is declared in the .idl file, here is the declaration in the .idl file, the rest is identical to the above example, apart from the .dll name and name for the libraray and the uuid.
char* __stdcall encrypt_string([in, string]char *pinkey,[in, string]char *pinstr,[in]int mIRCret);
I have tried a few variations of this.. but none of them seem to make any difference..
<br />
<br />
[out, string] char* __stdcall encrypt_string([in, string]char *pinkey,[in, string]char *pinstr,[in]int mIRCret);<br />
<br />
[string] char* __stdcall encrypt_string([in ,string]char *pinkey,[in, string]char *pinstr,[in]int mIRCret);<br />
<br />
I am almost positive it has to do with the having [string] infront of char * as when I remove this from the arguments they also come up as unsupported variant type.
does anyone any any suggestions on how to resolve this issue..
thanks in advance for any help!
|
|
|
|
|
fixed my problem the idl function prototype should return as LPSTR and it works - Thanks anyway!
[string]LPSTR __stdcall encrypt_string([in, string]char *pinkey,[in, string]char *pinstr,[in]int mIRCret);
|
|
|
|
|
hi,
i have an integer array that i would like to initialize to null or other integer equivalent to it.
Actually I need the values in the previous integer array to be flush out and be empty before i click a button and continue with what the program is doing. Any suggestion on how to do this?
Thank you for any help
|
|
|
|
|
// Suppose:
// int myrray[N];
// int *myarray = new int[N];
// So:
memset(myarray, 0, sizeof (array)); // init by second parameter for each byte
--
======
Arman
|
|
|
|
|
// sorry no 'array' but 'myarray'
memset(myarray, 0, sizeof (myarray)); // init by second parameter for each byte
--
======
Arman
|
|
|
|
|
Hello, I very newbie to C++, I wanted to build Peer to Peer TV application to broadcast TV on the internet that do not need a server and high bandwidth. Something like Octoshape at http://www.octoshape.com/play/play.asp
I am not afraid to learn anything that is related in building this application, I am very keen and eager to learn to build p2p application. Can you give me what are the components that I should learn first before start building this kind of application ? such as socket programming, IO and what else ?
Any good website resources, tips, advices are very welcomed. I want to use C++. Thank you...
|
|
|
|
|
The basic components you'll need to know and work with -
1) User-interface/Windows programming
2) Capturing Video and audio from a device (camera, TV tuner card, etc.)
3) Compression of the audio and video streams
4) Realtime communication over a network
5) Decompression of the audio and video streams
6) Rendering of the audio and video streams
That's quite a bit for a beginner - just #1 is!
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
Thanks for your reply, it helps.
|
|
|
|
|
hi,
I was wondering whether it is possible to set the mapping mode of MM_TEXT in CWnd scrolling functions? It is actually a custom control with a base class of CWnd which display drawing using CDC.
Thanks for any reply
|
|
|
|
|
MM_TEXT is the default mapping mode
|
|
|
|
|
i notice that when i set the scroll range using SetScrollRange function, the range i specify does not equal to mm_TEXT mapping mode. How can i make them same?
|
|
|
|
|
I guess I would need to see the code to understand what the problem context is. I'm probably just misunderstanding what you are asking.
A window will use MM_TEXT by default. This makes it arbitrary to use logical ranges or device ranges since there is a one to one ratio.
If your client area defines a different mapping mode such as MM_HIMETRIC, you have at least two choices...
1) Use logical ranges for the scrollbars
2) Use device ranges for the scrollbar. This requires conversions from one coordinate system to the other. This is much simpler to accomplish with a CScrollView than CWnd in my opinion.
If you are pursuing option 2, then my answer to your question would be that you need to convert your scroll info from LPtoDP before setting the scrollbar info. However, you will likely need to provide more information describing what you are trying to accomplish before anyone can provide you with clear and helpful information.
|
|
|
|
|
Hi, there are hundreds of posts on the internet about this but i still don't get it. I am writing a windows program using the g++ compiler and the RAD C++ library[^]. I get these errors:
WarpFile.o(.text+0x0): In function `ZN11_RADCPP_APP12getBuildTimeEv':
C:/Program Files/Dev-Cpp/include/radc++.h:2182: multiple definition of `_RADCPP_APP::getBuildTime()'
Main.o(.text+0x6a0):C:/Program Files/Dev-Cpp/include/radc++.h:2182: first defined here
WarpFile.o(.text+0x30): In function `ZN11_RADCPP_APP12getBuildDateEv':
C:/Program Files/Dev-Cpp/include/radc++.h:2181: multiple definition of `_RADCPP_APP::getBuildDate()'
Main.o(.text+0x6d0):C:/Program Files/Dev-Cpp/include/radc++.h:2181: first defined here
WarpFile.o(.bss+0x0): In function `ZN11_RADCPP_APP12getBuildTimeEv':
etc...
Can someone please look at my code (here[^]) and tell me what i'm doing wrong. Or alternatively explain how i can prevent this error. I know it's because something has been defined in two object files but i don't know how to stop it
Customer in computer shop: "Can you copy the Internet onto this disk for me?"
|
|
|
|
|
I can not see the problem in your code, which implies it may be in the header. I could not figure out how to decompress the library download, so I could not look at “regc++.h” to check if it has code guards defined.
Try moving the ‘#include “regc++.h”’ from the header file ‘common.h’ and only include it in the files that need it.
Beyond that I can not tell why the errors are occurring.
Good Luck!
INTP
"Program testing can be used to show the presence of bugs, but never to show their absence."Edsger Dijkstra
|
|
|
|
|
Yes, i fiddled around with the code and merged Graphics.cpp with Main.cpp and made a Main.h where i did the same thing. It eventually worked, probably because, like you said, i only included things in the files that needed it.
btw, the library is "radc++.h" not "regc++.h" and i just remembered that i downloaded and installed it in Dev-C++. But all you need to know it that it is purely based on Microsoft Window API, no external libraries.
Customer in computer shop: "Can you copy the Internet onto this disk for me?"
|
|
|
|
|
Hello everybody today i was working on a project and was wondering if there is a more efficient way to do this. I have a .txt file with about 90,000 lines of data. The data is separated with tabs to form columns.
For Example:
Year Month Day Hour Income Expenses
90 1 1 1 19950.25 0
90 1 2 10 10.0 1000.22
In your opinion what will be the best way to print only the income column programmability.
I used a for loop and line.find('\t'...) to find the locations of each tab and store the results in an array. I do this for every line because the location of the tab differs from line to line. If there is a faster way I would love to know about it because I'm spending a lot of time waiting for the program to finish.
Thanks in advance.
|
|
|
|
|
When I learned to program we had to write stuff like this – why are you? You should be using the ‘list’ template.
Some of the modern MS languages allow you to ignore the fact that if you use ‘new’ you need to supply a ‘delete’, may be that is the problem. Any thing you allocate you need to deallocate – even in C++.
INTP
"Program testing can be used to show the presence of bugs, but never to show their absence."Edsger Dijkstra
|
|
|
|
|
Are you pre-allocating space for the array or re-allocating each time something new is added to it?
Are you reading in the file a line at a time or reading in each character individually and performing a "find" after each character is read?
************************************
What does the process your using look like? It would greatly assist in finding any obvious inefficiencies.
|
|
|
|