 |
|
 |
hi,
can you tell me a simple procedure of connecting an MFC application with SQL server??
thanks in advance..
|
|
|
|
 |
|
 |
Thomas Hoekstra wrote:
A BSTR should be allocated with ::SysAllocString() or CString::AllocSysString().
Otherwise you will see some funny string in VB while debugging your project.
In case it is not clear, the pointer to the BSTR that is returned from that function (currently) will be invalid: the BSTR will be freed when the CComBSTR object is destroyed. If the CComBSTR::Detach(...) function was used, it would work OK.
Also, when you use many of the OLE String Conversion Macros, like OLE2T(...), the memory returned by the macro is freed at the next closing scope. In the case of the SetString(...) function, that means the pointer in m_pData is invalid when the function returns. And the pointer stored in m_pData is always deleted in the destructor, which is incorrect in the case of using the String Conversion Macro.
Lastly, the memory in m_pData is never checked and/or freed if the SetFile(...) function is called more than once. The stored buffer length should be checked, and if the existing buffer is already large enough, it should not be reallocated. The call to memset(...) right after the allocation of memory is also questionable; it works because NULL equals 0, but this is a strange use of NULL. Just because NULL and MB_OK are equal to 0 does not mean that you should make a call to MessageBox(...) like this:
MessageBox( 0, _T( "A Message" ), _T( "A Caption" ), 0 );
Peace!
-=- James (Sonork:100.21837)
"There is nothing worse than being oblivious to the fact that you do not know what you are doing."
[Get Check Favorites 1.5 Now!]
|
|
|
|
 |
|
 |
I've made a program that will successfully convert text into hex. So now i need to make a program to convert the hex form back into text. i wish to make the program so that you jsut read the hex from a .txt file and then print the text form onto a new .txt file. THe prob is that i'm a newbie and i dont think you would wanna help but i would truly appreciate it.
thx
T.P.D
|
|
|
|
 |
|
 |
A BSTR should be allocated with ::SysAllocString() or CString::AllocSysString(). Otherwise you will see some funny string in VB while debugging your project. STDMETHODIMP CHexConverter::GetNextLine(BSTR *pbstrOutput) { ... ... ... //send to the user //CComBSTR bstrTmp; //bstrTmp = (LPCSTR)sNextLine; *pbstrOutput = sNextLine.AllocSysString(); return S_OK; } You are also exceeding the boundaries of your BYTE b[17]. The terminating zero should be b[16], because the indexes run from 0 to 16, forming an array of 17 elements. Writing to b[17] corrupts your stack! BOOL CHexConverter::GetNextLine(CString& sNextLine) { ... ... ... //get to the buffer pointer BYTE b[17]; memset(b, 0, 17); memcpy(b, pRes, iChars); delete [] pRes; pRes = NULL; //convert them to hex format sNextLine.Format ("%0.8X %0.2X %0.2X %0.2X %0.2X %0.2X %0.2X " \ "%0.2X %0.2X - %0.2X %0.2X %0.2X %0.2X %0.2X %0.2X %0.2X " \ "%0.2X ", m_lCurLine * 16, b[0], b[1], b[2], b[3], b[4], b[5], b[6], b[7], b[8], b[9], b[10], b[11], b[12], b[13], b[14], b[15]); //replace non alphanumeric chars with '.' for (int i=0; i < iChars; i++) { if (!::IsCharAlphaNumeric (b[i])) b[i] = 0x2E; //hex equavelent of '.' } // b[17] = 0; // Stack corruption !!! b[16] = 0; // don't forget terminating null ... ... ... }
|
|
|
|
 |
|
 |
I want to use method SetWallpaper of interface IActiveDesktop ,but my picture's path is CString, it's no match with first SetWallpaper's parameter. I can't convert CString to WCHAR. Please help me. Thank you very much ! Sory for my poor English .
|
|
|
|
 |
|
 |
Hello,
Try the AllocSysString() method of the CString object.
AllocSysString() returns a BSTR.
|
|
|
|
 |
|
 |
I was wondering what type of test program to use for testing COM object. Please give some details step by step. thanks!
|
|
|
|
 |
|
 |
Dear Mukesh Gupta:
I am a chinese programer! I needed to use the code!
will the code change the text, for example "AAA",
to "0x41,0x41,0x41"?
Can you understang me?
thanks to you!
yours
linghuchong
|
|
|
|
 |
|
 |
Hello There,
I have created a little programme called TESTER that u can download to see how it works.
Regarding your probelm, well it exactly dosen't converts
"AAA" to "0x41, 0x41, 0x41". What it does is it will convert
"AAA" to
"Ox00000000 41 41 41 00 00 00 00 00 00 00 00 00 00 00 00 00 AAA".
u can have a look at the Tester programme. You need to build and regsiter the componet before using Tester.
Hope this helps...
Cheers,
Mukesh
|
|
|
|
 |
|
 |
Dear Mukesh:
Oh,I undestand you!thanks to you!
I need to add the "0x" to the String so that I can
get byte name[]={"0x41,0x41"};
will you introduce some ATL tutorial www sit to me?
thanks to you,again!
yours
linghuchong
|
|
|
|
 |