|
So - it blocks untill it gets connection - after that it's ok. The question here is how to fix that block? Use a separate thread for your socket communications if you need to respond to UI events while waiting for connections
|
|
|
|
|
Thanks a lot, I will try that.
|
|
|
|
|
Hi:
I´ve create a pointer, don´t mind the type object, and sometime when you want to delete it, this can produce an exception, example when you haven´t initialized the pointer(the error, in this case, will be "Access Violation").How could I catch this error? the problem is that the delete instruction doesn´t catch any exception and doesn´t return any value.
Thanks.
|
|
|
|
|
Always initialize pointer variables to zero, with new or with some other legal pointer value. Use ASSERT_VALID for pointers to MFC objects. Delete will ignore zero pointers so if you take care that any pointer you delete is either zero or points to memory allocated with new you won't have problems. If you want to reuse the pointer variable, zero it after delete.
|
|
|
|
|
I generally use the following macro (the idea originally came from a COM/OLE book 3-4yrs ago):
#define DELETE_POINTER( p ) \
{ \
if( p != NULL ) { \
delete p; \
} \
p = NULL; \
}
So my code is:
fx()
{
CSomeObj pSomeObj = new CSomePbj();
...
DELETE_POINTER( pSomeObj );
}
The macro could easily be updated to include a try,catch block around the delete. If your using MFC you can throw in ASSERT_VALID like the other poster suggested. Or if your not using MFC you can lift the code from the MFC Source to determine if the pointer is valid (validadd.cpp, function AfxIsValidAddress)
Mike
|
|
|
|
|
delete NULL is perfectly valid and does nothing, which is why all pointers should be initialised to NULL, apart from being able to check them for validity. So the above macro only helps if the pointer is NULL, in which case it would do no harm to delete it.
Christian
#include "std_disclaimer.h"
People who love sausage and respect the law should never watch either one being made.
The things that come to those who wait are usually the things left by those who got there first.
|
|
|
|
|
I am writing some test code for a project. I have dozens of messages of a propriety format that I want to display. The messages all take the form of structures where all the data members are public. Rather than manually a control for each element in the structure , is there a way to automatically create a dialog that would display the contents of a specific structure? The only way I can think is to write something to parse the source code . I'd like to be able to drop a control like an ADO data control on a dialog , point it at the structure and let it make a guess of the field types . Then supply an instance at run time for display purposes. Does such a thing exist ?
|
|
|
|
|
Why don't you just add a member function that creates a formatted string containing the structures's data? That way, you only have to write code once and call it when needed.
struct MYSTRUCT
{
int nMyInt;
double dMyDouble;
CString sMyString;
CString GetDataString(CString sVarName)
{
CString sData;
sData.Format("Contents of %s\n"
" nMyInt = %d\n"
" dMyDouble = %lf\n"
" sMyString = %s",
sVarName, nMyInt, dMyDouble, sMyString);
return sData;
};
};
Instead of writing a function that returns a value, you could make the function set an additional value in the struct, but that would make the struct variable use more memory.
struct MYSTRUCT
{
int nMyInt;
double dMyDouble;
CString sMyString;
CString sDataString;
void SetDataString(CString sVarName)
{
sDataString.Format("Contents of %s\n"
" nMyInt = %d\n"
" dMyDouble = %lf\n"
" sMyString = %s",
sVarName, nMyInt, dMyDouble, sMyString);
};
};
At this point, it may be better to write a real live class instead of using a struct, but since I don't know your requirements, that's a call you'll have to make.
Of course, you could just write a global external function to do all that as well.
So many choices, so little time...
|
|
|
|
|
I am using Micrisoft Visual C++ 6.0 compiler in Windows 2000 and I keep getting problems. It sometimes says 'File being used by another process' etc.
Sometimes it even deletes the CPP file when working in the Header. Does anyone know anything about this..
This is causing a lot of probs for me
Thank in advance.
|
|
|
|
|
Hello
How can I get version of MDAC installed on my comp?
Ernst
|
|
|
|
|
file version of "X:\Program files\Common Files\System\ado\msado15.dll"
|
|
|
|
|
I am currently working on a control system application and want to change the priority of the application on starting (dialog based). I could not find any way other than CreateProcess (which is not being used) to change the priority of the process.
Pease guide me with the same (a small example shall be very much helpful).
thanks in advance,
-------------------------------------------
Dashmesh A. Singh
Tata Consultancy Services,
INDIA
e-mail: visions_next@yahoo.co.uk
dashmesha_singh@tcscal.co.in
|
|
|
|
|
|
Thanks Tomasz for your help.
I was able to solve the problem with your help.
//To Set the Priority of the process from within the app
HANDLE hProcess;
DWORD pid;
pid = GetCurrentProcessId();
hProcess = OpenProcess(PROCESS_SET_INFORMATION,true,pid);
if(hProcess == 0)
AfxMessageBox("Invalid Process handle");
else
{
SetPriorityClass(hProcess,HIGH_PRIORITY_CLASS);
CloseHandle(hProcess);
}
-------------------------------------------
Dashmesh A. Singh
Tata Consultancy Services,
INDIA
e-mail: visions_next@yahoo.co.uk
dashmesha_singh@tcscal.co.in
|
|
|
|
|
Hi,
What is parity in modem setting ?
For example in modem setting: 9600,n,8,1
In this setting i don't use of parity, but if i use of it, what will happend ?
My month article: Game programming by DirectX by Lan Mader.
Please visit in: www.geocities.com/hadi_rezaie/index.html
Hadi Rezaie
|
|
|
|
|
When using 7 bit transfers, you have an eighth bit that can be used for a parity check. The sender can set the bit according to whether the number of bits in the data part of the byte is odd or even. This allows a simple sanity check on the receiving side.
Both sides need to agree on the parity setting (high bit signals odd or high bit signals even), or you'll have problems. Typically, a receiver with 8,n,1 will see a senders 7,E,1 data as partial garbage, since it will be getting some chars with 128 added to them, and some without.
|
|
|
|
|
I'm sure this has already been answered around here somewhere, but I can't find it.
I'll preface this with telling you that I am a long-time VB programmer (amateur) who is
learning VC just for fun.
I want a program with menu and toolbars with multiple different dialogs within it --
i.e. an MDI with multiple child dialogs (which is a total breeze to set up in VB).
I've got the MDI with a child CFormView OK. But where do I load any additional dialogs?
And for that matter, where exactly is the first dialog view being loaded? -- I've wandered
around in the code and don't see where it is happening. I have fiddled with loading
subdialogs in a dialog-based app, but that's not quite what I'm going for here.
Sub-question is: do I want or need to be using the Doc/View architecture? It seems to me
that I don't, but I'm really new to this (and admittedly don't understand the Doc/View
architecture yet). The program will be accessing a MS Jet database (but I don't mind
handling the DB access myself).
Thanks in advance for any suggestions/help.
David.
|
|
|
|
|
I found the info I needed in a book.
(Essential Visual C++ by Mickey Williams, SAMS publishing -- in case you are curious).
|
|
|
|
|
Hi,
That would be interesting for me, since I'm facing the same problem. I tried to find this book here in Brazil but unfortunatelly it will take too long to get it by bying from Amazon or other place.
I'd like to know how to implement this, if you could send me something I'd really apreciate that.
My email is crercio@osite.com.br
Thanks a lot.
Crercio O. Silva
|
|
|
|
|
I'm still learning MFC,
I want to be able to have the program read the PCs regional settings for the language and then use the approriate string table.
|
|
|
|
|
You must make dlls with the resources for each idiom
Then into the program you set the source of the resources with void AfxSetResourceHandle.
Cheers!!!
Carlos Antollini.
|
|
|
|
|
Let's say you know for sure what a process's ID is. How would you go about getting a window handle (hwnd) from that process ID? Thanks in advance
Sincerely,
Kanoo
|
|
|
|
|
The thing is that the process can have any number of windows open.
The only thing that comes to mind is that you could walk the window list and compare the process id's of all parent windows to the process id that you have.
It's a bit rough but here's an idea. Note, the I haven't tried it myself.
void GetProcessWindows(DWORD dwProcID)
{
DWORD dwWndProcId;
HWND hwndDesktop, hwndParent;
// start with the desktop
// all parent windows will be a child of the dekstop
hwndDesktop = GetDesktopWindow();
// get first parent window
hwndParent = GetWindow(hwndDesktop, GW_CHILD);
// go through this and all subsequent parent windows comparing their
// process id's with the one we are seeking info on
while(hwndParent) {
GetWindowThreadProcessId(hwndParent, &dwWndProcId);
// does window handle belong to the process we are checking?
if(dwWndProcId == dwProcID) {
// report the handle (or do something meaningful)
TRACE("Process window handle = %08x\n", dwWndProcId);
}
hwndParent = GetWindow(hwndDesktop, GW_HWNDNEXT);
}
}
|
|
|
|
|
I agree with the approach, but not sure app windows will show up as children of the desktop. (er, no I haven't tried it either).
I'd loop by enumerating all the top level windows, starting with HWND hwnd = ::GetTopWindow(NULL); and continuing with hwnd = ::GetNextWindow(hwnd, GW_HWNDNEXT);.
Then, as you say, comparing the process IDs found. The problem remains that apps tend to have more than one top level window, which means more work if you want the 'main' one.
|
|
|
|
|
This is code ripped from one of my apps. I think I got everything.
In the header file, I have this:
const int UWM_FOUNDHWNDADMIN = WM_APP + 1;
class CDlg : public CDialog
{
afx_msg LRESULT OnFoundHwnd(WPARAM wParam, LPARAM lParam);
DECLARE_MESSAGE_MAP()
private:
PROCESS_INFORMATION* m_pProcessInfo;
HWND m_hwnd;
void RunComponent();
void GetAppHWnd();
};
static BOOL CALLBACK EnumWindowsProcGetHwnd(HWND hwnd, LPARAM lParam);
In the CPP file, I have this:
void CDlg::RunD2RemoteAdmin()
{
CString sFileName = GetProgramPath();
AddBackSlash(sFileName);
sFileName += "MyProgram.exe";
if (FileExists(sFileName))
{
char cmdLine[1024];
strcpy(cmdLine,(const char*)sFileName);
m_pProcessInfo = new PROCESS_INFORMATION;
if (!m_pProcessInfo)
{
CString sMsg;
sMsg = "Could not allocate memory for component process info (not critical)";
AfxMessageBox(sMsg);
return;
}
STARTUPINFO StartupInfo = {0};
StartupInfo.cb = sizeof(STARTUPINFO);
if (::CreateProcess(NULL, cmdLine, NULL, NULL, FALSE,
0, NULL, NULL, &StartupInfo, m_pProcessInfo))
{
WaitForInputIdle(m_pProcessInfo->hProcess, 15000);
GetAppHWnd();
}
}
else
{
CString sMsg;
sMsg = "Could not find executable component";
AfxMessageBox(sMsg);
}
}
void CDlg::GetAppHWnd()
{
DWORD pid = m_pProcessInfo->dwProcessId;
HANDLE ps = OpenProcess(SYNCHRONIZE|PROCESS_TERMINATE, FALSE, pid);
EnumWindows(EnumWindowsProcGetHwnd, pid);
CloseHandle(ps);
}
LRESULT CDlg::OnFoundHwnd(WPARAM wParam, LPARAM lParam)
{
wParam;
lParam;
m_hwnd = (HWND)wParam;
DWORD dwPID = (DWORD)lParam;
if (dwPID == m_pProcessInfo->dwProcessId)
{
}
else
{
}
return 1L;
}
BOOL CALLBACK EnumWindowsProcGetHwnd(HWND hwnd, LPARAM lParam)
{
CString sTitle;
CWnd::FromHandle(hwnd)->GetWindowText(sTitle);
DWORD wndPid;
::GetWindowThreadProcessId(hwnd, &wndPid);
if (wndPid == (DWORD)lParam && !sTitle.IsEmpty())
{
if (sTitle.Find("Remote Admin Monitor") >= 0)
{
theApp.m_pMainWnd->SendMessage(UWM_FOUNDHWNDADMIN, (WPARAM)hwnd, lParam);
}
return FALSE;
}
else
{
return TRUE;
}
}
|
|
|
|
|