|
Looks like that's what it is, if I run through the data array and print out anything that isn't a zero up until the bytes read from the Read call, the rest of the file is there. I guess I'll have to replace all the 0's with something else when I send the array and then send another message to the client telling which slots in the array to re-replace with zeros before writing to file... does anybody know of a better way to do this?
Thanks!
Kelly Ryan
|
|
|
|
|
Nevermind, got it working, thanks.
Kelly Ryan
|
|
|
|
|
KellyR wrote:
does anybody know of a better way to do this?
The way I understood it, the client is already receiving the correct content, which includes zeroes. What are you doing with this data at the client end? Writing a local file? The zeroes in the array will represent a problem only if you intend to treat such binary content as if it were text, that is for example, if you try to write it to a file in text mode, or if you call string related functions on it.
If you are writing a file at the client end, make sure you open it in binary mode, and that's all you need.
--
jlr
http://jlamas.blogspot.com/[^]
|
|
|
|
|
In an MFC application, how can I prevent a modeless CDialog from becoming the active window?
Look at the example code - I'm fading in a CWnd, and it fades away unless the user hovers over it. if the user ignores it the window fades away and the program exits. I want to acheive the same thing but with a CDialog so that I can use a dialog template but I can't find a way of preventing the dialog from becomming active. If there is a way to use a dialog template for a vanilla CWnd this would serve the same purpose.
<code>
#include <afxwin.h>
#include <afxext.h>
#include "resource.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
class CTinyApp : public CWinApp
{
public:
virtual BOOL InitInstance();
BOOL RegisterWNDCLASS();
};
CTinyApp theApp;
BOOL CTinyApp::RegisterWNDCLASS()
{
WNDCLASS wndclass;
wndclass.style = CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc = ::DefWindowProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = AfxGetInstanceHandle();
wndclass.hIcon = LoadIcon(IDR_MAINFRAME);
wndclass.hCursor = LoadCursor( IDC_ARROW );
wndclass.hbrBackground = (HBRUSH) (COLOR_WINDOW + 1);
wndclass.lpszMenuName = NULL;
wndclass.lpszClassName = "MyTinyWnd";
if( !AfxRegisterClass( &wndclass ))
{
TRACE("Window class MyTinyWnd could not be registered.\n");
return FALSE;
}
return TRUE;
}
class CTinyWnd : public CWnd
{
DECLARE_DYNAMIC(CTinyWnd)
public:
CTinyWnd();
void ComeAlive();
protected:
DECLARE_MESSAGE_MAP();
public:
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
afx_msg void OnActivate(UINT nState, CWnd* pWndOther, BOOL bMinimized);
afx_msg void OnTimer(UINT nIDEvent);
afx_msg void OnBnClickedOk();
afx_msg void OnShowWindow(BOOL bShow, UINT nStatus);
afx_msg void OnMouseMove(UINT nFlags, CPoint point);
afx_msg void OnNcMouseMove(UINT nHitTest, CPoint point);
int m_nTimer;
int m_nLevel;
CButton m_cOKButton;
CFont m_Font;
};
IMPLEMENT_DYNAMIC(CTinyWnd, CWnd)
BEGIN_MESSAGE_MAP(CTinyWnd, CWnd)
ON_WM_TIMER()
ON_WM_SHOWWINDOW()
ON_WM_ACTIVATE()
ON_WM_CREATE()
ON_WM_NCMOUSEMOVE()
ON_WM_MOUSEMOVE()
ON_BN_CLICKED(IDOK, OnBnClickedOk)
END_MESSAGE_MAP()
CTinyWnd::CTinyWnd() : m_nTimer(-1), m_nLevel(3)
{
}
void CTinyWnd::ComeAlive()
{
if (m_nTimer != -1)
{
KillTimer(m_nTimer);
m_nTimer = -1;
}
ModifyStyleEx(WS_EX_LAYERED,0);
}
void CTinyWnd::OnBnClickedOk()
{
KillTimer(m_nTimer);
m_nTimer = -1;
DestroyWindow();
delete this;
}
void CTinyWnd::OnTimer(UINT nIDEvent)
{
CWnd::OnTimer(nIDEvent);
static bool bDir = true;
if (m_nTimer == nIDEvent)
{
if (bDir)
m_nLevel+=2;
else
m_nLevel--;
if (m_nLevel > 3)
{
if (m_nLevel > 254)
bDir = !bDir;
SetLayeredWindowAttributes(0, m_nLevel, LWA_ALPHA);
RedrawWindow(NULL, NULL, RDW_ERASE|RDW_INVALIDATE|RDW_FRAME|RDW_ALLCHILDREN);
}
else
{
KillTimer(m_nTimer);
m_nTimer = -1;
DestroyWindow();
delete this;
}
}
}
int CTinyWnd::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CWnd::OnCreate(lpCreateStruct) == -1)
return -1;
m_cOKButton.Create("OK",
WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON|BS_TEXT,
CRect(60,20,140,60),
this,
IDOK);
m_Font.CreatePointFont(80,"MS Shell Dlg");
m_cOKButton.SetFont(&m_Font);
return 0;
}
void CTinyWnd::OnActivate(UINT nState, CWnd* pWndOther, BOOL bMinimized)
{
CWnd::OnActivate(nState, pWndOther, bMinimized);
ComeAlive();
}
void CTinyWnd::OnShowWindow(BOOL bShow, UINT nStatus)
{
CWnd::OnShowWindow(bShow, nStatus);
static bool bFirst = true;
if (bFirst)
{
bFirst = false;
m_nLevel = 3;
SetLayeredWindowAttributes(0, m_nLevel, LWA_ALPHA);
m_nTimer = (int)SetTimer(1,50, NULL);
}
}
void CTinyWnd::OnMouseMove(UINT nFlags, CPoint point)
{
static bool bFirst = true;
if (bFirst)
{
ComeAlive();
bFirst = false;
}
}
void CTinyWnd::OnNcMouseMove(UINT nHitTest, CPoint point)
{
static bool bFirst = true;
if (bFirst)
{
ComeAlive();
bFirst = false;
}
}
BOOL CTinyApp::InitInstance()
{
RegisterWNDCLASS();
CTinyWnd* pWnd = new CTinyWnd;
BOOL bCreate = pWnd->CreateEx(WS_EX_TOOLWINDOW|WS_EX_LAYERED,
"MyTinyWnd",
"Popup Message",
WS_BORDER|WS_POPUP|WS_CAPTION,
CRect(200,200,400,300),
NULL,
0, 0);
if (!bCreate)
{
delete pWnd;
return FALSE;
}
m_pMainWnd = pWnd;
m_pMainWnd->ShowWindow(SW_SHOWNA);
m_pMainWnd->UpdateWindow();
return TRUE;
}
</code>
|
|
|
|
|
mintguy wrote:
In an MFC application, how can I prevent a modeless CDialog from becoming the active window?
Try removing the Visible style (WS_VISIBLE ) from the dialog template, then creating the dialog window using CDialog::Create , and then making it appear using CWnd::ShowWindow with SW_SHOWNOACTIVATE .
CFadingDialog dlg;
dlg.Create(IDD_FADING);
dlg.ShowWindow(SW_SHOWNOACTIVATE);
mintguy wrote:
If there is a way to use a dialog template for a vanilla CWnd this would serve the same purpose.
You might take a look at the implementation of MFC's CFormView class.
Hope that helps,
--
jlr
http://jlamas.blogspot.com/[^]
|
|
|
|
|
In Continuation with Jose!, you can also achieve same by returning FALSE instead of TRUE from the OnInitDialog function
"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
|
|
|
|
|
Doesn't work. Try it and see.
|
|
|
|
|
mintguy wrote:
Doesn't work. Try it and see.
Have you urself tried this,i.e. returning FALSE instead of TRUE from OnInitDialog Function.
AnyWays where is code of CDialog based Class implemented by you
"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
|
|
|
|
|
Yes sorry it does work, apologies. I was mssing all three elements together i.s. SHOW_NA, WS_VISIBLE and returning FALSE from OnInitDialog.
Thanks very much for your help.
|
|
|
|
|
mintguy wrote:
apologies.
No need of that!
"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
|
|
|
|
|
Doesn't work. please try it and see.
|
|
|
|
|
It turns out you need to combine what I said with what Alok said. That is:
- 'Visible' as FALSE in dialog template
- Return FALSE in CFadingDlg::OnInitDialog
- Create the dialog with Create()
- Show the dialog with ShowWindow(SW_SHOWNOACTIVATE)
I've just tried this and it worked.
--
jlr
http://jlamas.blogspot.com/[^]
|
|
|
|
|
Ahh yes. Apologies. Thanks very much. I'm sorry I said it didn't work.
The WS_VISIBLE style is the key part I was missing actually. I had tried the rest myself earlier.
Thanks again.
|
|
|
|
|
Hi,
I am currently working on a legacy MultiThreaded MFC application which talks to the remote hardware over a network. The application is compiled with VC++ 6.0 SP5 and has many dlls (Regular, Extension, C++ and WIN32). Now here is a typical user scenarion
1. The user starts a wizard to generate a report for a particular parameter usage on the remote hardware.
2. Configures the report parameters through wizard walkthrough and creates a task that will send some commands to the remote hardware and fetch the required data. The task is executed immidiately.
Now here is a problem I faced during the recent Release build for internal testing due to accidental change in compiler settings.
The application was originally configured to compile with optimization set to "complie for speed" for the Release builds.
When the binary created with this setting is executed, the application runs perfectly fine. The user starts the wizard configure parameters create and execute the task. The application fetches the required data and generates the report.
Now if the compiler setting is changed to optimization=disable with rest every thing remaining same, the application crashes with bad memory reference during the task execution.
During a task execution there may be 3 to 5 threads (worker + GUI) running depending on the complexity of the requested task.
I did found out that the crash was due to invalid thread handle value for one of the threads by attaching the VC debugger externally (On running the release build of the application from within the VC debugger, it works perfectly fine, strange !!!???). Breakpoints are not helping as it seems that they introduces enough time delay for the thread handle to be valid.
I am not too sure on whether the handle is getting invalid either due to not getting initialized at all (the thread is created externally and then set as a reference in class object) or getting terminated too soon.
Well guys I really need help on this as I have been struggling with it for 2-3 days and it is driving me nuts !!
1. I will really like to know what caused the problem at the first place ?
2. What really happened when optimization is turned off that lead to application crash.
I tried to solve this problem by
1. Introducing external delays using loops which didn't help
2. Making the thread switch context by introducing Sleep(0) which did seems to solve the problem (Why?) for this wizard but it crashed another one (again a mistery to me !!)
3. By using Event synchronization object. I create a auto reset event with initial state set as non-signalled. After the thread internal parameters are initialized and before execute method is called I call SetEvent() to set the state to signalled, the application is working perfectly fine with optimization disabled. Interestingly if I simply turnon the optimization for speed without making any code changes everything works fine again !!
In the main execute method I wait for the event to get signalled before proceeding by using WaitForSingleObject(EventHandle, 500), I do get out of the wait but not due to event getting signalled but due to WaitTimeOut happening (don't know why the timeout is happening when the wait should have been over due to event signalling), INFINITE timeout hangs the application.
So please if anyone has a clue on what is going on here please let me know asap.
Sorry if the problem description is bit too long.
Thanks in Advance.
Regards
|
|
|
|
|
Hi,
it seems to me, that you have some weird problem with thread synchronization somewhere. By changing the optimalization switch, the compiler changed the order/amount of instructions that can changed the order/timing of some operation.
This can lead to the situation, where with speed optimalization the thread initialization finishes before other thread uses it, but with optimalization off the initialization is not finished yet, so the second thread uses something uninitialized.
By introducing the Sleep(0) you changed the order of the instructions stream, so it could 'fix' your issue at the moment. But if the synchronization problem is in your application, it will pop-up somewhere else, so definitielly Sleep(0) is not a conceptual solution for such a problem.
By using the event synchronization, you can fix the problem usually (or a part of it). But from the description you gave, it seems that effectivelly you only introduced the 500ms sleep to the start of the application, so just postponing the problem. Only idea I can get is that either the event is not signalled at all, or you can use two different handles, not the same event for synchronization.
hope this helps, dont't hesitate to ask for more
|
|
|
|
|
My C++ application makes system calls, that use cmd.exe ( net use, copy, run .exe, getmac ) with parameters. I am writing a wrapper function that will handle all the parameter formatting, waiting for command to complete, and check the return values.
At first I used the system() command, but I want to hide the cmd window.
So I tried WinExec(), but this runs as a seperate thread and i do see how to suspend the parent thread.
So I tried CreateProcess() but I my exe could be running on any windows platform including Win 95/98. CreateProcess has some compatiblity issues with these version and hiding the window, from what i have read. I am guessing i would have the same problem waiting for the command to complete anyways.
So I tried ShellExecute() but again I was unable to get the parent thread to wait for the command to terminate.
So now I am working with ShellExecuteEx() but again i am having trouble getting the parent thread to wait until the command ends.
can show me how to wait for WinExec, ShellExecute, ShellExecuteEx to finish?
I've been working with WaitForSingleObject but i am missing something..b/c i cannot get it to work.
|
|
|
|
|
jet915 wrote:
My C++ application makes system calls, that use cmd.exe ( net use, copy, run .exe, getmac )
Why use this antiquated approach when functions exist for just such purposes?
jet915 wrote:
So I tried CreateProcess() but I my exe could be running on any windows platform including Win 95/98. CreateProcess has some compatiblity issues with these version and hiding the window, from what i have read.
It works on Windows 95 according to MSDN. What specifically did you read?
jet915 wrote:
So I tried ShellExecute() but again I was unable to get the parent thread to wait for the command to terminate.
It's part of the PROCESS_INFORMATION structure.
jet915 wrote:
can show me how to wait...
PROCESS_INFORMATION pi;
...
CreateProcess(..., &pi);
WaitForSingleObject(pi.hProcess, INFINITE);
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|
|
hi, I download the windbg and tried to use to debug my code.
but how to attach the project with the windbg? seems like VS and windbg is running seperate, does anybody has step by step documentation? thank you!
I can't find any moeory.dum file in my machine.
|
|
|
|
|
Check out Toby Opferman's article(s).
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|
Thanks for reply. I am looking for the memory dump file in my machine, but no luck so far, wondering if the windows2000 could not generate such file....?
thank you for any info!
|
|
|
|
|
If a control has tabstop set to true then it can also be accessed with the mnemonic access keys. I have a control that has tabstop set to false (don't want user to be able to tab to it) but do want to allow access via the access key. I've noticed that it doesn't work when tabstop set to false. I've even tried setting a static control with tab order preceding the control to help get the caret there but no luck. Would I have to intercept a windows message to do this? Saw in Spy++ some GetDlgCode messages being fired during the Access Key event but not sure what to do. Thanks
|
|
|
|
|
mx483 wrote:
...the access key.
Do you mean mnemonic?
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|
Yep mnemonic. I even tried an accelerator key that was mapped to code that would set the focus but I haven't gotten that to work either. Back to the drawing board.
|
|
|
|
|
Was successful in mapping an accelerator key to some code that put the focus to a control that had tabstop set to false. It wasn't working originally because I was using a dialog app that probably didn't have the accelerator table attached. Curious if there are other solutions. This seems to work pretty well though.
|
|
|
|
|