English 中文(简体)
复读数据
原标题:Array of datas returning issue, Overwriting

Please help me on this Here i want to save the converted data into new pointers. But everytime the data is overwriting with most recent data. Please check my code

 TCHAR nameBuffer[256]; //Globally Declared

 void Caller()
 {
 TCHAR* ptszSecondInFile= QStringToTCharBuffer(userName);
 TCHAR* ptszOutFile=QStringToTCharBuffer(Destinationfilename);
 }

TCHAR *dllmerge::QStringToTCharBuffer( QString buffer )
{
    memset(nameBuffer, 0, sizeof(nameBuffer));
#if UNICODE
_tcscpy_s(nameBuffer, _countof(nameBuffer), buffer.toUtf8());
#else
_tcscpy_s(nameBuffer, _countof(nameBuffer), buffer.toLocal8Bit());
#endif
_tprintf( _T( "nameBuffer %s
" ), nameBuffer );
return nameBuffer;
 }

I am gettting ptszSecondInFile and ptszOutFile both same answer. Is it possible to do with TCHAR* nameBuffer[256];

问题回答

参看你在QStringToTCharBuffer使用全球变量名称Buffer。 在当地...... 或者仅仅复制两个电话之间的名称Buffer的价值......否则,第二次电话将超过全球变量的价值......

为未来提供方案建议: 在这种情况下,你不必使用。

你们需要记忆,以保持你们一劳永逸地需要全球缓冲地带。 两人都有<条码>QStringToTCharBuffer的功能,为每一条形状或通过该功能的“焦炭缓冲”。 d 我通知第二位,因为你更可能忘记一个职能分配记忆。

i.e:

TCHAR *dllmerge::QStringToTCharBuffer( QString buffer )
{
    TCHAR* nameBuffer = new TCHAR[256];

    memset(nameBuffer, 0, sizeof(nameBuffer));
#if UNICODE
    _tcscpy_s(nameBuffer, _countof(nameBuffer), buffer.toUtf8());
#else
    _tcscpy_s(nameBuffer, _countof(nameBuffer), buffer.toLocal8Bit());
#endif
    _tprintf( _T( "nameBuffer %s
" ), nameBuffer );
    return nameBuffer;
}

v.:

void Caller()
{
    const int maxSize = 256;
    TCHAR szSecondInFile[maxSize];
    TCHAR szOutFile[maxSize];
    QStringToTCharBuffer( userName, szSecondInFile, maxSize );
    QStringToTCharBuffer( Destinationfilename, szOutFile, maxSize );
}

dllmerge::QStringToTCharBuffer( QString buffer, TCHAR* pOutString, const int size )

等等。





相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签