|
Use GetFileSize to find the size of the f01.txt file in bytes.
Then use ReadFile with the lpNumberOfBytesRead parameter set to the value returned by GetFileSize.
Then use WriteFile with the nNumberOfBytesToWrite parameter set to the value returned by GetFileSize.
Jason Henderson quasi-homepage articles "Like it or not, I'm right!"
|
|
|
|
|
Thanks for the information.
|
|
|
|
|
Hi.
I design and implement Windows programs using MFC and its doc/view architecture. Currently I am studying Jeffrey Richter's Programming Applications for Microsoft Windows. It is an amazing booking with unparrelled insights to Windows core.
In his book, Richter demonstrates thread synchronization both at user-mode and at kernel object levels using Win32 API. For example, for critical sections, you can call EnterCriticalSection(...). For events, you can call CreateEvent(...).
Anyways, I have studies from Jeff Prosise's Programming Windows with MFC. Prosise demonstrates thread synchronization using MFC tools including CCriticalSection, CEvent, CMutex, as well as CSingleLock.
Again, I have no experience with Win32 API GUI tools. I would like to know is it what is the preferred tool for thread synchronization: Win32 API or MFC? Both techniques make use of the same thread synchronization tools. I want to know which technique is more powerful now and in the future.
I really enjoy working with Win32 API, just not for GUI.
Thanks,
Kuphryn
|
|
|
|
|
The MFC thread synchronization classes are essentially thin wrappers for the underlying Win32 synchronization objects. If your project uses MFC, then you'd save some time and effort if you use the MFC wrappers. On the other hand you mention that you enjoy pure API coding, from which I assume that you prefer native API coding to MFC. If that's the case you may use the API calls directly. For example instead of using the CCriticalSection class you'd have to use InitializeCriticalSection , EnterCriticalSection etc. Performance wise you won't find any difference.
Regards,
Nish
Author of the romantic comedy
Summer Love and Some more Cricket [New Win]
Review by Shog9
Click here for review[NW]
|
|
|
|
|
Nicely explained! Thanks.
Kuphryn
|
|
|
|
|
Can anyone provide the checksum algorithm for MS Access OLE Object fields? I am looking for the Paint bitmap trailer which consists of 12 bytes appended to the bitmap like this:
0x01 0x05 0x00 0x00
0x00 0x00 0x00 0x00
0xcb 0xad 0x05 0xfe
The last 4 bytes are the checksum. Among the half dozen or so bitmaps I've checked, only the 0xcb byte seems to vary but all 4 are probably calculated. Thanks,
Ed
|
|
|
|
|
I am creating a server and a client apliction for sending/receiving files trough a CAsyncSocket derived class.But it seems that the server can't send all the file data troght the socket... I can't figure out why... here it is the code for sending the file on the server side :
void send_File(const CString &name)
{
CFile f;
unsigned char buffer[512];
int n;
f.Open(name,CFile::modeRead|CFile::shareDenyNone);
while ( (n = f.Read(buffer,512)) )
if (!PacketSend(*ClientSocket,buffer,n))
AfxMessageBox("Error sending packet...");
f.Close();
}
//code of PacketSend function
bool CConversarDlg::PacketSend(CMySocket &sock,void *buffer,const int &length)
{
//the "head" of each packet is an int, which tells the client how many bytes the packet has (packet length)
int total = sizeof(int) + length;
int sent;
int bufpos = 0;
BYTE *buf = new BYTE[sizeof(int) + length];
memcpy(buf,&length,sizeof(int));
memcpy((void *) (buf+sizeof(int)),buffer,length);
do
{
sent = sock.Send(buf+bufpos,total);
if ( sent == SOCKET_ERROR ) return false;
total -= sent;
bufpos += sent;
if ( total > 0 ) Sleep(20);
} while ( total > 0 );
delete [] buf;
return true;
}
Well, I always got the messagebox saying "error sending packet..." when I call the function send_file(const CString &); But this only occurs when a file is larger then a 5 kbytes. I can't figure out why.I am a beginner with sockets and tcp/ip.... Anyone could help? Thanks.
|
|
|
|
|
Hello, the codegurus around the world.;)
Even though I can't point out something wrong of your code, your code may
work if you send only one file within 512 characters.
You check if the first send(...) function successfully sends the data.
If not, try not to call send function at all.
At the same time, you had better check if CFile reads the exact buffer before
Send function is called by thread and CEvnet.
(This means that Socket send function may be called before CFile object
restore the 512 bytes data to the buffer?)
You can check these codes in Guncleus project (P2P application)
Go to my article, and try to go to Guncleus project web site, and download
the free code. And Check GnuUpload.h and GnuUpload.cpp, and you will find some
code of how to upload the files.
Please, don't send me your email about your questions directly.
Have a nice day!
Sonork - 100.10571:vcdeveloper
-Masaaki Onishi-
|
|
|
|
|
I would like to send an ASCII string out my serial port by pressing one of the buttons. I don't need it to effect anything else just the one specific string. A friend gave me an idea how to do it. I was wondering if everyone could take a look at my code and tell me what I need to change to complete it. I hope this makes sense what I said. I am new to Visual C++
const char * AsciiCmd = "GO";
CreateFile(AsciiCmd, GENERIC_READ |GENERIC_WRITE,
0, 0, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, 0);
WriteFile(AsciiCmd, GENERIC_READ //I don't know what to put in next or if this is even going to work.
thankyou for any help you can give.
Mavrock
|
|
|
|
|
I'm stumped and need help. Why does my modeless property sheet show up right from the get go?
I have my property sheet stuff in CMainFrame (MainFrm.cpp/.h). I have a CPropertySheet derived class, CMySheet, and do the following in MainFrm.cpp:
m_pMySheet = new CMySheet("My Modeless Form", this, 0);
m_pMySheet->Create(this, -1, NULL);
I created a modeless property sheet and have overridden the CPropertySheet::OnInitDialog() operation as follows:
BOOL CMySheet::OnInitDialog()
{
// Setting of m_bModeless to FALSE and then TRUE is a trick from CodeGuru
m_bModeless = FALSE;
BOOL bResult = CPropertySheet::OnInitDialog();
m_bModeless = TRUE;
// The rest of my sheet's initialization - fields, controls, etc...
return bResult;
}
As soon as I run my executable, up pops my modeless property sheet. I don't want this to happen until my controlling dialog (dialog, menu item/menu bar) displays the property sheet.
Thanks in advance.
Johnny
|
|
|
|
|
Ok, I think I found out by examining my m_pMySheet->Create() statement, Sorry for this original post.
Here is what I should have examined:
m_pMySheet->Create(this, -1, NULL)
with the second parameter -1, the Create() function employs the following style WS_VISIBLE | WS_SYSMENU | WS_POPUP | WS_CAPTION | DS_MODALFRAME
What I should do is explicitly define my window's (prop-sheet's) style to not have WS_VISIBLE.
See ya...
Johnny
|
|
|
|
|
My debug is constantly screwing up royally.. if i trace a section of code it will jump from one line to a few down and just skip stuff.. the locals window doesnt show anything but 'this' and everything under that is a value that cant be evaluated..
its like my debug is debugging code that is no longer there .. it will go over statements and just do what it wants to almost.. then five minutes later it will mystically work even though i didnt change the part i was trying to debug at all..
i have tried to clean solution and rebuild all, but this does nothing to fix this problem.. anyone seen this before? stupid .net is a little buggy i feel..
-dz
|
|
|
|
|
Hmm, make sure you don't have any optimizations turned on. Those'll screw up a debugging session nicely. And make sure you're using a program database for debugging information. (both of these settings are in project properties)
---
Shog9
If I could sleep forever, I could forget about everything...
|
|
|
|
|
thanks a ton.. i turned on the optimizations a week ago.. didnt even think about the connection.. thanks a bunch!
any chance you know why i cant add a class to a dialog in the resource editor? it asks for the class name, the files, what its base is (CDialog).. i click ok and nothing happens.. never creates the .h or .cpp and gives no error.. cant add a class to any dialog..
at least i can do that manually, being able to debug again is a definate help, thanks a ton!
-dz
|
|
|
|
|
i see this frequently on VC6. sometimes a rebuild all will fix it, sometimes i have to restart VC, sometimes i have to reboot.
sorry i don't have a better answer.
-c
Conservative:
One who admires radicals centuries after they're dead.
-- Leo C. Rosten
|
|
|
|
|
Have you tried a rebuild all? Sometimes this solves the problem.
"Hey man, Taliban, Tali me Banana."
|
|
|
|
|
Hi
I have a strange problem I can't solve. At first a short explanation what I want to do:
I have written an MFC DLL. I added a sourcefile of an subclassed window. Now I want to call that window inside the DLL:
CSubWindow window;
window.Create(...)
...
(show the window)
Well, ok, the window shows up. But then the window itself starts a timer after that the window hides itself. It calls SetTimer(...) and hides itself in the OnTimer() procedure.
But for some reason SetTimer seems to fail so that the window can't hide itself after a period. Inside an EXE everything works, but inside the DLL all the timer thingies don't work anymore.
Of coure I could add a Sleep() command to hide the window after a period, but that's the worst solution I can think of since it stops the whole DLL.
Does anyone have a solution how to get the timers of an window get to work in a DLL?
thanks in advance
Greg
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Does anyone ever developed one ? Where can I find some tips about this ? I found some things on MSDN and PLATAFORM SDK but I need some debug tips and other stuff...
Mauricio Ritter - Brazil
Sonorking now: 100.13560 Trank
The alcohol is one of the greatest enemys of man, but a man who flee from his enemys is a coward.
|
|
|
|
|
I have now tried doing my own double buffering but the flicker is still there!
In WM_PAINT I do this (it's suppose to be double buffering ):
memdc = ::CreateCompatibleDC(clientDC);
hBitmap = CreateCompatibleBitmap(clientDC, 200,200);
::SelectObject(memdc, hBitmap);
SetBkColor(memdc, RGB(0,0,0));
BitBlt(clientDC, 0,0,200,200,memdc,0,0,SRCCOPY);
ReleaseDC(g_hWnd, clientDC);
So... which step have I missed? Or what step have I missunderstod!
Rickard Andersson@Suza Computing
C# and C++ programmer from SWEDEN!
UIN: 50302279
E-Mail: nikado@pc.nu
Speciality: I love C#, ASP.NET and C++!
|
|
|
|
|
hm.. I have figured it out now!
and I see now that I posted an incomplete code snippet of the code I had problem with too.....
Rickard Andersson@Suza Computing
C# and C++ programmer from SWEDEN!
UIN: 50302279
E-Mail: nikado@pc.nu
Speciality: I love C#, ASP.NET and C++!
|
|
|
|
|
I setup a low level keyboard hook using SetWindowsHookEx(), and the hook proc. Everything works fine, but I dont know how to figure out what key was pressed.
Microsoft docs :
LRESULT CALLBACK LowLevelKeyboardProc(
int nCode, // hook code
WPARAM wParam, // message identifier
LPARAM lParam // message data
);
docs say this about lParam
lParam
[in] Pointer to a KBDLLHOOKSTRUCT structure.
here is the doc for kbdllhoststruct:
typedef struct tagKBDLLHOOKSTRUCT {
DWORD vkCode;
DWORD scanCode;
DWORD flags;
DWORD time;
ULONG_PTR dwExtraInfo;
} KBDLLHOOKSTRUCT, *PKBDLLHOOKSTRUCT;
HELP!! how do i get the vkCode??? (In the regular keyboard hook the code is stored in wParam, but now its buried)
|
|
|
|
|
you will get the Virtual Keycode frm the struct...
as u mentioned here..then wut is the problem..specify your problem clear.....
Renjith-CPian.
|
|
|
|
|
The answer to your question is in your question!!!
lParam ... is a ... Pointer to a KBDLLHOOKSTRUCT structure.
so try this:-
KBDLLHOOKSTRUCT * pKbHk;
DWORD dwVkCode;
pKbHk = (KBDLLHOOKSTRUCT *) lParam;
dwVkCode = pKbHk->vkCode;
STL is a religeon. Enquiries to Reverend Christian Graus
|
|
|
|
|
I'm having trouble getting my listbox to scroll automatically as new items are added to it. I've tried using the ScrollWindow method, but it doesn't seem to change anything. What I have now is the following:
void MyClass::updateNews( const char *news ) {
int max;
m_news.AddString( news );
max = m_news.GetScrollLimit( SB_VERT );
m_news.SetScrollPos( SB_VERT, max );
}
But it doesn't work quite right. It scroll most of the way down, but there are still a few lines still unshown.
Any help would be appreciated.
|
|
|
|
|
Did you try CListBox::SetTopIndex?
Tomasz Sowinski -- http://www.shooltz.com
What is "scratch" and why can everything be made from it?
|
|
|
|