Thread View: borland.public.cppbuilder.nativeapi
5 messages
5 total messages
Started by Jarkko Juntunen
Thu, 08 May 2003 08:28
How to insert into buffer?
Author: Jarkko Juntunen
Date: Thu, 08 May 2003 08:28
Date: Thu, 08 May 2003 08:28
43 lines
1934 bytes
1934 bytes
Hi!
I have next chunk of code (mostly from MSDN web-page):
error = WNetAddConnection2(&nr, cPass, cUser, NULL);
if(error)
{
LPVOID lpMsgBuf;
if (!FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
(LPTSTR) &lpMsgBuf,
0,
NULL ))
{
// Handle the error.
return;
}
// Process any inserts in lpMsgBuf.
// ...
// Display the string.
MessageBox( NULL, (LPCTSTR)lpMsgBuf, "Error", MB_OK |
MB_ICONINFORMATION );
// Free the buffer.
LocalFree( lpMsgBuf );
}
And that works just fine. But I'd like to insert something into begining of
my lpMsgBuffer. So the error message will be something like "Can't connect
:" lpMsgBuf;
But I don't know how to do that. Any suggestions?
Thanks!
Re: How to insert into buffer?
Author: Vladimir Afanasyev
Date: Thu, 08 May 2003 09:07
Date: Thu, 08 May 2003 09:07
8 lines
1166 bytes
1166 bytes
it is also possible:
// Display the string.
MessageBox( NULL, (AnsiString("Can't connect: ")+(LPCTSTR)lpMsgBuf).c_str(), "Error", MB_OK | MB_ICONINFORMATION );
Vladimir.
Re: How to insert into buffer?
Author: hans galema
Date: Thu, 08 May 2003 09:11
Date: Thu, 08 May 2003 09:11
12 lines
1476 bytes
1476 bytes
Jarkko Juntunen wrote:
> // Display the string.
> MessageBox( NULL, (LPCTSTR)lpMsgBuf, "Error", MB_OK |
> MB_ICONINFORMATION );
AnsiString Message = "Can't connect: " + AnsiString ( lpMsgBuf );
MessageBox( NULL, Message.c_str(), "Error", MB_OK |
MB_ICONINFORMATION );
Hans.
Re: How to insert into buffer?
Author: Remy Lebeau (TeamB)
Date: Thu, 08 May 2003 17:01
Date: Thu, 08 May 2003 17:01
28 lines
2026 bytes
2026 bytes
"Jarkko Juntunen" <dzeidzei@suolakaivos.com> wrote in message
news:Xns937574BE25A36dzeidzeisuolakaivosc@207.105.83.65...
> I'd like to insert something into begining of my lpMsgBuffer.
You can't insert into lpMsgBuffer directly. You would have to allocate a
second buffer, put "Can't Connect:" into it first, then copy the contents
lpMsgBuffer into the second buffer afterwards, ie:
// "Can't Connect: " + lpMsgBuf + extra padding
int len = lstrlen((LPCTSTR)lpMsgBuf) + 20;
lpMyBuffer = (LPTSTR) GlobalAlloc(GPTR, len * sizeof(TCHAR));
lstrcpy(lpMyBuffer, TEXT("Can't Connect: "));
lstrcat(lpMyBuffer, (LPCTSTR)lpMsgBuf);
MessageBox( NULL, lpMyBuffer, "Error", MB_OK | MB_ICONINFORMATION );
GlobalFree(lpMyBuffer);
Or, just use the VCL and AnsiString:
AnsiString Msg = "Can't Connect: " + SysErrorMessage(GetLastError());
MessageBox( NULL, Msg.c_str(), "Error", MB_OK | MB_ICONINFORMATION );
Gambit
Re: How to insert into buffer?
Author: Jarkko Juntunen
Date: Thu, 08 May 2003 19:48
Date: Thu, 08 May 2003 19:48
3 lines
944 bytes
944 bytes
Thaks again to all of You! Now it's working. -- -jii
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads