|
Help me!
I want convert file .mp3 to file .sty (play with Organ player).
Thank you so much!
modified 29-Jun-15 3:14am.
|
|
|
|
|
What have you tried and where are you stuck?
|
|
|
|
|
I'm looking into perf tuning in our application and one area we've identified when converting many strings between String^ and a native array of UTF-8 chars. Currently, I use code similar to this:
array<Byte>^ byteArray = System::Text::Encoding::UTF8->GetBytes(str);
pin_ptr<Byte> p = &byteArray[0];
I then proceed to memcpy from p to my own storage block.
Has anyone compared Encoding::UTF8->GetBytes() to pinning a string^ and using WideCharToMultiByte(CP_UTF8, ...)?
I suspect it will be faster to use WideCharToMultiByte even if I call twice (once to get byte count, once to convert) and will investigate today but I thought there may be a war story or two out there.
Any lessons learned?
John
|
|
|
|
|
Update:
Well, my initial experiment proved to me that YES, it's much faster to use WideCharToMultiByte().
The speedup varies by language of text I'm converting of course.
The time to run my tests were reduced by: English: 13%, German: 18%, Japanese: 16%, Chinese: 12%
The gist of my code is now:
String^ str = "...the string to convert...";
pin_ptr<const wchar_t> unicode16 = PtrToStringChars(str);
int const cbNeeded = WideCharToMultiByte(CP_UTF8, 0, unicode16, -1, nullptr, 0, nullptr, nullptr);
auto converted = make_unique<MyBuffer>(cbNeeded);
int const cbConverted = WideCharToMultiByte(CP_UTF8, 0, unicode16, -1, converted.get(), cbNeeded, nullptr, nullptr);
It was a surprise that passing -1 for the length parameter to WCtoMB resulted in an even faster conversion!
I hope this helps someone out there and I'm still interested in any responses from any devs doing similar work.
John
|
|
|
|
|
Thanks for posting the result. This is valuable information.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Hi Iam using the below codes to save the report as PDF in c#...Is it possible to convert it in C++/Cli
Thanks:thumbsup:
My Codes
byte[] Bytes = Reportviewer1.LocalReport.Render(format:"PDF",deviceInfo:"");
using (FileStream stream = new FileStream("C:\MyFolder", FileMode.Create))
{
stream.Write(Bytes, 0, Bytes.Length);
}
|
|
|
|
|
Paramu1973 wrote: Is it possible to convert it in C++/Cli No conversion is necessary, as C++/CLI is essentially the same.
|
|
|
|
|
Yep, conversion should be straightforward. 'using' is unnecessary. 'gcnew' instead of 'new'. :: to scope namespaces and clases instead of '.', etc..
|
|
|
|
|
THANKS
|
|
|
|
|
I got below exception while reading data from .dat file using c++ code eof.
Unhandled exception at 0x0FD2CCC8 (msvcp110d.dll) in ConsoleApplication1.exe: 0xC0000005: Access violation reading location 0x004DF174.
My Code:
teacher t1;
ifstream file1;
file1.open("Teacher.dat",ios::binary|ios::app);
file1.seekg(0);
while(!file1.eof())
{
file1.read((char*)&t1,sizeof(t1));
t1.Display();
}
file1.close();
Last record prints multiple time and throwing exception.
Please have a look into.
Thanks in advance.
|
|
|
|
|
1. This does not look like managed code.
2. Please use <pre> tags round your code to make it more readable.
3. What is the structure of the teacher type?
4. How is the data file created?
5. What does the Display method do?
|
|
|
|
|
i have created a simple window using MFC application wizard but i can see only navigation pane(which is in left side of window). Can anyone tell how to view those contents on List view pane.
|
|
|
|
|
That sounds like a bit more that a 'simple' window. What type of control is in each pane?
|
|
|
|
|
Hi Friends,
I came through a interesting question in inheritance. Here is the chunk of code and out put is given below.
// Inheritance tricky.cpp : Defines the entry point for the console application.
//
class Foo
{
private:
int i;
public:
Foo()
{
i = 0;
}
void geti()
{
cout << i << endl;
}
};
class Bar : public Foo
{
private:
int j;
public:
Bar()
{
j = 1;
}
void getj()
{
cout << j << endl;
}
};
void display(Foo* obj, int ctr)
{
for (int i = 0; i < ctr; i++)
{
((Foo*)obj + i)->geti();
}
}
int _tmain(int argc, _TCHAR* argv[])
{
Foo myFoo[3];
display(myFoo, 3);
Bar myBar[3];
display(myBar, 3);
return 0;
}
and Output is
0
0
0
0
1
0
The first 3 line is 0 that's fine. But how the 2nd last is 1 ???
Is there is any way that I can get all 0 in output if I am still executing this code
Bar myBar[3];
display(myBar, 3);
PLease help me out.
Thanks in Advance.
Regards,
Amrit
-- modified 12-May-15 15:52pm.
|
|
|
|
|
myBar[1].i is still 0. The problem here is that you try to apply pointer-arithmetic to a base-class pointer. When you add 1 to Foo* obj in the loop in display(..), the pointer is increased by the size of Foo , because it's declared as a pointer to Foo . But it's actually (initially) pointing to instances of Bar , whose size is larger than that of Foo - so after adding 1 to the pointer, it points to some address still within the first instance of Bar , not to the second Bar . The output of 1 is whatever happens to be at the address where i should be if the pointer was valid.
The closest thing you can do to make it work is to use pointers to pointers:
void display2(Foo** obj, int ctr)
{
for (int i = 0; i < ctr; i++)
{
(*(obj + i))->geti();
}
}
int _tmain(int argc, _TCHAR* argv[])
{
Foo myFoo[3];
display(myFoo, 3);
Bar myBar[3];
Foo *myBaz[3] = { &myBar[0], &myBar[1], &myBar[2] };
display2(myBaz, 3);
return 0;
}
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
Hi Sascha,
I am not able to understand why we need to take address of Bar objects in line
Foo *myBaz[3] = { &myBar[0], &myBar[1], &myBar[2] };
and why we need to pass to pass the address of myBaz to a Foo** ( Double Pointer )?
How surprisingly its working fine now?
One more thing I still didn't get it hpw it prints 1 for 2nd iteration of Bar object.
If I am not wrong, even if we are passing Bar address to Foo pointer, it wil call the geti function of Foo only ? so It should print variable i value that is 0 ?
Please clear my doubt.
Thanks
|
|
|
|
|
Hi Amrit,
I'll try to explain it with some diagrams.
First, the simple case - you probably know this, but I'll show it for completeness. The class Foo has a single member of type int (int32), so it has a size of 4 bytes.
# 3 instances of Foo in memory with a Foo* pointer pointing to it:
Foo myFoo[3];
Foo* ptr = myFoo;
# ptr ptr+1 ptr+2 # (100) (100+4) (100+8)
# | | |
# v v v
# Memory address: 100..103 104..107 108..111 # Instance: --Foo1-- --Foo2-- --Foo3--
# Members: ---i---- ---i---- ---i----
Now with the class Bar (8 bytes) and your original approach:
# 3 instances of Bar in memory with a Foo* pointer pointing to it:
Bar myBar[3];
Foo* ptr = myBar;
# ptr ptr+1 ptr+2 # (100) (100+4) (100+8) # | | | # v v v
# Memory address: 100........107 108........115 116........123
# Instance: -----Bar1----- -----Bar2----- -----Bar3-----
# Members: ---i---___j___ ---i---___j___ ---i---___j___
# Value: 0 1 0
And now with pointers to pointers. Let's say we're on a 32bit-system here, then a pointer has the size of 4 bytes (32 bit). So, when doing pointer arithmetic with pointers to pointers, adding 1 means always increasing its pointed-to-address by 4 bytes. It doesn't have anything to do with the size of the class that's being pointed to by the pointer that's being pointed to
# 3 instances of Bar in memory with a Foo** pointer pointing to Bar* pointers:
Bar myBar[3]; Foo *myBaz[3] = { &myBar[0], &myBar[1], &myBar[2] };
# Value: 100 108 116
Foo** pptr = myBaz;
# pptr pptr+1 pptr+2
# (200) (200+4) (200+8) # | | |
# v v v
# Memory address: 200 204 208 # Pointer: &myBar[0] &myBar[1] &myBar[2]
# Value: 100 108 116
# | \ \__
# | \ \__
# | *pptr \ *(pptr+1) \ *(pptr+2) # v v v
# Memory address: 100........107 108........115 116........123
# Instance: -----Bar1----- -----Bar2----- -----Bar3-----
# Members: ---i---___j___ ---i---___j___ ---i---___j___
Does this answer your questions?
/Sascha
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
|
All the resource files and dlls are changed to English but cannot find the reason of displaying the Chinese language.
Peer.rc code is now that compiles fine.
#ifdef string ID IDS_ENUMSTRTEST#error Microsoft Visual C++ #endif //APSTUDIO_INVOKED
Thanks
|
|
|
|
|
How do I can split file over 4gb in fat32 in to multiple file with same name and same directory
cygwin1.dll can do this in iso9660 file system
|
|
|
|
|
You cannot, unless you create the directories across different root paths. In any directory each file name must be unique.
|
|
|
|
|
Hi guys,
I have asked this question in an interview
How to swap address of pointers of 2 variables without using a temporary variable?
As I know the arithmetic operation is not allowed between 2 pointers. So what is the trick ?
Pls help me out. Thanks in advance.
Regards,
Amrit
|
|
|
|
|
Amrit Agr wrote: Pls help me out
Perhaps it is helpful to know that the interviewer probably didn't know what they were doing in terms of interviewing.
Hopefully you were asked some other questions which were in fact more relevant.
Amrit Agr wrote: So what is the trick ?
Being interesting to see if there is in fact a correct answer. Just googling suggests that the standard C/C++ answer which, as you noted, is not in fact the same as Managed C++ makes it very unlikely that you can in fact do it without an intermediary. And if possible it would require more consideration than just whether it was a pointer or not.
|
|
|
|
|
you can use swap() method in c/c++,
is this you want?
|
|
|
|
|
XOR swap algorithm[^]
X := X XOR Y
Y := X XOR Y
X := X XOR Y
But you cannot do this with pointers as compiler does not allow XOR operation on pointers, you have to cast pointer to integer(32bit ptr to 32bit integer and 64bit ptr to 64bit integer) beforehand. This is a favourite interview question among some interviewers (who apparently read the same interview book).
|
|
|
|