|
I have some codes which I don't know how to continue writing. The code goes like this:
HRSRC hrSrc = FindResource(AfxGetResourceHandle(), MAKEINTRESOURCE(IDR_LOCKUP_EXE), "Exe");
HGLOBAL hGlobal = LoadResource(AfxGetResourceHandle(), hrSrc);
LPVOID lpExe = LockResource(hGlobal);
CFile file;
file.Open("C:\Testing.exe", CFile::modeCreate | CFile::modeWrite | CFile::shareDenyNone);
file.Write(lpExe, (UINT)SizeofResource(AfxGetResourceHandle(), hrSrc));
file.Close();
HANDLE hExe = LoadLibrary("C:\Testing.exe");
HRSRC hrSrc2 = FindResource(hExe, MAKEINTRESOURCE(IDR_LOCK_FILE), "LOCKFILE");
HGLOBAL hGlobal2 = LoadResource(hExe, hrSrc2);
LPVOID lpExe2 = LockResource(hGlobal2);
LPBYTE sExe2 = (LPBYTE)lpExe2;
LPTSTR sExe3 = (LPTSTR)sExe2;
CFile file2;
file2.Open("C:\Program Files\Adobe\Acrobat 6.0\Reader\AcroRd32.exe", CFile::typeBinary | CFile::modeRead | CFile::shareDenyNone);
CFile file3;
file3.Open(sExe3, CFile::modeWrite | CFile::shareDenyNone);
file3.Write(???);
file3.Close;
For the ???, what should I put in there so that I can insert the AcroRd32.exe as a binary resource into Testing.exe (I don't want to add in the resource manually)? Or should I rewrite some parts of the code?
|
|
|
|
|
|
I understand that. But how can I use the UpdateResource function to transform a file into a resource and update the resource of my program?
|
|
|
|
|
Did you look at the "Updating Resources" example on MSDN?
|
|
|
|
|
Yes. But I am not sure how to create a pointer to point to my file that I want to include as a resource and insert into the UpdateResource function. You know how can I do that?
|
|
|
|
|
HANDLE hInputFile = CreateFile("AcroRd32.exe", GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);<br />
DWORD dwFileSize = GetFileSize(hInputFile, NULL), dwBytesRead;<br />
LPBYTE pBuffer = new BYTE[dwFileSize];<br />
ReadFile(hInputFile, pBuffer, dwFileSize, &dwBytesRead, NULL);<br />
CloseHandle(hInputFile);<br />
HANDLE hUpdateResource = BeginUpdateResource("Testing.exe", FALSE);<br />
UpdateResource(hUpdateResource, RT_RCDATA, "Acro", MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL), pBuffer, dwFileSize);<br />
EndUpdateResource(hUpdateResource, FALSE);<br />
delete [] pBuffer;
|
|
|
|
|
Thanks for the help. But when I run the program, it gives me this error when I press the OK button:
Debug Error:
Program:..sktop\LockupApplication\LockupBuilder\Debug\LockupBuilder.exe
Invalid Allocation size: 4294967295 bytes
What's wrong? Please help me.
|
|
|
|
|
Ricky Koh wrote:
Invalid Allocation size: 4294967295 bytes
What's wrong?
You cannot allocate that much memory! The absolute maximum that you could allocate is 3GB (and that's only on the advanced flavors of Windows), but that assumes that such a contiguous block exists after everything else is loaded. In reality, the most you could probably get would be little more than 2GB.
|
|
|
|
|
ok. so is there any way to solve this problem ('cause i got this error when I added the code that you have given me into my program)?
|
|
|
|
|
What about the suggestion(s) in this thread?
http://www.codeproject.com/script/comments/forums.asp?msg=605271&forumid=1647#xx605271xx
Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?
|
|
|
|
|
Thanks for the reference. I have seen the thread. But, how can I allocate an amount of memory first so that I will not get the allocation problem when I run the program?
My code is now like this:
HRSRC hrSrc = FindResource(AfxGetResourceHandle(), MAKEINTRESOURCE(IDR_LOCKUP_EXE), "Exe");
HGLOBAL hGlobal = LoadResource(AfxGetResourceHandle(), hrSrc);
LPVOID lpExe = LockResource(hGlobal);
CFile file;
file.Open("C:\Testing.EXE", CFile::modeCreate | CFile::modeWrite | CFile::shareDenyNone);
file.Write(lpExe, (UINT)SizeofResource(AfxGetResourceHandle(), hrSrc));
file.Close();
HANDLE hInputFile = CreateFile("C:\Documents and Settings\Administrator\My Documents\Testing.txt", GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
DWORD dwFileSize = GetFileSize(hInputFile, NULL), dwBytesRead;
LPBYTE pBuffer = new BYTE[dwFileSize];
ReadFile(hInputFile, pBuffer, dwFileSize, dwBytesRead, NULL);
CloseHandle(hInputFile);
HANDLE hUpdateResource = BeginUpdateResource("C:\Testing.exe", FALSE);
UpdateResource(hUpdateResource, "LOCKFILE", "IDR_LOCK_FILE", MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL), pBuffer, dwFileSize);
EndUpdateResource(hUpdateResource, FALSE);
delete [] pBuffer;
|
|
|
|
|
Sir,
I am developing FTP in win32 console application like client-server
program. i want to send files from client to server as blocks.
for eg, i want to send 10kb file means,i will send like 1kb files.
so, i heve 1 structure named as block.
how can i implement this code.can u anybody help this..
Thanks in advance,
Rathipriya.
Rathipriya
|
|
|
|
|
a FTP client for console already exists!
Don't try it, just do it!
|
|
|
|
|
Hello All
I have a small DialogApp(mfc). when I compiled it with vc7, the exe runs fine on NT4, Win2k and XP, but when trying to run it on Win98, Win98 kept saying that the exe image is corrupted. I wonder if anyone've seen the problem and know why?
PS. mfc and CRT is statically linked into the exe.
|
|
|
|
|
normally its the other way round.. but 98 suxx indeed
Don't try it, just do it!
|
|
|
|
|
Are u compiling your program in Unicode ? if u are, then it will not run in legacy windows (WinME, Win98, Win95).
I Dream of Absolute Zero
|
|
|
|
|
Hey,
My prog is supposed to communicate with an external device with the serial port.I ve got some trouble trying to get it working...
If I don t run the hyperterminal before using my software, the communication doesn t work.I ve tried to use overlapped and nonoverlapped communication.I ve tried to use a couple of activex controls and different classes.But it's still the same.Moreover, I am almost sure that my initializiation parameters are OK.
Has somebody already had this kind of bug?
What does the hyperterminal do that my prog doesn t?
I tried to use a sniffer to find out what s going on in my communication, but everything looks find as well.
If you have any ideas, please feel free to share ur thought....
I ve been trying to debug my softare for 2 weeks now...
Thanks for ur precious help.
sysy
|
|
|
|
|
You can use PortMon[^] to compare the settings of the terminal program with those of your application.
Cheers,
Fredrik
"Felix qui potuit rerum cognoscere causas."
|
|
|
|
|
Cable
If hyperteminal works then it should be OK
Data
You are using a sniffer, have you tried using 2 PCs with your prog on #1 and hypertermial on #2? Or use 1 PC with two serial ports?
CreateFile
CreateFile can be used to send serial data, search MSDN for "Configuring a Communications Resource" try this and send a test string to another PC that has hypertermial running, e.g. send "hello world". This should prove out your line settings baud rate, stop bits, parity etc. I assume this is where you problem is.
With serial comms I always found is easiest to buy a comms library, the last one I used was COMM-DRV.
Generally the problems are caused by the cable, handshaking, or not setting the DCB block in SetCommState
A favourite problem is using XON/XOFF protocol and sending XOFF, also some devices/computers will conver a LF to CR/LF unless line characteristics are set to raw mode.
So do a simple test to prove it works sending to hypertermial, that will elinate the receiving prog/device.
It is amazing what you can accomplish if you do not care who gets the credit. - Harry S Truman
|
|
|
|
|
Hi,
you can try to use the MSCOMM32.OCX for that.
Otherwise you can find a serial class here:
http://www.naughter.com
Regards Mark
|
|
|
|
|
Hi
When i load my workspace, i get a message "can not access the calss view information file. classview information will not be available". how can i fix this problem?
Thanks
|
|
|
|
|
is the class view empty?
yeah,when I link to the sourcesaft control, that is like you.
dupengfei
|
|
|
|
|
First, check if you have a hidden msdev.exe process running when no Visual Studio is running. If you have one, kill it. If that doesn't help, delete the classview file, .clw. It will be regenerated when you load and compile.
Cheers,
Fredrik
"Felix qui potuit rerum cognoscere causas."
|
|
|
|
|
Please check the following link for the solution
http://www.codeproject.com/script/comments/forums.asp?forumid=1647&mode=all&userid=161454&select=491032&df=100&fr=16230.5#xx491032xx
|
|
|
|
|
Hi all,
I am having problem to load BITMAP on a Custom Dialog.
Everything is ok, i mean.. from the main dialog, i clicked button A to launch the Custom Dialog.
Compiled, Run...works perfect..the Custom DIalog came out..
but the problem is how to load a BITMAP into and display on the custom dialog???
Its totally different compare to loading into the main dialog? (i know how to load into main dialog)..
My custom dialog do not have the OnInitDialog() and the OnPaint() function!!?!
So should i declare some new one?
so where should i put these codes??? put them in the main dialog header file or the custom dialog header file??
public:
CRect rectStaticClient;
int sourcex, sourcey,offsetx,offsety;
protected:
CDC m_dcMem; // Compatible Memory DC for dialog
HBITMAP m_hBmpOld; // Handle of old bitmap to save
HBITMAP m_hBmpNew; // Handle of new bitmap from file
BITMAP m_bmInfo; // Bitmap Information structure
also i suppose to put this into OnPaint()
CPaintDC dc(this);
dc.BitBlt(offsetx,offsety,m_size.cx,m_size.cy,
&m_dcMem, sourcex, sourcey,SRCCOPY);
CDialog::OnPaint();
but now..where should i put them?
also...all those member variables.. where should i declare them?
into the Main Dialog or into the Custom Dialog??
hope u guys can help and guide me.
thanks alot..
regards,
Thong
twh81@tm.net.my
...
|
|
|
|
|