|
No, GlobalAlloc() alone can not do what you want.
You could probably use the clipboard to do what you want but it would be a lot more work than using one of the other methods mentioned.
A handle is like a pointer in that it is specific to the application and can not be shared with another application (in general).
...cmk
Save the whales - collect the whole set
|
|
|
|
|
VC++ 6, MFC, SP5, WinXP - Home .
I've spent the last few months writing an application for work (They found out I do some programming for fun and now it's part of my job ) Anyway, The application is done and runs fine on XP. Both the release version and debug version run well, debug shows no memory leaks or asserts (other then the asserts I want it to show.)
So anyway, I try to run it on Win 2K and the app crashes at start up. No chance for the main window to open or anything. The crash is not a GPF or a blue screen, just a small message box that states "Your program has done something I don't like and will close now. A log is being created. OK." - Well, that's not the actual message but the jest of it ...and it doesn't tell me where the darn log is!!! I know I took a lot of care to use API functions that would work all the way down to Win 95, so I'm kind of stummped. I even used some of the debugging code here on Codeproject to insert into the application during debug builds and it shows everything was A-OK.
Anyone have any ideas of where I can even start looking for the cause of this crash?
Thanks for any advice.
-- modified at 23:00 Tuesday 6th September, 2005
|
|
|
|
|
-- modified at 23:42 Tuesday 6th September, 2005
For the record, I deleted this because CP posted it twice....
|
|
|
|
|
If a log was created, it's probably in the system event log. My first step with problems like this is to create a global file object, and to use it to log how far the app gets before crashing, and work out what line is blowing up through a process of elimination.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Thanks for the idea! Sort of like a debug output screen but written to a file. That it too simple!
And off the record, your other message was deleted because you were really listening to Iron Maiden again, right?
Thanks for the help!
Paul...
|
|
|
|
|
Nah, I just got the Hollywood Rocks box set, so I have no idea who I'm listening to from one moment to the next, but it's all good...
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
If you can get your program 'started' then you should download the "Debugging Tools for Windows" form Microsoft's website. Install it. Read about running 'AdPlus to capture the 'crash' mode. Then look at the DMP file using WinDBG (have all the PDB files for your project handy) and you can probably determine exactly where and why your program crashes.
|
|
|
|
|
Problem:
I have difficulty in displaying Unicode string in Win32 console.
Test:
-Win32 Console is a character-mode application, not a byte-mode application. So even other documents said Win32 Console support Unicode, I found no sample or more details document than MSDN about this.
-I tried to used the FillConsoleOutputCharacter(Unicode development mode)
and found that the Win32 Screen Buffer is really a character-based buffer.
#include <wincon.h>
TCHAR c;
COORD crdSrc;
crdSrc.X = 0;
crdSrc.Y = 2;
for (c = 0x0000; c < 0xFFFF; c++)
{
...
FillConsoleOutputCharacter(hFile,c,sizeof(c),crdSrc,&dwConsole);
//Unicode mode: sizeof(c) = 1 character
}
The result in the output is always showing two character(???). But it can
show some following compound Unicode character: ㈪ ㈫ ㌘ ....
It make me confused now.
-I used "cmd /U" in command line. The pipe are Unicode but displaying is strill OEM.
Conclusion:
-I have a doubt that the Win32 Console Screen Buffer has one byte
per character(character-mode application). If it is actually that, it is
unable to show Unicode character in Win32 Console except some system Compound
Unicode Character.
Question:
-Can anyone help me to displaying Unicode string in Win32 Console?
-By the way, can you show me the way to read a handle(HANDLE) information. Reading STD_OUTPUT_HANDLE always causes violent access memory exception (is it secured pipe?).
Many thanks.
Le Tuan Anh
Mail to: anhlt@mt-it.com
|
|
|
|
|
Hello
How can I read another process of variable if I don`t know variable address?
If I know variable address,
I can do:
// readprocess.cpp
...
if( (string)pe.szExeFile =="A.exe" )
{
h=OpenProcess(PROCESS_ALL_ACCESS,TRUE,pe.th32ProcessID);
if(h!=NULL)
{
if(ReadProcessMemory(h,(LPCVOID)0x0012FED4,&tmp,4,&dwNumberOfBytesRead))
MessageBox(NULL,"ok","ok",NULL);
...
of course, get variable address(0x0012FED4) by other way;
//A.cpp
...
int a;
cout << &a << endl;
...
I want know how can get variable address by readprocess.cpp?
thanks!
|
|
|
|
|
I just new in visual c++ and have a copy of server and client source code. The result after I compile show Bytes recv: 21, but I want to change it so that I can send what I type. Can help me...Below is the client source code:
#include "stdafx.h"
#include "winsock2.h"
void main()
{
// Initialize Winsock.
WSADATA wsaData;
int iResult = WSAStartup( MAKEWORD(2,2), &wsaData );
if ( iResult != NO_ERROR )
{
printf("Error at WSAStartup()\n");
}
// Create a socket.
SOCKET m_socket;
m_socket = socket( AF_INET, SOCK_STREAM, 0 );
if ( m_socket == INVALID_SOCKET )
{
printf( "Error at socket(): %ld\n", WSAGetLastError() );
WSACleanup();
return;
}
// Connect to a server.
sockaddr_in clientService;
clientService.sin_family = AF_INET;
clientService.sin_addr.s_addr = inet_addr( "127.0.0.1" );
clientService.sin_port = htons( 60000 );
if ( connect( m_socket, (SOCKADDR*) &clientService, sizeof(clientService) ) == SOCKET_ERROR)
{
printf( "Failed to connect.\n" );
WSACleanup();
return;
}
// Send and receive data.
long bytesSent;
long bytesRecv = SOCKET_ERROR;
char sendbuf[300] = "Client: Sending data.";
char recvbuf[300] = "";
bytesSent = send( m_socket, sendbuf, lstrlen(sendbuf), 0 );
printf( "Bytes Sent: %ld\n", bytesSent );
while( bytesRecv == SOCKET_ERROR )
{
bytesRecv = recv( m_socket, recvbuf, 300, 0 );
if ( bytesRecv == 0 || bytesRecv == WSAECONNRESET )
{
printf( "Connection Closed.\n");
break;
}
if (bytesRecv < 0)
return;
printf( "Bytes Recv: %ld\n", bytesRecv );
}
return;
}
|
|
|
|
|
I'm at a loss why you keep pasting all of this code here. I'd also reiterate that it's obvious that you're using code when you have no idea what it does. Copy and paste without examining the code is no way to learn.
TTjen wrote:
char sendbuf[300] = "Client: Sending data.";
char recvbuf[300] = "";
bytesSent = send( m_socket, sendbuf, lstrlen(sendbuf), 0 );
As I said yesterday, it doesn't matter how big or small you make sendbuf, lstrlen will return the length of the string you assigned to it, which is 21. The rest of the variable just never gets sent, because it's beyond the null value which causes lstrlen to ( correctly ) stop counting. You can set this string to be any value you like, up to 300 characters, and it will send it and give you back it's length. A better approach would be to use a string class like std::string or, if you're using MFC, CString. Both give you access to the underlying char * without having to allocate any memory, or impose a length limit. then you can assign the text you type to this variable, and pass the buffer in to the send method.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Greetings All,
How does one initializes GDI+ in C++?
Thanks.
Sincerely,
Max Pastchenko
|
|
|
|
|
If you got to the appropriate section, I have a series of GDI+ articles, including one on how to get it working in VC6.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
certainly, I understand that a header file needs to be included but this is not quite what i asked. Lets say i want to start wowrking with colors once i inluded everything...
Sincerely,
Max Pastchenko
|
|
|
|
|
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemdrawingcolormemberstopic.asp\
What I really want to do is use a Dll that works with colors in GDI+, so I need to be able to send Color I want to use to that DLL from C++, if this makes sence.
Sincerely,
Max Pastchenko
|
|
|
|
|
That link leads to the Colors enum, I'm not sure that's visible in GDI+ using C++. If it is, did you write this dll ? What is it ? Why do you need to pass these values ? An enum is just a bunch of numbers, you should have no trouble passing it around.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
mpastchenko wrote:
Lets say i want to start wowrking with colors once i inluded everything...
Well, you didn't ask that. Read some tutorials, 'how do I work with colors' is a pretty broad question.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Ok, sorry, i will be more specific.
My area of expertise in GDI+ in C++ environment is still lacking, i have been using it in C# without problems.
I have a DLL that contains some operations using GDI+, using System.Drawing.Color for some operation for example. One of the set properties in the DLL is supposed to Set this Color... it will use it then for further operation. For example, I need to pass color which needs to be skipped in bitmap comparison.
I did not write the DLL originaly, i added some modofications to it, so i know what it is supposed to do.
Sincerely,
Max Pastchenko
|
|
|
|
|
mpastchenko wrote:
I have a DLL that contains some operations using GDI+, using System.Drawing.Color for some operation for example. One of the set properties in the DLL is supposed to Set this Color... it will use it then for further operation. For example, I need to pass color which needs to be skipped in bitmap comparison.
Why do you need to pass a Color from the enum ? They are just a lookup to a red/green/blue value anyhow, and that's what your code will need to skip colors ( the R/G/B ). Why not pass a COLORREF ? Or even three bytes ?
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
I think passing one of the two will solve the problem. very good
Sincerely,
Max Pastchenko
|
|
|
|
|
I have been using Microsoft Visual C++ 6.0 for a MFC SDI project for some time.
Recently however, I have noticed that the Release Build of my executable gives an "Access Violation" error when the program is terminated. The Debug Build does not give any such problem.
Because I couldn't solve the problem, I loaded a backup of my project. The previously built executable ran and exited nicely, but when I recompiled the code and ran again, I recieved the same error.
The error occurs when the program is terminated (after the WM_DESTROY message is successfully processed, but before ExitInstance() or any of the Document/Frame/View objects have their destructor called.
The error is:
0xC00000005, Access Violation.
The assembly code at this point is something like
mov e-something dword ptr [eax]
or something like that (I am not at my pc now, it has no internet connection).
Note that information on the error is limited, because it only occurs in the Release Build.
If you have any idea what could be going on, or remember anywhere/anyone talking about something similar, PLS let me know.
|
|
|
|
|
Hamza5 wrote:
Note that information on the error is limited, because it only occurs in the Release Build.
This Would be helpful:-
www.codeproject.com/debug/survivereleasever.asp[^]
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
|
|
|
|
|
Thanks this article is great.
btw, there are two accidental spaces in front of the hyperlink, so it becomes "http:/ www." instead of "http:/www.".
Just mentioning that in case anyone else uses the link.
|
|
|
|
|
The problem can be caused by a non-initialized pointer ;
in debug version the pointer might be automatically
initialized to zero by the compiler, and in release
version, the compiler does not perform any automatic
init. So, when a delete is done on the pointer, it
crashes if the pointer is not null.
|
|
|
|
|
Thanks, I will review my code for that.
|
|
|
|
|